#if UNITY_EDITOR using System.IO; using System.Text; using UnityEngine; public class AutoNormScript : UnityEditor.AssetModificationProcessor { static StringBuilder scriptContent = new StringBuilder(); public static void OnWillCreateAsset(string path) { path = path.Substring(7).Replace(".meta",""); FileInfo fileInfo =new FileInfo(Path.Combine(Application.dataPath, path)); if (fileInfo.Extension.Equals(".cs")) { scriptContent.Clear(); scriptContent.Append("/*\n"); scriptContent.AppendFormat("*\t作者:{0}\n",SystemInfo.deviceName); scriptContent.AppendFormat("*\t时间:{0}\n",System.DateTime.UtcNow); string[] versionInfoArr=File.ReadAllLines(Path.Combine(Application.dataPath.Replace("Assets", ""), "ProjectSettings", "ProjectVersion.txt")); string unityVersion = ""; for (int i = versionInfoArr.Length-1; i>=0; i--) { if (versionInfoArr[i].Contains("m_EditorVersion:")) { unityVersion = versionInfoArr[i].Substring(16); } } scriptContent.AppendFormat("*\tUnity版本:{0}\n", unityVersion); scriptContent.Append("*/\n"); scriptContent.Append(File.ReadAllText(fileInfo.FullName)); File.WriteAllText(fileInfo.FullName,scriptContent.ToString()); } } } #endif
标签:脚本,System,scriptContent,添加,AppendFormat,path,fileInfo,versionInfoArr,备注 From: https://www.cnblogs.com/lichuangblog/p/18497680