Create Script Template In Edit Mode

很多时候 许多类 的 格式 都是重复的,比如 从配置文件中映射出来的类。

这个时候写一个 类模板 就很节省时间了。

Code

 1     public static string TestPath = "Assets/Test.cs";
 2     public static string TestValue = ""test"";
 3     public static string TestCode =
 4 @"
 5 using UnityEngine;
 6 using System;
 7 using System.Text;
 8 using System.Reflection;
 9 using System.Collections;
10 using System.Collections.Generic;
11 using com.kuxiong.battlemodule;
12 using System.Linq;
13 
14 namespace com.kuxiong.battlemodule
15 {
16     public class Test
17     {
18         public string name = " + TestValue + @";
19     }
20 }";
21 
22 
23     [MenuItem("MyTest/Test")]
24     public static void Test()
25     {
26         Debug.Log("Creating Test Vo");
27 
28         System.IO.File.WriteAllText(TestPath, TestCode);
29 
30         AssetDatabase.ImportAsset(TestPath);
31         AssetDatabase.Refresh();
32     }
原文地址:https://www.cnblogs.com/chongxin/p/4513866.html