using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class ChangeScriptTemplates : UnityEditor.AssetModificationProcessor
{
private static string annotationStr =
"//==================================================\r\n"
+ "// 描 述:\r\n"
+ "// 作 者:\r\n"
+ "// 创建时间:#CreateTime#\r\n"
+ "// 版 本:v1.0\r\n"
+ "//==================================================\r\n";
public static void OnWillCreateAsset(string path)
{
//排除meta文件
path = path.Replace(".meta", "");
//cs文件加注注释
if (path.EndsWith(".cs"))
{
//读取脚本内容并添加到annotationStr后面
annotationStr += File.ReadAllText(path);
//获取当前时间替换创建时间字段
annotationStr = annotationStr.Replace("#CreateTime#", System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
//写入并创建脚本
File.WriteAllText(path, annotationStr);
}
}
}