diff --git a/Editor/UI/GenerateTool/UIGenerateEditorTool.cs b/Editor/UI/GenerateTool/UIGenerateEditorTool.cs index 47eff80..d26790b 100644 --- a/Editor/UI/GenerateTool/UIGenerateEditorTool.cs +++ b/Editor/UI/GenerateTool/UIGenerateEditorTool.cs @@ -2,20 +2,22 @@ using UnityEditor; using UnityEngine; -namespace AlicizaX.UI.Editor -{ - public static class UIGenerateEditorTool - { - [MenuItem("GameObject/UI工具/热更工程UI代码", priority = -1)] - public static void GenerateHotfixUIScript() - { - UIGenerateWindow.ShowWindow(Selection.gameObjects.FirstOrDefault(),UIGenerateConfiguration.Instance.UIScriptGenerateConfig.HotFixProjectUIScriptGenerateData); +namespace AlicizaX.UI.Editor { + public static class UIGenerateEditorTool { + [MenuItem("GameObject/UI生成绑定/热更工程UI代码", priority = 10)] + public static void GenerateHotfixUIScript() { + UIScriptGeneratorHelper.GenerateAndAttachScript( + Selection.gameObjects.FirstOrDefault(), + UIGenerateConfiguration.Instance.UIScriptGenerateConfig.HotFixProjectUIScriptGenerateData + ); } - [MenuItem("GameObject/UI工具/主工程UI代码", priority = -1)] - public static void GenerateMainUIScript() - { - UIGenerateWindow.ShowWindow(Selection.gameObjects.FirstOrDefault(),UIGenerateConfiguration.Instance.UIScriptGenerateConfig.MainProjectUIScriptGenerateData); + [MenuItem("GameObject/UI生成绑定/主工程UI代码", priority = 21)] + public static void GenerateMainUIScript() { + UIScriptGeneratorHelper.GenerateAndAttachScript( + Selection.gameObjects.FirstOrDefault(), + UIGenerateConfiguration.Instance.UIScriptGenerateConfig.MainProjectUIScriptGenerateData + ); } } } diff --git a/Editor/UI/GenerateTool/UIGenerateEditorWindow.cs b/Editor/UI/GenerateTool/UIGenerateEditorWindow.cs deleted file mode 100644 index f100aca..0000000 --- a/Editor/UI/GenerateTool/UIGenerateEditorWindow.cs +++ /dev/null @@ -1,42 +0,0 @@ -using UnityEditor; -using UnityEngine; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using AlicizaX.UI.Editor; -using AlicizaX.UI.Runtime; -using UnityEngine.UIElements; - -public class UIGenerateWindow : EditorWindow -{ - private GameObject targetObject; - - - public static GameObject GetTargetObject() - { - return GetWindow().targetObject; - } - - public static void ShowWindow(GameObject target, UIScriptGenerateData scriptGenerateData) - { - var window = GetWindow(false, "UI Config Editor", false); - window.maxSize = Vector2.zero; - window.minSize = Vector2.zero; - window.rootVisualElement.style.display = DisplayStyle.None; - window.rootVisualElement.parent.style.display = DisplayStyle.None; - window.Initlize(target, scriptGenerateData); - } - - public static void CloseWindow() - { - var window = GetWindow(false, "UI Config Editor"); - window.Close(); - } - - private void Initlize(GameObject target, UIScriptGenerateData scriptGenerateData) - { - targetObject = target; - UIScriptGeneratorHelper.GenerateAndAttachScript(targetObject, scriptGenerateData); - } -} diff --git a/Editor/UI/GenerateTool/UIGenerateEditorWindow.cs.meta b/Editor/UI/GenerateTool/UIGenerateEditorWindow.cs.meta deleted file mode 100644 index d3d2173..0000000 --- a/Editor/UI/GenerateTool/UIGenerateEditorWindow.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7bfa0d164c11486cb3a133829d53dccf -timeCreated: 1739339632 \ No newline at end of file diff --git a/Editor/UI/GenerateTool/UIScriptGeneratorHelper.cs b/Editor/UI/GenerateTool/UIScriptGeneratorHelper.cs index 5760bf9..a906449 100644 --- a/Editor/UI/GenerateTool/UIScriptGeneratorHelper.cs +++ b/Editor/UI/GenerateTool/UIScriptGeneratorHelper.cs @@ -44,7 +44,7 @@ namespace AlicizaX.UI.Editor } - public static class UIScriptGeneratorHelper + internal static class UIScriptGeneratorHelper { private static UIGenerateConfiguration _uiGenerateConfiguration; @@ -305,6 +305,7 @@ namespace AlicizaX.UI.Editor public static void GenerateAndAttachScript(GameObject targetObject, UIScriptGenerateData scriptGenerateData) { + EditorPrefs.SetInt("InstanceId", targetObject.GetInstanceID()); UIBindDatas.Clear(); GenerateNameSpace = scriptGenerateData.NameSpace; ArrayComs.Clear(); @@ -377,12 +378,25 @@ namespace AlicizaX.UI.Editor UIBindDatas.Clear(); ArrayComs.Clear(); var className = EditorPrefs.GetString("Generate"); - var targetObject = UIGenerateWindow.GetTargetObject(); + // var targetObject = UIGenerateWindow.GetTargetObject(); + int instanceId = EditorPrefs.GetInt("InstanceId", -1); + if (instanceId == -1) + { + return; + } + + var targetObject = (GameObject)EditorUtility.InstanceIDToObject(instanceId); + + if (!targetObject) + { + Debug.Log("UI脚本生成附加物体丢失!"); + } + EditorPrefs.DeleteKey("Generate"); GetBindData(targetObject.transform); + AttachScriptToGameObject(targetObject, className); Debug.Log($"Generate {className} Successfully attached to game object"); - UIGenerateWindow.CloseWindow(); } } diff --git a/Editor/UI/GenerateTool/UISettingEditorWindow.cs b/Editor/UI/GenerateTool/UISettingEditorWindow.cs index 5cb96f7..bf0fb47 100644 --- a/Editor/UI/GenerateTool/UISettingEditorWindow.cs +++ b/Editor/UI/GenerateTool/UISettingEditorWindow.cs @@ -8,7 +8,7 @@ using UnityEngine.Windows; namespace AlicizaX.UI.Editor { - public class UISettingEditorWindow : OdinEditorWindow + internal class UISettingEditorWindow : OdinEditorWindow { [MenuItem("Tools/AlicizaX/UI Setting Window")] private static void OpenWindow() diff --git a/Runtime/UI/UIBase/UIHolderObjectBase.cs b/Runtime/UI/UIBase/UIHolderObjectBase.cs index bd5dad7..92e5092 100644 --- a/Runtime/UI/UIBase/UIHolderObjectBase.cs +++ b/Runtime/UI/UIBase/UIHolderObjectBase.cs @@ -46,7 +46,7 @@ namespace AlicizaX.UI.Runtime [SerializeField] [HideLabel] - internal UXButton[] hotButtons; + private UXButton[] hotButtons; internal void BindHotKeys() {