Unity3D自定义脚本模板
2015-11-17 17:03
393 查看
啥也不说直接上代码
[code]/******************************************************************* * 文件名: ScriptTemplateEditor.cs * 时 间: 9/9/2015 * 作 者: lzh * 公 司: CompanyName * 项目名: ProjectName * 描 述: 自定义脚本模板 * 根据自己的需求,将这个脚本放到项目的Editor目录中即可。 *******************************************************************/ using UnityEngine; using UnityEditor; public class ScriptTemplateEditor : UnityEditor.AssetModificationProcessor { static string AuthorName = "lzh"; // 可自定义 static string CompanyName = "CompanyName"; // 可自定义 static string ProjectName = "ProjectName"; // 可自定义 public static void OnWillCreateAsset(string path) { path = path.Replace(".meta", ""); path = path.Replace("Assets", ""); path = Application.dataPath+path; int index = path.LastIndexOf("/"); string fileName = path.Substring(index+1); string file = System.IO.File.ReadAllText(path); if(!file.StartsWith("//[lzh]")) { // 在【unity的安装目录下】\Unity\Editor\Data\Resources\ScriptTemplates // 的脚本模板加前面加上一行标记,我这是://[lzh],可自定义 return; } file = file.Replace("//[lzh]", ""); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("/***************************************************"); sb.AppendLine(" * 文件名: " + fileName); sb.AppendLine(" * 描 述: "); sb.AppendLine(" * 时 间: " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sb.AppendLine(" * 作 者: " + AuthorName); sb.AppendLine(" * 公 司: " + CompanyName); sb.AppendLine(" * 项目名: " + ProjectName); sb.AppendLine(" ***************************************************/"); sb.AppendLine(file); System.IO.File.WriteAllText(path, sb.ToString()); AssetDatabase.Refresh(); } //public static void OnWillCreateAsset2(string path) //{ // path = path.Replace(".meta", ""); // int index = path.LastIndexOf("."); // string file = path.Substring(index); // if (file != ".cs" && file != ".js" && file != ".boo") return; // string fileExtension = file; // index = Application.dataPath.LastIndexOf("Assets"); // path = Application.dataPath.Substring(0, index) + path; // file = System.IO.File.ReadAllText(path); // file = file.Replace("#CreateDate#", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // file = file.Replace("#ProjectName#", PlayerSettings.productName); // file = file.Replace("#CompanyName#", PlayerSettings.companyName); // file = file.Replace("#FileExtension#", fileExtension); // file = file.Replace("#AuthorName#", "li.zhihai"); // System.IO.File.WriteAllText(path, file); // AssetDatabase.Refresh(); //} }
相关文章推荐
- 学习Space shooter 小项目 总结
- unity 网格Mesh占用内存公式
- 【Unity开发】Unity2D多分辨率屏幕适配方案(IOS露出天空盒解决办法)
- Unity加载prefab时调用脚本函数顺序和内存释放问题
- Unity3d中设置UISprite图片灰显方法
- Unity3D占用内存太大的解决方法
- Unity给力插件之MegaFiers
- 【UGUI】Unity的UGUI实现Button按钮长按状态的判断
- UnityEngine.UI.dll is in timestamps but is not known in assetdatabase
- unity 手游《天神传》服务端源码+客户端源码+文档
- Unity3d 开发之 ulua 坑的总结
- Unity 实现Log实时输出到屏幕或控制台上<二>
- Unity 实现Log实时输出到屏幕或控制台上<二>
- unity物体指示线
- Unity拖动摄像机加上惯性滑动的效果
- 【NGUI】Unity插件NGUI的Button按钮修改为Disabled状态
- unity导入的自定义3D模型从地板掉下去
- Unity 配置使 .prefab 可以文本化阅读修改
- 【笨木头Unity】入门之旅009:Demo之四处找死(四)_在代码里操作物体
- Unity不同平台读取本地文件地址