Unity 及 VS2015 建立指令碼時自動新增頭部註釋
阿新 • • 發佈:2019-02-19
首先來看下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中建立一個指令碼都會自動新增頭部註釋了。