自动给脚本添加备注信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#if UNITY_EDITOR
using System.IO;
using System.Text;
using UnityEngine;
public class AutoNormScript : UnityEditor.AssetModificationProcessor
{
    static StringBuilder scriptContent = new StringBuilder();
    public static void OnWillCreateAsset(string path)
    {
        path = path.Substring(7).Replace(".meta","");
        FileInfo fileInfo =new FileInfo(Path.Combine(Application.dataPath, path));
        if (fileInfo.Extension.Equals(".cs"))
        {
            scriptContent.Clear();
            scriptContent.Append("/*\n");
            scriptContent.AppendFormat("*\t作者:{0}\n",SystemInfo.deviceName);
            scriptContent.AppendFormat("*\t时间:{0}\n",System.DateTime.UtcNow);
            string[] versionInfoArr=File.ReadAllLines(Path.Combine(Application.dataPath.Replace("Assets", ""), "ProjectSettings", "ProjectVersion.txt"));
            string unityVersion = "";
            for (int i = versionInfoArr.Length-1; i>=0; i--)
            {
                if (versionInfoArr[i].Contains("m_EditorVersion:"))
                {
                    unityVersion = versionInfoArr[i].Substring(16);
                }
            }
            scriptContent.AppendFormat("*\tUnity版本:{0}\n", unityVersion);
            scriptContent.Append("*/\n");
            scriptContent.Append(File.ReadAllText(fileInfo.FullName));
            File.WriteAllText(fileInfo.FullName,scriptContent.ToString());
        }
    }
}
#endif

  

posted @   游戏鼻祖  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2017-10-23 unity 同一标签里内容拥有不同颜色
点击右上角即可分享
微信分享提示