From 7c93c2458fa72358d3b1ee43a8575cd42cc2d938 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期二, 01 七月 2025 17:37:51 +0800
Subject: [PATCH] 130 子 【战斗】战斗系统 / 【战斗】战斗系统-客户端 UI界面方便开关编辑器 /界面基础代码自动生成 /主线战斗编辑器

---
 /dev/null                                          |  122 -----------------
 Assets/Editor/Tool/StoryBattleEditorWindow.cs      |  120 +++++++++++++++++
 Assets/Editor/Tool/StoryBattleEditorWindow.cs.meta |    2 
 Assets/Editor/Tool/WindowTool.cs                   |   70 +++++++--
 Assets/Editor/UI/PSDTOUGUIProcessor.cs             |   68 +++++++-
 5 files changed, 229 insertions(+), 153 deletions(-)

diff --git a/Assets/Editor/Tool/StoryBattleEditorWindow.cs b/Assets/Editor/Tool/StoryBattleEditorWindow.cs
new file mode 100644
index 0000000..ae69d0f
--- /dev/null
+++ b/Assets/Editor/Tool/StoryBattleEditorWindow.cs
@@ -0,0 +1,120 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+
+public class StoryBattleEditorWindow : EditorWindow
+{
+
+    private StoryBattleField storyBattleField;
+
+    // 鍋囪浣犳湁濡備笅瀛楁
+    private int redIndex = 0;
+    private int blueIndex = 0;
+
+    private int skillId = 0;
+    private SkillConfig currentSkillConfig;
+    private int casterCamp = 0; // 0=绾㈡柟锛�1=钃濇柟
+
+    private float timeScale = 1f;
+
+    [MenuItem("Tools/StoryBattleEditor")]
+    public static void OpenWindow()
+    {
+        StoryBattleEditorWindow window = GetWindow<StoryBattleEditorWindow>("Story Battle Editor");
+        window.minSize = new Vector2(800, 600);
+        window.Show();
+
+        BattleManager.Instance.StartStoryBattle();
+        window.storyBattleField = BattleManager.Instance.storyBattleField;
+    }
+
+    private void OnGUI()
+    {
+        GUILayout.Label("Story Battle Editor", EditorStyles.boldLabel);
+
+        if (storyBattleField == null)
+        {
+            EditorGUILayout.HelpBox("璇峰厛鎸囧畾 StoryBattleField 瀹炰緥", MessageType.Warning);
+            if (GUILayout.Button("閲嶆柊鍔犺浇"))
+            {
+                storyBattleField = BattleManager.Instance.storyBattleField;
+            }
+            return;
+        }
+
+        EditorGUILayout.Space();
+        EditorGUILayout.LabelField("鎶�鑳藉綍鍒跺姩浣滄祴璇�", EditorStyles.boldLabel);
+
+        // 鎶�鑳絀D杈撳叆涓庨厤缃幏鍙�
+        skillId = EditorGUILayout.IntField("鎶�鑳絀D", skillId);
+        currentSkillConfig = SkillConfig.Get(skillId);
+        if (currentSkillConfig != null)
+        {
+            EditorGUILayout.LabelField($"鎶�鑳藉悕: {currentSkillConfig.SkillName}");
+        }
+        else
+        {
+            EditorGUILayout.HelpBox("鏈壘鍒拌鎶�鑳介厤缃�", MessageType.Warning);
+        }
+
+        timeScale = EditorGUILayout.FloatField("TimeScale", timeScale);
+
+        Time.timeScale = timeScale;
+
+        // 绾㈣摑鍙屾柟 BattleObject 閫夋嫨
+        var redCampList = new List<BattleObject>(from BO in storyBattleField.battleObjMgr.redCampList where !BO.IsDead() select BO);
+        var blueCampList = new List<BattleObject>(from BO in storyBattleField.battleObjMgr.blueCampList where !BO.IsDead() select BO);
+
+        string[] redNames = redCampList != null
+            ? redCampList.ConvertAll(obj => obj != null ? obj.BattleObjectId.ToString() : "null").ToArray()
+            : new string[0];
+        redIndex = EditorGUILayout.Popup("绾㈡柟 BattleObject", redIndex, redNames);
+
+        string[] blueNames = blueCampList != null
+            ? blueCampList.ConvertAll(obj => obj != null ? obj.BattleObjectId.ToString() : "null").ToArray()
+            : new string[0];
+        blueIndex = EditorGUILayout.Popup("钃濇柟 BattleObject", blueIndex, blueNames);
+
+        // 閫夋嫨鏂芥硶鑰�
+        casterCamp = EditorGUILayout.Popup("鏂芥硶鑰呴樀钀�", casterCamp, new string[] { "绾㈡柟", "钃濇柟" });
+
+        EditorGUILayout.Space();
+        if (GUILayout.Button("鎾斁 SkillRecordAction"))
+        {
+            if (currentSkillConfig == null)
+            {
+                Debug.LogError("SkillConfig 鏈壘鍒帮紒");
+                return;
+            }
+            if (redCampList == null || blueCampList == null || redCampList.Count == 0 || blueCampList.Count == 0)
+            {
+                Debug.LogError("绾㈡柟鎴栬摑鏂瑰垪琛ㄤ负绌猴紒");
+                return;
+            }
+            var redObj = redCampList[Mathf.Clamp(redIndex, 0, redCampList.Count - 1)];
+            var blueObj = blueCampList[Mathf.Clamp(blueIndex, 0, blueCampList.Count - 1)];
+            BattleObject caster = (casterCamp == 0) ? redObj : blueObj;
+
+            // 鏋勯�燬killRecordAction
+            var action = new SkillRecordAction(skillId, storyBattleField, caster);
+
+            if (storyBattleField.recordPlayer != null)
+            {
+                storyBattleField.recordPlayer.PlayRecord(action);
+            }
+            else
+            {
+                Debug.LogError("recordPlayer 鏈缃紒");
+            }
+        }
+
+        if (GUILayout.Button("鍏ㄩ儴澶嶆椿"))
+        {
+            storyBattleField.battleObjMgr.ReviveAll();
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/Assets/Editor/UI/UIBaseInspector.cs.meta b/Assets/Editor/Tool/StoryBattleEditorWindow.cs.meta
similarity index 83%
rename from Assets/Editor/UI/UIBaseInspector.cs.meta
rename to Assets/Editor/Tool/StoryBattleEditorWindow.cs.meta
index 99a3e20..16f8c7d 100644
--- a/Assets/Editor/UI/UIBaseInspector.cs.meta
+++ b/Assets/Editor/Tool/StoryBattleEditorWindow.cs.meta
@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 0fbf6ddb4c77d3d4d99505d359d8b869
+guid: 23553de5d3bda0d44bef5fde563b18f1
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2
diff --git a/Assets/Editor/Tool/WindowTool.cs b/Assets/Editor/Tool/WindowTool.cs
index 9caa2f6..d274c69 100644
--- a/Assets/Editor/Tool/WindowTool.cs
+++ b/Assets/Editor/Tool/WindowTool.cs
@@ -1,35 +1,71 @@
 using UnityEngine;
 using UnityEditor;
+using System.Collections.Generic;
 
 public class WindowTool : EditorWindow
 {
-    [MenuItem("Tools/绐楀彛绠$悊")]
+    private string windowName = "";
+    private int selectedUIIndex = -1;
+    private List<string> uiNameList = new List<string>();
+
+    [MenuItem("Tools/WindowTool")]
     public static void ShowWindow()
     {
-        EditorWindow.GetWindow<WindowTool>("绐楀彛绠$悊").Show();
+        GetWindow<WindowTool>("WindowTool");
     }
-
-    [SerializeField]
-    private string windowName;
 
     private void OnGUI()
     {
+        EditorGUILayout.LabelField("绐楀彛鍚嶇О", EditorStyles.boldLabel);
+
+        // 鐩戝惉TextField鍙樺寲
+        string newWindowName = EditorGUILayout.TextField("windowName", windowName);
+        if (newWindowName != windowName)
+        {
+            windowName = newWindowName;
+            selectedUIIndex = -1; // 鎵嬪姩杈撳叆鏃跺彇娑堥�変腑
+        }
+
+        // 鑾峰彇UIManager涓殑鐣岄潰鍒楄〃
+        if (UIManager.Instance != null && UIManager.Instance.uiDict != null)
+        {
+            uiNameList.Clear();
+            foreach (var kv in UIManager.Instance.uiDict)
+            {
+                uiNameList.Add(kv.Key);
+            }
+
+            EditorGUILayout.Space();
+            EditorGUILayout.LabelField("UI鐣岄潰鍒楄〃", EditorStyles.boldLabel);
+
+            int clickedIndex = GUILayout.SelectionGrid(selectedUIIndex, uiNameList.ToArray(), 1);
+
+            // 鍙鐐瑰嚮灏辫鐩杦indowName
+            if (clickedIndex >= 0 && clickedIndex < uiNameList.Count)
+            {
+                selectedUIIndex = clickedIndex;
+                windowName = uiNameList[selectedUIIndex];
+            }
+        }
+        else
+        {
+            EditorGUILayout.HelpBox("UIManager.Instance 鎴� uiDict 鏈垵濮嬪寲", MessageType.Warning);
+        }
+
         EditorGUILayout.Space();
+
+        // 淇濈暀鍘熸湁鐨勬墦寮�鍜屽叧闂寜閽�
         EditorGUILayout.BeginHorizontal();
-        GUILayout.Label("绐楀彛鍚嶇О");
-        EditorGUILayout.EndHorizontal();
-        windowName = GUILayout.TextField(windowName, GUILayout.MinWidth(300));
         if (GUILayout.Button("鎵撳紑"))
         {
-            OpenWindow();
+            // 鎵撳紑绐楀彛閫昏緫
+            UIManager.Instance.OpenWindow(windowName);
         }
+        if (GUILayout.Button("鍏抽棴"))
+        {
+            // 鍏抽棴绐楀彛閫昏緫
+            UIManager.Instance.CloseWindow(windowName);
+        }
+        EditorGUILayout.EndHorizontal();
     }
-
-    private void OpenWindow()
-    {
-        if (string.IsNullOrEmpty(windowName) || !Application.isPlaying)
-            return;
-        UIManager.Instance.OpenWindow(windowName);
-    }
-
 }
\ No newline at end of file
diff --git a/Assets/Editor/UI/PSDTOUGUIProcessor.cs b/Assets/Editor/UI/PSDTOUGUIProcessor.cs
index 42da342..9e995f8 100644
--- a/Assets/Editor/UI/PSDTOUGUIProcessor.cs
+++ b/Assets/Editor/UI/PSDTOUGUIProcessor.cs
@@ -49,6 +49,35 @@
             g.raycastTarget = false;
         }
     }
+
+    private static List<string> SplitByCamelCase(string input)
+    {
+        if (string.IsNullOrEmpty(input))
+            return new List<string>();
+
+        var result = new List<string>();
+        var currentWord = new StringBuilder();
+        currentWord.Append(input[0]);
+
+        for (int i = 1; i < input.Length; i++)
+        {
+            if (char.IsUpper(input[i]))
+            {
+                // 閬囧埌澶у啓瀛楁瘝锛岃〃绀烘柊鍗曡瘝寮�濮�
+                result.Add(currentWord.ToString());
+                currentWord.Clear();
+            }
+            currentWord.Append(input[i]);
+        }
+
+        // 娣诲姞鏈�鍚庝竴涓崟璇�
+        if (currentWord.Length > 0)
+        {
+            result.Add(currentWord.ToString());
+        }
+
+        return result;
+    }
     
     [UnityEditor.MenuItem("GameObject/鐢熸垚UI鑴氭湰", false, 10)]
     public static void GenerateUIScript()
@@ -61,8 +90,16 @@
         }
         
         string className = go.name;
