Pārlūkot izejas kodu

选择表格时,以及reload关卡选择时自动运行gen_code_json.bat;

wgl 5 mēneši atpakaļ
vecāks
revīzija
eed238fa82

+ 2 - 36
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEdPopup.cs

@@ -289,46 +289,12 @@ public class GameMapEdPopup : PopupWindowContent
 		}
 		UnityEngine.Debug.Log($"\"{gameMap.showIdent}\"表保存完毕!");
 		UnityEngine.Debug.Log("记得运行\"gen_code_json.bat\"更新数据!");
-		RunBat();
-	}
-
-	//运行.bat文件
-	public static void RunBat()
-	{
-
-		string batPath = Application.dataPath + "/../Luban/gen_code_json.bat"; // 示例路径
-
-		// 检查文件是否存在
-		if (!System.IO.File.Exists(batPath))
-		{
-			UnityEngine.Debug.LogError(".bat文件不存在: " + batPath);
-			return;
-		}
-
-		// 配置进程启动信息
-		ProcessStartInfo psi = new ProcessStartInfo
-		{
-			FileName = "cmd.exe", // 通过cmd调用
-			Arguments = $"/K \"{batPath}\"", // 传递.bat路径
-			WorkingDirectory = System.IO.Path.GetDirectoryName(batPath),
-			UseShellExecute = true,
-			CreateNoWindow = false
-		};
-
-		// 启动进程
-		try
-		{
-			Process.Start(psi);
-			UnityEngine.Debug.Log("成功启动.bat文件: " + batPath);
-		}
-		catch (Exception e)
-		{
-			UnityEngine.Debug.LogError("启动失败: " + e.Message);
-		}
+		ExcelEditor.RunBat();
 	}
 
 	public void ReloadExcelData(string path, int mapIdx)
 	{
+		ExcelEditor.RunBat();
 		List<string> excelWorksheets = new();
 		Tables allCfgData = new Tables(ExcelEditor.Loader);
 		List<SingleCreateEnemyConfig> cfgCreateEnemy = allCfgData.CfgCreateEnemy.DataList;

+ 36 - 0
ActionTowerDefense/Assets/Scripts/ExcelEditor.cs

@@ -5,6 +5,7 @@ using System.IO;
 using System;
 using SimpleJSON;
 using System.Diagnostics;
+using UnityEngine;
 
 /*使用方法
     using System.IO;
@@ -139,4 +140,39 @@ public class ExcelEditor
     {
         return JSON.Parse(File.ReadAllText("GenerateDatas/json/" + fileName + ".json"));
     }
+
+    //运行.bat文件
+    public static void RunBat()
+    {
+
+        string batPath = Application.dataPath + "/../Luban/gen_code_json.bat"; // 示例路径
+
+        // 检查文件是否存在
+        if (!System.IO.File.Exists(batPath))
+        {
+            UnityEngine.Debug.LogError(".bat文件不存在: " + batPath);
+            return;
+        }
+
+        // 配置进程启动信息
+        ProcessStartInfo psi = new ProcessStartInfo
+        {
+            FileName = "cmd.exe", // 通过cmd调用
+            Arguments = $"/K \"{batPath}\"", // 传递.bat路径
+            WorkingDirectory = System.IO.Path.GetDirectoryName(batPath),
+            UseShellExecute = true,
+            CreateNoWindow = false
+        };
+
+        // 启动进程
+        try
+        {
+            Process.Start(psi);
+            UnityEngine.Debug.Log("成功启动.bat文件: " + batPath);
+        }
+        catch (Exception e)
+        {
+            UnityEngine.Debug.LogError("启动失败: " + e.Message);
+        }
+    }
 }

+ 1 - 0
ActionTowerDefense/Assets/Scripts/Levels/LevelSelect.cs

@@ -42,6 +42,7 @@ public class LevelSelect : MonoBehaviour
         {
             levels.Add($"{i + 1}:{sheets[i]}");
         }
+        ExcelEditor.RunBat();
     }
 
     //[Header("ËùÓйؿ¨ÅäÖÃ")]