当前位置:   article > 正文

C#代码添加脚本头

C#代码添加脚本头

目录

前言

代码展示


前言

创建脚本的时候添加脚本的介绍

代码展示

  1. using System.IO;
  2. /// <summary>
  3. /// 创建脚本自动添加头注
  4. /// </summary>
  5. public class CommentFirst : UnityEditor.AssetModificationProcessor
  6. {
  7. /// <summary>
  8. /// 在资源创建生成.meta时调用
  9. /// </summary>
  10. /// <param name="path">自动传入资源路径</param>
  11. public static void OnWillCreateAsset(string path)
  12. {
  13. path = path.Replace(".meta", "");
  14. if (!path.EndsWith(".cs")) return;
  15. string allText = "// ========================================================\r\n"
  16. + "// 描述:\r\n"
  17. + "// 功能:\r\n"
  18. + "// 作者:XXX \r\n"
  19. + "// 创建时间:#CreateTime#\r\n"
  20. + "// 版本:1.0\r\n"
  21. + "// 变更时间:\r\n"
  22. + "// 变更版本:#CreateTime2#\r\n"
  23. + "// 脚本路径:#ScripsPath#\r\n"
  24. + "// ========================================================\r\n";
  25. allText += File.ReadAllText(path);
  26. allText = allText.Replace("#CreateTime#", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  27. allText = allText.Replace("#ScripsPath#", path);
  28. File.WriteAllText(path, allText);
  29. }
  30. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/58471
推荐阅读
相关标签
  

闽ICP备14008679号