创建脚本头部注释方法一
在项目中创建名字为 NewScriptTemplates 的新脚本,将如下代码拷贝进去就ok了。然后再去创建新的脚本查看是否有头部注释了。
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEditor;
public class NewScriptTemplates : UnityEditor.AssetModificationProcessor
{
private static string noteStr =
"// ==========================================================\n"
+ "// Description:\n"
+ "// Autor:#Autor# \n"
+ "// CreateTime:#CreateTime# \n"
+ "// 版 本:v #Version# \n"
+ "// ========================================================\n";
public static void OnWillCreateAsset(string path)
{
path = path.Replace(".meta", "");
if (path.EndsWith(".cs"))
{
string allText = noteStr ;
allText += File.ReadAllText(path);
allText = allText.Replace("#CreateTime#",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
allText = allText.Replace("#Version#", Application.version);
allText = allText.Replace("#Autor#", Environment.UserName);
File.WriteAllText(path, allText);
AssetDatabase.Refresh();
}
}
}
|