unity自动添加头部注释脚本,放在Assets目录自动生效
csharp
public class ScriptCreateInit : UnityEditor.AssetModificationProcessor
{
private static void OnWillCreateAsset(string path)
{
path = path.Replace(".meta", "");
if (path.EndsWith(".cs"))
{
EditorApplication.delayCall += () =>
{
string scriptContent = "//==============================\n";
scriptContent += "//Author: yiaomumu \n";
scriptContent += "//Email: yiaomumu@qq.com\n";
scriptContent += "//Created on: " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
scriptContent += "//==============================\n\n";
if (!File.ReadAllText(path).Contains("//Author"))
{
scriptContent += File.ReadAllText(path);
File.WriteAllText(path, scriptContent);
AssetDatabase.Refresh();
}
};
}
}
}