How to modify the new Script Template-ScriptTemplates (the 15th of Unity3D development) and unity3d global script

Source: Internet
Author: User

How to modify the new Script Template-ScriptTemplates (the 15th of Unity3D development) and unity3d global script

Monkey original, reprinted. Reprinted Please note: Reprinted from the Cocos2Der-CSDN, thank you!
Address: http://blog.csdn.net/cocos2der/article/details/44957631

When adding a new script to unity, there is no copyright file header information, mainly because there is no name of the script creator. in project development, if you want to know who wrote the script, call and call for half a day to discover that it was written by yourself !!!

I am used to xcode, so I am going to add an information header to the new unity script.

Unity itself has a new script template file, but there are very few predefined keys in this file, which is not enough for us to use. Therefore, you need to add several keys by yourself. Then, replace these keys with the corresponding content when creating the script.

1. Modify the Template File

Open the template file Unity. app/Contents/Resources/ScriptTemplates/81-C # Script-NewBehaviourScript.cs.txt
To:

////  #SCRIPTNAME##FILEEXTENSION#//  #PROJECTNAME#////  Created by #SMARTDEVELOPERS# on #CREATIONDATE#.////using UnityEngine;using System.Collections;public class #SCRIPTNAME# : MonoBehaviour {    // Use this for initialization    void Start () {    }    // Update is called once per frame    void Update () {    }}

The above is the copyright header information, and the newly created script has the following effect:

////  TestClass.cs//  DomoJump////  Created by YanghuiLiu on 04/09/2015.////using UnityEngine;using System.Collections;public class TestClass : MonoBehaviour {    // Use this for initialization    void Start () {    }    // Update is called once per frame    void Update () {    }}
2. Add an Editor script to parse the key we added above
////  HEScriptKeywordReplace.cs//  HEUnityExtensionLib////  Created by YanghuiLiu on 04/09/2015.////using UnityEngine;using UnityEditor;using System.Collections;public class HEScriptKeywordReplace : UnityEditor.AssetModificationProcessor {    public static void OnWillCreateAsset ( string path ) {        path = path.Replace(".meta", "");        int index = path.LastIndexOf(".");        string file = path.Substring(index);        if (file != ".cs" && file != ".js" && file != ".boo") return;        string fileExtension = file;        index = Application.dataPath.LastIndexOf("Assets");        path = Application.dataPath.Substring(0, index) + path;        file = System.IO.File.ReadAllText(path);        file = file.Replace("#CREATIONDATE#", System.DateTime.Now.ToString("d"));        file = file.Replace("#PROJECTNAME#", PlayerSettings.productName);        file = file.Replace("#SMARTDEVELOPERS#", PlayerSettings.companyName);        file = file.Replace("#FILEEXTENSION#", fileExtension);        System.IO.File.WriteAllText(path, file);        AssetDatabase.Refresh();    }}
3. Set PlayerSettings attributes

Click Edit/Project Settings/Player to change Company Name to the desired Name.

OK. You can also modify it as needed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.