Unity Mono脚本自动添加头部注释
显示时间
脚本、、、、、、、、、、、、、、、、、、、、、、
、、、、、、、、、、、、、、、、
- /// <summary>
- /// 此函数在asset被创建完,文件已经生成到磁盘上,但是没有生成.meta文件和import之前被调用
- /// </summary>
- /// <param name="newFileMeta">newfilemeta 是由创建文件的path加上.meta组成的</param>
- public static void OnWillCreateAsset(string newFileMeta)
- {
- string newFilePath = newFileMeta.Replace(".meta", "");
- string fileExt = Path.GetExtension(newFilePath);
- if (fileExt != ".cs")
- {
- return;
- }
- //注意,Application.datapath会根据使用平台不同而不同
- string realPath = Application.dataPath.Replace("Assets", "") + newFilePath;
- string scriptContent = File.ReadAllText(realPath);
- //这里实现自定义的一些规则
- scriptContent = scriptContent.Replace("#SCRIPTFULLNAME#", Path.GetFileName(newFilePath));
- scriptContent = scriptContent.Replace("#COMPANY#", PlayerSettings.companyName);
- scriptContent = scriptContent.Replace("#AUTHOR#", "Passion");
- scriptContent = scriptContent.Replace("#VERSION#", "1.0");
- scriptContent = scriptContent.Replace("#UNITYVERSION#", Application.unityVersion);
- scriptContent = scriptContent.Replace("#DATE#", System.DateTime.Now.ToString("yyyy-MM-dd"));
- File.WriteAllText(realPath, scriptContent);
- }
//////////////////////////Data
//*************************************************
//*****************************************
//创建人: 银子
//联系方式:[email protected]
//日期: #DATE#
//感谢所有遇见
//如果你要驯服一个人 就要冒着掉眼泪的危险
//*****************************************
//*************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class Data : UnityEditor.AssetModificationProcessor {
/// <summary>
/// 此函数在asset被创建完,文件已经生成到磁盘上,但是没有生成.meta文件和import之前被调用
/// </summary>
/// <param name="newFileMeta">newfilemeta 是由创建文件的path加上.meta组成的</param>
public static void OnWillCreateAsset(string newFileMeta)
{
string newFilePath = newFileMeta.Replace(".meta", "");
string fileExt = Path.GetExtension(newFilePath);
if (fileExt != ".cs")
{
return;
}
//注意,Application.datapath会根据使用平台不同而不同
string realPath = Application.dataPath.Replace("Assets", "") + newFilePath;
string scriptContent = File.ReadAllText(realPath);
//这里现自定义的一些规则
scriptContent = scriptContent.Replace("#SCRIPTFULLNAME#", Path.GetFileName(newFilePath));
// scriptContent = scriptContent.Replace("#COMPANY#", PlayerSettings.companyName);
// scriptContent = scriptContent.Replace("#AUTHOR#", "Passion");
// scriptContent = scriptContent.Replace("#VERSION#", "1.0");
// scriptContent = scriptContent.Replace("#UNITYVERSION#", Application.unityVersion);
scriptContent = scriptContent.Replace("#DATE#", System.DateTime.Now.ToString("yyyy-MM-dd-HH:mm"));
File.WriteAllText(realPath, scriptContent);
}
}