Unity 及 VS2015 创建脚本时自动添加头部注释

首先来看下Unity:

在Editor文件夹下创建脚本如下:
using UnityEngine;
using System.Collections;
using System.IO;

namespace UGUIFrameWorkEditor
{
public class ChangeScriptTemplates : UnityEditor.AssetModificationProcessor
{
// 添加脚本注释模板
private static string str =
"// ========================================================\r\n"
+ "// Des:\r\n"
+ "// Autor:阿童木 \r\n"
+ "// CreateTime:#CreateTime#\r\n"
+ "// 版 本:v 1.0\r\n"
+ "// ========================================================\r\n";

    // 创建资源调用
    public static void OnWillCreateAsset(string path)
    {
        // 只修改C#脚本
        path = path.Replace(".meta", "");
        if (path.EndsWith(".cs"))
        {
            string allText = str;
            allText += File.ReadAllText(path);
            // 替换字符串为系统时间
            allText = allText.Replace("#CreateTime#", System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            File.WriteAllText(path, allText);
        }
    }
}

}

当我们创建脚本的时候就会自动添加头部注释了。
再来看看VS2015
因为我们有时候不想在unity中创建脚本,想在vs中进行创建,这样就不需要每次创建脚本unity都要进行编译。 我们找到F:\vs2015\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\WebClass(这是我的路径)下的Class脚本,打开是这样:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Web;

namespace $rootnamespace$
{
public class $safeitemrootname$
{
}
}
我们需要在它上方添加如下:
/**

  • 功 能:
  • 类 名: $safeitemname$
  • Ver Time Autor Des
  • ───────────────────────────────────
  • V0.01 $time$ 阿童木 初版

*/
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Web;

namespace $rootnamespace$
{
public class $safeitemrootname$
{
}
}
接着再找到F:\vs2015\Common7\IDE\ItemTemplatesCache\CSharp\Code\2052\Class路径下的Class,
将它修改为:
/**

  • 功 能:
  • 类 名: $safeitemname$
  • Ver Time Autor Des
  • ───────────────────────────────────
  • V0.01 $time$ 阿童木 初版

*/

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
然后我们每次在vs中创建一个脚本都会自动添加头部注释了。

你可能感兴趣的:(Unity 及 VS2015 创建脚本时自动添加头部注释)