Assets/Editor/Tool/StoryBattleEditorWindow.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Assets/Editor/Tool/StoryBattleEditorWindow.cs.meta | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Assets/Editor/Tool/WindowTool.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Assets/Editor/UI/PSDTOUGUIProcessor.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Assets/Editor/UI/UIBaseInspector.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Assets/Editor/Tool/StoryBattleEditorWindow.cs
New file @@ -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); // 技能ID输入与配置获取 skillId = EditorGUILayout.IntField("技能ID", 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; // 构造SkillRecordAction 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(); } } } Assets/Editor/Tool/StoryBattleEditorWindow.cs.meta
File was renamed from Assets/Editor/UI/UIBaseInspector.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 guid: 0fbf6ddb4c77d3d4d99505d359d8b869 guid: 23553de5d3bda0d44bef5fde563b18f1 MonoImporter: externalObjects: {} serializedVersion: 2 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); // 只要点击就覆盖windowName 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); } } 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(" // 初始化组件引用 绑定按钮等UI组件事件"); 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("}"); Assets/Editor/UI/UIBaseInspector.cs
File was deleted