前言
每次打开unity工程包,都需要重新拖入一些东西进来,可麻烦,今天就用添加头部注释来举例。
正文
对于公司有固定框架的,这样做就不需要每次都手动添加,只用改下命名空间就好了。
脚本添加头部注释
- 目录 Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs.txt
添加头部
/**
*Copyright(C) 2018 by #COMPANY#
*All rights reserved.
*FileName: #SCRIPTFULLNAME#
*Author: #AUTHOR#
*Version: #VERSION#
*UnityVersion:#UNITYVERSION#
*Date: #DATE#
*Description:
*History:
*/
添加脚本。
- 目录 Editor\Data\Resources\PackageManager\ProjectTemplates\com.unity.template.3d\Assets
添加 Editor\AddFileHeadComment.cs
public class AddFileHeadComment : 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#", "Pan");
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);
}
}
Comments | NOTHING