修改 Unity C#脚本模板

脚本模板的路径:

Window:

Unity安装目录\Editor\Data\Resources\ScriptTemplates\81-C# Script-
NewBehaviourScript.cs.txt

Mac:

Unity.app/Contents/Resources/ScriptTemplates/81-C# Script-NewBehaviourScript.cs.txt

C#模板

/*************************************************************************
 *  Copyright © 2018-2020 #AUTHORNAME#. All rights reserved.
 *------------------------------------------------------------------------
 *  File         :  #SCRIPTNAME#.cs
 *  Author       :  #AUTHORNAME#
 *  Date         :  #CREATETIME#
 *  Description  :  
 *************************************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace JIANING(修改为你的命名空间) {
    
    public class #SCRIPTNAME# : MonoBehaviour {

        // Use this for initialization
        void Start () {
            #NOTRIM#
        }
        
        // Update is called once per frame
        void Update () {
            #NOTRIM#
        }
    }
}

并在项目的Editor文件夹下创建以下脚本

CodeEditor.cs

using System.IO;

namespace JIANING.Editor.Code {
    
    public class CodeEditor : UnityEditor.AssetModificationProcessor {
        
        public const string authorName = "JIANING(修改为你自己的名称即可)";

        public static void OnWillCreateAsset(string path) {
            path = path.Replace(".meta", "");

            if (path.ToLower().EndsWith(".cs")) {
                string content = File.ReadAllText(path);

                content = content.Replace("#AUTHORNAME#", authorName);
                content = content.Replace("#CREATETIME#", System.DateTime.Now.ToShortDateString());

                File.WriteAllText(path, content);
            }
        }
    }
}

注意:

在创建新脚本之前,需要先将脚本CodeEditor.cs拖入到工程目录下的Editor(如果没有就自己创建一个命名为Editor的文件夹)目录中去

加入对话

12条评论

  1. naturally like your web site however you need to test the spelling on several of your posts. A number of them are rife with spelling issues and I find it very bothersome to inform the truth however I will definitely come again again. Pearline Darrell Gay

  2. Thanks for the sensible critique. Me and my neighbor were just preparing to do some research about this. We got a grab a book from our local library but I think I learned more clear from this post. I am very glad to see such great information being shared freely out there. Ninnette Zacharie Southard

  3. Can I simply say that of a relief to seek out a person that in fact knows what theyre talking about on the web. You actually know how to bring an issue to light to make it important. Lots more people must check out this and see why side of the story. I cant think youre less popular simply because you certainly develop the gift. Reba Jozef Giff

  4. As I web site possessor I believe the content matter here is rattling fantastic , appreciate it for your efforts. You should keep it up forever! Good Luck. Katine Roger Wakeen

留下评论

电子邮件地址不会被公开。 必填项已用*标注