Unity3D游戏开发

Unity 创建C#脚本时自动添加头部注释

2018-10-27  本文已影响0人  xzhuan

Aitin原创稿件,转载请注明出处!
代码如下

/**************************************
*Module:添加C#代码 自动添加注释                                           
*Author:aitin                                        
*Time: 2018.05.22                                                     
**************************************/
using System.Collections;
using System.IO;


namespace CLB
{
   public class ChangeScriptTemplate : UnityEditor.AssetModificationProcessor
   {

       // 添加脚本注释模板
       private static string str =
       "// ========================================================\r\n"
       + "// Module:\r\n"
       + "// Author:aitin \r\n"
       + "// Time:#CreateTime#\r\n"
       + "// ========================================================\r\n";

       // 创建资源调用
       public static void OnWillCreateAsset(string path)
       {
           // 只修改C#脚本
           path = path.Replace(".meta", "");
           if (path.EndsWith(".cs"))
           {
               string allText = str;
               allText += File.ReadAllText(path);
               // 替换字符串为系统时间
               allText = allText.Replace("#CreateTime#", System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
               File.WriteAllText(path, allText);
           }
       }
   }
}
上一篇下一篇

猜你喜欢

热点阅读