添加自动生成配置文件工具
parent
c02482532a
commit
c65b702403
|
@ -0,0 +1,108 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
//using cfg;
|
||||||
|
using SimpleJSON;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using ZC;
|
||||||
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
|
namespace ZEditor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 配置文件工具(后面再完善把,暂时不想搞了)
|
||||||
|
/// </summary>
|
||||||
|
public class GenConfigCSEditor : Editor
|
||||||
|
{
|
||||||
|
[MenuItem("Tool/自动生成配置表和cs常量工具")]
|
||||||
|
public static void Gen()
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
// 指定批处理文件的路径
|
||||||
|
string pathToBatchFile = $"{Application.dataPath}".Replace("Assets", "Luban") + "/gen.bat";
|
||||||
|
|
||||||
|
Process process = new Process();
|
||||||
|
|
||||||
|
// 设置进程启动信息
|
||||||
|
process.StartInfo.FileName = pathToBatchFile;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.RedirectStandardError = true;
|
||||||
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
|
// 启动进程
|
||||||
|
process.Start();
|
||||||
|
|
||||||
|
// 读取输出(如果需要)
|
||||||
|
string output = process.StandardOutput.ReadToEnd();
|
||||||
|
string errors = process.StandardError.ReadToEnd();
|
||||||
|
|
||||||
|
// 等待进程结束
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
|
// 可以将输出或错误信息打印到Unity的控制台
|
||||||
|
UnityEngine.Debug.Log(output);
|
||||||
|
if (!string.IsNullOrEmpty(errors))
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError(errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JSONNode JX(string arg)
|
||||||
|
{
|
||||||
|
string path = String.Empty;
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
case "item_tbitem":
|
||||||
|
path = AssetConst.Assets_DemoGame_GameRes_Config_JSON_item_tbitem_json;
|
||||||
|
break;
|
||||||
|
case "tbplayer":
|
||||||
|
path = AssetConst.Assets_DemoGame_GameRes_Config_JSON_tbplayer_json;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var textAsset = ResourcesLocalComponent.Instance.LoadAssetSync<TextAsset>(path);
|
||||||
|
return JSON.Parse(textAsset.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [MenuItem("Tool/运行场景")]
|
||||||
|
// public static void Run()
|
||||||
|
// {
|
||||||
|
// EditorApplication.isPlaying = true;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9f815f01838f40a4b9be377d51589289
|
||||||
|
timeCreated: 1721372740
|
Loading…
Reference in New Issue