完成配置表常量工具;
parent
68274ad87c
commit
379cecbb29
|
@ -0,0 +1,5 @@
|
|||
using UnityEngine;
|
||||
public static class #CLASSNAME#
|
||||
{
|
||||
#CONSTCONTENT#
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f8aa6a7854744a2599fcb988dcba2871
|
||||
timeCreated: 1721631976
|
|
@ -39,8 +39,8 @@ namespace ZEditor
|
|||
Bridging(ref sb, resPath);
|
||||
|
||||
var readAllText = File.ReadAllText(template);
|
||||
var content = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", "AssetConst");
|
||||
var loaderContent = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", "LoaderAssetConst");
|
||||
var content = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", csName);
|
||||
var loaderContent = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", loaderCsName);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.Create(path).Dispose();
|
||||
|
|
|
@ -22,30 +22,6 @@ namespace ZEditor
|
|||
Run();
|
||||
|
||||
string folderPath = @"Assets/DemoGame/GameRes/Config/JSON";
|
||||
|
||||
// // 获取文件夹下所有文件的完整路径
|
||||
// string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
|
||||
//
|
||||
// Tables tables;
|
||||
// // 输出文件路径
|
||||
// foreach (string file in files)
|
||||
// {
|
||||
// if (file.Contains(".meta"))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// tables = new cfg.Tables(JX);
|
||||
// }
|
||||
|
||||
// string gameConfDir = @"Assets/DemoGame/GameRes/Config/JSON"; // 替换为gen.bat中outputDataDir指向的目录
|
||||
// var tables = new cfg.Tables(file => JSON.Parse(File.ReadAllText($"{gameConfDir}/{file}.json")));
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// foreach (var item in tables.TbItem.DataMap)
|
||||
// {
|
||||
// string name = $"{item.Key}_{item.Value.Name}";
|
||||
// sb.AppendLine($"public const int {name} = {item.Key};");
|
||||
// }
|
||||
}
|
||||
|
||||
static void Run()
|
||||
|
@ -78,6 +54,45 @@ namespace ZEditor
|
|||
{
|
||||
UnityEngine.Debug.LogError(errors);
|
||||
}
|
||||
|
||||
Debug.Log("配置文件生成成功,开始生成常量脚本");
|
||||
// 自动生成脚本
|
||||
GenConst();
|
||||
}
|
||||
|
||||
private const string fileName = "ConfigConst";
|
||||
private const string folderPath = "Assets/DemoGame/GameScript/Hotfix/Const";
|
||||
public static string template = "Assets/DemoGame/GameRes/ConfigConstTemplate.txt";
|
||||
|
||||
// [MenuItem("Tool/单独生成配置表常量脚本")]
|
||||
static void GenConst()
|
||||
{
|
||||
string path = $"{folderPath}/{fileName}.cs";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
var tables = new cfg.Tables(JX);
|
||||
// item_tbitem
|
||||
foreach (var item in tables.TbItem.DataList)
|
||||
{
|
||||
sb.AppendLine($"public const int item_tbitem_{item.Id}_{item.Name}_{item.Desc} = {item.Id};");
|
||||
}
|
||||
|
||||
// tbplayer
|
||||
foreach (var playerData in tables.TBPlayer.DataList)
|
||||
{
|
||||
sb.AppendLine($"public const int tbplayer_{playerData.Id}_{playerData.Name}_{playerData.Desc} = {playerData.Id};");
|
||||
}
|
||||
|
||||
var readAllText = File.ReadAllText(template);
|
||||
var content = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", fileName);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.Create(path).Dispose();
|
||||
}
|
||||
|
||||
File.WriteAllText(path, content);
|
||||
|
||||
Debug.Log("生成配置表常量脚本完成!");
|
||||
}
|
||||
|
||||
private static JSONNode JX(string arg)
|
||||
|
@ -95,14 +110,9 @@ namespace ZEditor
|
|||
break;
|
||||
}
|
||||
|
||||
var textAsset = ResourcesLocalComponent.Instance.LoadAssetSync<TextAsset>(path);
|
||||
return JSON.Parse(textAsset.text);
|
||||
}
|
||||
|
||||
// [MenuItem("Tool/运行场景")]
|
||||
// public static void Run()
|
||||
// {
|
||||
// EditorApplication.isPlaying = true;
|
||||
// }
|
||||
// var textAsset = ResourcesLocalComponent.Instance.LoadAssetSync<TextAsset>(path);
|
||||
var textAsset = File.ReadAllText(path);
|
||||
return JSON.Parse(textAsset);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
public static class ConfigConst
|
||||
{
|
||||
public const int item_tbitem_10000_发型_初始发型 = 10000;
|
||||
public const int item_tbitem_10001_外套_初始外套 = 10001;
|
||||
public const int item_tbitem_10002_上衣_初始上衣 = 10002;
|
||||
public const int item_tbitem_10003_裙子_初始下装 = 10003;
|
||||
public const int item_tbitem_10004_袜子_初始袜子 = 10004;
|
||||
public const int item_tbitem_10005_鞋子_初始鞋子 = 10005;
|
||||
public const int item_tbitem_10006_发饰_初始发饰 = 10006;
|
||||
public const int item_tbitem_10007_中秋节发饰_中秋节发饰 = 10007;
|
||||
public const int item_tbitem_10008_中秋节鞋子_中秋节鞋子 = 10008;
|
||||
public const int item_tbitem_10009_礼包_中秋节礼包 = 10009;
|
||||
public const int tbplayer_10000_小明_这是小明啊 = 10000;
|
||||
public const int tbplayer_10001_小兰_这是小兰啊 = 10001;
|
||||
public const int tbplayer_10002_小花_这是小花啊 = 10002;
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 77c106f464c5948499e3b8e1784df08c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue