美文网首页Unity3D游戏开发
Unity 创建C#脚本时自动添加头部注释

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

作者: xzhuan | 来源:发表于2018-10-27 11:26 被阅读0次

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);
           }
       }
   }
}

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/jwtdtqtx.html