在Editor文件夾下創建腳本如下:
using UnityEngine;using System.Collections;using System.IO;namespace UGUIFrameWorkEditor{ public class ChangeScriptTemplates : UnityEditor.AssetModificationPRocessor { // 添加腳本注釋模板 private static string str = "http:// ========================================================/r/n" + "http:// Des:/r/n" + "http:// Autor:阿童木 /r/n" + "http:// CreateTime:#CreateTime#/r/n" + "http:// 版 本:v 1.0/r/n" + "http:// ========================================================/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); } } }}當我們創建腳本的時候就會自動添加頭部注釋了。
因為我們有時候不想在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中創建一個腳本都會自動添加頭部注釋了。
新聞熱點
疑難解答