-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddFileHeadComment.CS
More file actions
34 lines (30 loc) · 1.44 KB
/
AddFileHeadComment.CS
File metadata and controls
34 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEditor;
using UnityEngine;
using System.IO;
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#", "Passion");
scriptContent = scriptContent.Replace("#VERSION#", "1.0");
scriptContent = scriptContent.Replace("#UNITYVERSION#", Application.unityVersion);
scriptContent = scriptContent.Replace("#DATE#", System.DateTime.Now.ToString());
File.WriteAllText(realPath, scriptContent);
}
}