New file |
| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEditor; |
| | | using System.IO; |
| | | using System.Text; |
| | | |
| | | public class LuaConfigFunctionGenerate
|
| | | {
|
| | |
|
| | | [MenuItem("Assets/生成配置表Lua读取接口")]
|
| | | public static void InsertConfigInterface()
|
| | | {
|
| | | var csfilePath = Application.dataPath + "/Scripts/Lua/LuaConfigUtility.cs";
|
| | | var content = File.ReadAllText(csfilePath);
|
| | |
|
| | | var fileName = string.Empty;
|
| | |
|
| | | foreach (var obj in Selection.objects)
|
| | | {
|
| | | if (obj is UnityEngine.Object)
|
| | | {
|
| | | var path = AssetDatabase.GetAssetPath(obj);
|
| | | if (path.EndsWith("txt") || path.EndsWith("TXT"))
|
| | | {
|
| | | fileName = Path.GetFileNameWithoutExtension(path);
|
| | | var newContent = MakeConfigInterface(fileName);
|
| | | if (!content.Contains(newContent))
|
| | | {
|
| | | content = content.Replace("//这里插入配置表获取方法", StringUtility.Contact("//这里插入配置表获取方法\r\n", MakeConfigInterface(fileName)));
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | var encoderShouldEmitUTF8Identifier = true;
|
| | | var throwOnInvalidBytes = false;
|
| | | var encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes);
|
| | | var append = false;
|
| | | var streamWriter = new StreamWriter(csfilePath, append, encoding);
|
| | | streamWriter.Write(content);
|
| | | streamWriter.Close();
|
| | | AssetDatabase.ImportAsset(csfilePath);
|
| | |
|
| | | } |
| | | |
| | | public static string MakeConfigInterface(string _configName)
|
| | | {
|
| | | var temp = "\tpublic static " + _configName + "Config" + " Get" + _configName + "(string _key)\r\n"
|
| | | + "\t{\r\n"
|
| | | + "\t\treturn ConfigManager.Instance.GetTemplate<" + _configName + "Config" + ">(_key);\r\n"
|
| | | + "\t}"
|
| | | + "\r\n";
|
| | |
|
| | | return temp;
|
| | | } |
| | | |
| | | } |