-        string targetFolder = Path.Combine(Application.dataPath, "Scripts/Main/UI");
+
+        List<string> caseList = SplitByCamelCase(className);
+
+        string targetFolder = Path.Combine(Application.dataPath, "Scripts/Main/System");
         
+        if (Directory.Exists(targetFolder + "/" + caseList[0]))
+        {
+            targetFolder += "/" + caseList[0];
+        }
+
         // 纭繚鐩爣鏂囦欢澶瑰瓨鍦�
         if (!Directory.Exists(targetFolder))
         {
@@ -94,35 +131,40 @@
         sb.AppendLine("    // 缁勪欢寮曠敤");
         sb.AppendLine("");
         sb.AppendLine("    // 鐢熷懡鍛ㄦ湡");
-        sb.AppendLine("    protected override void Awake()");
+        sb.AppendLine("    protected override void InitComponent()");
         sb.AppendLine("    {");
-        sb.AppendLine("        base.Awake();");
-        sb.AppendLine("        // 鍒濆鍖栫粍浠跺紩鐢�");
+        sb.AppendLine("        base.InitComponent();");
+        sb.AppendLine("        // 鍒濆鍖栫粍浠跺紩鐢� 缁戝畾鎸夐挳绛塙I缁勪欢浜嬩欢");
         sb.AppendLine("    }");
         sb.AppendLine("");
-        sb.AppendLine("    protected override void Start()");
+        sb.AppendLine("    protected override void OnPreOpen()");
         sb.AppendLine("    {");
-        sb.AppendLine("        base.Start();");
-        sb.AppendLine("        // 鍒濆鍖栨暟鎹�");
+        sb.AppendLine("        base.OnPreOpen();");
         sb.AppendLine("    }");
         sb.AppendLine("");
-        sb.AppendLine("    // UI浜嬩欢");
+        sb.AppendLine("    protected override void OnPreClose()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.OnPreClose();");
+        sb.AppendLine("    }");
+        sb.AppendLine("");
         sb.AppendLine("    protected override void OnOpen()");
         sb.AppendLine("    {");
         sb.AppendLine("        base.OnOpen();");
-        sb.AppendLine("        // 绐楀彛鎵撳紑鏃剁殑閫昏緫");
         sb.AppendLine("    }");
         sb.AppendLine("");
         sb.AppendLine("    protected override void OnClose()");
         sb.AppendLine("    {");
         sb.AppendLine("        base.OnClose();");
-        sb.AppendLine("        // 绐楀彛鍏抽棴鏃剁殑閫昏緫");
         sb.AppendLine("    }");
         sb.AppendLine("");
-        sb.AppendLine("    public override void Refresh()");
+        sb.AppendLine("    protected override void NextFrameAfterOpen()");
         sb.AppendLine("    {");
-        sb.AppendLine("        base.Refresh();");
-        sb.AppendLine("        // 鍒锋柊UI鏄剧ず");
+        sb.AppendLine("        base.NextFrameAfterOpen();");
+        sb.AppendLine("    }");
+        sb.AppendLine("");
+        sb.AppendLine("    protected override void CompleteClose()");
+        sb.AppendLine("    {");
+        sb.AppendLine("        base.CompleteClose();");
         sb.AppendLine("    }");
         sb.AppendLine("}");
         
diff --git a/Assets/Editor/UI/UIBaseInspector.cs b/Assets/Editor/UI/UIBaseInspector.cs
deleted file mode 100644
index ac106e5..0000000
--- a/Assets/Editor/UI/UIBaseInspector.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-using UnityEngine;
-using UnityEditor;
-
-[CustomEditor(typeof(UIBase), true)]
-public class UIBaseInspector : Editor
-{
-    SerializedProperty uiLayer;
-    SerializedProperty uiName;
-    SerializedProperty isMainUI;
-    SerializedProperty supportParentChildRelation;
-    SerializedProperty isPersistent;
-    SerializedProperty maxIdleRounds;
-
-    // 鍔ㄧ敾鐩稿叧
-    SerializedProperty openAnimationType;
-    SerializedProperty closeAnimationType;
-    SerializedProperty animeRoot;
-    SerializedProperty animeDuration;
-    SerializedProperty scaleOverInOutCurve;
-    SerializedProperty animationEase;
-
-    SerializedProperty openMask;
-    SerializedProperty clickEmptySpaceClose;
-
-    void OnEnable()
-    {
-        uiLayer = serializedObject.FindProperty("uiLayer");
-        uiName = serializedObject.FindProperty("uiName");
-        isMainUI = serializedObject.FindProperty("isMainUI");
-        supportParentChildRelation = serializedObject.FindProperty("supportParentChildRelation");
-        isPersistent = serializedObject.FindProperty("isPersistent");
-        maxIdleRounds = serializedObject.FindProperty("maxIdleRounds");
-
-        openAnimationType = serializedObject.FindProperty("openAnimationType");
-        closeAnimationType = serializedObject.FindProperty("closeAnimationType");
-        animeRoot = serializedObject.FindProperty("_rectTransform");
-        animeDuration = serializedObject.FindProperty("animeDuration");
-        scaleOverInOutCurve = serializedObject.FindProperty("scaleOverInOutCurve");
-        animationEase = serializedObject.FindProperty("animationEase");
-
-        openMask = serializedObject.FindProperty("openMask");
-        clickEmptySpaceClose = serializedObject.FindProperty("clickEmptySpaceClose");
-    }
-
-    public override void OnInspectorGUI()
-    {
-        base.OnInspectorGUI();
-        // serializedObject.Update();
-
-        // EditorGUILayout.PropertyField(uiLayer);
-        // EditorGUILayout.PropertyField(uiName);
-        // EditorGUILayout.PropertyField(isMainUI);
-        // EditorGUILayout.PropertyField(supportParentChildRelation);
-
-        // EditorGUILayout.Space();
-        // EditorGUILayout.LabelField("鎸佷箙鍖栬缃�", EditorStyles.boldLabel);
-        // EditorGUILayout.PropertyField(isPersistent);
-        // if (isPersistent.boolValue)
-        // {
-        //     EditorGUI.indentLevel++;
-        //     EditorGUILayout.PropertyField(maxIdleRounds);
-        //     EditorGUI.indentLevel--;
-        // }
-
-        // EditorGUILayout.Space();
-        // EditorGUILayout.LabelField("鍔ㄧ敾璁剧疆", EditorStyles.boldLabel);
-        // EditorGUILayout.PropertyField(openAnimationType);
-        // EditorGUILayout.PropertyField(closeAnimationType);
-        // EditorGUILayout.PropertyField(animeRoot, new GUIContent("animeRoot (鍔ㄧ敾鏍硅妭鐐�)"));
-        // if (openAnimationType.enumValueIndex != 0 || closeAnimationType.enumValueIndex != 0)
-        // {
-        //     EditorGUI.indentLevel++;
-        //     EditorGUILayout.PropertyField(animeDuration);
-        //     if ((UIAnimationType)openAnimationType.enumValueIndex == UIAnimationType.ScaleOverInOut)
-        //     {
-        //         EditorGUILayout.PropertyField(scaleOverInOutCurve);
-        //     }
-        //     EditorGUILayout.PropertyField(animationEase);
-        //     EditorGUI.indentLevel--;
-        // }
-        // // 鍔ㄧ敾鐢熸晥鎻愮ず
-        // if ((openAnimationType.enumValueIndex != 0 || closeAnimationType.enumValueIndex != 0) && animeRoot.objectReferenceValue == null)
-        // {
-        //     EditorGUILayout.HelpBox("濡傞渶鍔ㄧ敾鐢熸晥锛屽繀椤绘寚瀹� animeRoot锛堝姩鐢绘牴鑺傜偣锛夛紒", MessageType.Warning);
-        // }
-
-        // EditorGUILayout.Space();
-        // EditorGUILayout.LabelField("閬僵璁剧疆", EditorStyles.boldLabel);
-
-        // EditorGUILayout.BeginHorizontal();
-
-        // EditorGUILayout.PropertyField(openMask);
-        // EditorGUILayout.PropertyField(clickEmptySpaceClose);
-        // EditorGUI.BeginChangeCheck();
-        // openMask.boolValue = GUILayout.Toggle(openMask.boolValue, "寮�鍚伄缃�", EditorStyles.miniButtonLeft);
-        // clickEmptySpaceClose.boolValue = GUILayout.Toggle(clickEmptySpaceClose.boolValue, "鐐瑰嚮绌虹櫧鍏抽棴", EditorStyles.miniButtonRight);
-        // if (EditorGUI.EndChangeCheck())
-        // {
-        //     if (tempOpenMask && tempClickEmptyClose)
-        //     {
-        //         if (openMask.boolValue != tempOpenMask)
-        //         {
-        //             clickEmptySpaceClose.boolValue = false;
-        //             openMask.boolValue = true;
-        //         }
-        //         else
-        //         {
-        //             openMask.boolValue = false;
-        //             clickEmptySpaceClose.boolValue = true;
-        //         }
-        //     }
-        //     else
-        //     {
-        //         openMask.boolValue = tempOpenMask;
-        //         clickEmptySpaceClose.boolValue = tempClickEmptyClose;
-        //     }
-        // }
-        // EditorGUILayout.EndHorizontal();
-
-        // serializedObject.ApplyModifiedProperties();
-    }
-}
\ No newline at end of file

--
Gitblit v1.8.0