Tuesday, August 27, 2013

Change default C# script template in Unity3d

Standard
Hello All:

In this post, I will explain how to change the default C# script template for Unity3d. The default script template has less namespace included for C#, which in turn result in adding commonly used namespaces very frequently.


Below is the location for script templates

  1. Windows: \Program Files\Unity\Editor\Data\Resources\ScriptTemplates
  2. MAC:  /Applications/Unity/Unity.app/Contents/Resources/ScriptTemplates
Open 81-C# Script-NewBehaviourScript.cs.txt in any text editor like NotePad++ or Sublime Text (in administrator mode) and replace the existing code with below code:

      #region Class Information
/*----------------------------------------------------------------------------------
// File:           #SCRIPTNAME#.cs
// Project:          $projectName$
// Solution:           $solutionName$
// Description:        $description$
//
// Change History:
// Name                              Date                                          Version  Description                    
// ----------------------------------------------------------------------------------
// $programmer$  $date$             1.0     Created
// ----------------------------------------------------------------------------------*/
# endregion

        using UnityEngine;
        using System.Collections;
        using System.Collections.Generic;
        using System;
        using System.Linq;
        using Rand = UnityEngine.Random;
        using Obj = UnityEngine.Object;
        public class #SCRIPTNAME# : MonoBehaviour {
        #region Variables
        #endregion
        #region Methods
         void Awake()
        {
    
        }
        // Use this for initialization
        void Start()
        {
    
        }
        // Update is called once per frame
        void Update()
        {
    
        }
        #endregion
        }
    
This will change default generated mono behavior class.

Sometimes we just want to have a class with properties and method and no mono behavior.
For this, create new file with the name 85-C# Model Script-Model.cs.txt and copy below code in this


    #region Class Information
/*----------------------------------------------------------------------------------
// File:           #SCRIPTNAME#.cs
// Project:          $projectName$
// Solution:           $solutionName$
// Description:        $description$
//
// Change History:
// Name                              Date                                          Version  Description                    
// ----------------------------------------------------------------------------------
// $programmer$  $date$             1.0     Created
// ----------------------------------------------------------------------------------*/
# endregion
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using System;
    using System.Linq;
    using Rand = UnityEngine.Random;
    using Obj = UnityEngine.Object;
    public class #SCRIPTNAME# {

    #region Variables
    #endregion

    #region Methods
    #endregion
    }
    
After this save the file. Now in unity you will one more option named C# Model Script when you try to create a new asset in your unity project.

In case of any issues please post in comments, I will try to solve them.

Thanks for printing this post. Hope you liked it.
Keep visiting and sharing.
Thanks,
Ashwani.

0 comments :

Post a Comment