From 9bcf20ad6a470a8043ede1693e9e808d8e07799d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Mon, 30 Mar 2026 11:44:57 +0800 Subject: [PATCH] add generate property --- Editor/UI/GenerateWindow/UIGenerateQuick.cs | 13 ++++++ Editor/UI/Helper/UIScriptGeneratorHelper.cs | 49 ++++++++++++++++++--- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/Editor/UI/GenerateWindow/UIGenerateQuick.cs b/Editor/UI/GenerateWindow/UIGenerateQuick.cs index 8cd3e41..1d28d77 100644 --- a/Editor/UI/GenerateWindow/UIGenerateQuick.cs +++ b/Editor/UI/GenerateWindow/UIGenerateQuick.cs @@ -37,6 +37,19 @@ namespace AlicizaX.UI.Editor Debug.Log("没有找到符合规则路径的生成配置 请检查!"); } + [MenuItem("GameObject/UI生成绑定 仅复制属性", priority = 11)] + public static void UICopyBindVariableContent() + { + GameObject selectedObject = Selection.gameObjects.FirstOrDefault(); + if (selectedObject == null) + { + Debug.LogError("没有选中物体!"); + return; + } + + UIScriptGeneratorHelper.CopyVariableContentToClipboard(selectedObject); + } + public static bool CheckCanGenerate(GameObject targetObject, UIScriptGenerateData scriptGenerateData) { if (targetObject == null || scriptGenerateData == null) return false; diff --git a/Editor/UI/Helper/UIScriptGeneratorHelper.cs b/Editor/UI/Helper/UIScriptGeneratorHelper.cs index eb04069..ee036c4 100644 --- a/Editor/UI/Helper/UIScriptGeneratorHelper.cs +++ b/Editor/UI/Helper/UIScriptGeneratorHelper.cs @@ -149,6 +149,12 @@ namespace AlicizaX.UI.Editor ScriptFileWriter != null; } + private static bool EnsureVariableGenerationStrategyReady() + { + return IdentifierFormatter != null && + ScriptCodeEmitter != null; + } + private static Type ResolveUIElementComponentType(string uiName) { if (string.IsNullOrEmpty(uiName)) @@ -495,6 +501,37 @@ namespace AlicizaX.UI.Editor GenerateScript(generationContext); } + public static void CopyVariableContentToClipboard(GameObject targetObject) + { + if (targetObject == null) throw new ArgumentNullException(nameof(targetObject)); + + if (!EnsureVariableGenerationStrategyReady()) + { + return; + } + + string variableContent; + try + { + ResetCollectedBindData(); + CollectBindData(targetObject.transform); + variableContent = ScriptCodeEmitter.GetVariableContent(_uiBindDatas, GetPublicComponentName); + } + finally + { + ResetCollectedBindData(); + } + + EditorGUIUtility.systemCopyBuffer = variableContent ?? string.Empty; + if (string.IsNullOrEmpty(variableContent)) + { + Debug.LogWarning($"UI生成绑定未找到可复制的属性内容,已清空剪贴板: {targetObject.name}"); + return; + } + + Debug.Log($"UI生成绑定属性已复制到剪贴板: {targetObject.name}"); + } + private static void InitializeGenerationContext(GameObject targetObject) { EditorPrefs.SetInt(GenerateInstanceIdKey, targetObject.GetInstanceID()); @@ -504,9 +541,7 @@ namespace AlicizaX.UI.Editor EditorPrefs.SetString(GenerateAssetPathKey, assetPath); } - _uiBindDatas.Clear(); - _arrayComponents.Clear(); - _componentTypeCache.Clear(); + ResetCollectedBindData(); } private static UIGenerationValidationResult ValidateGeneration(UIGenerationContext context) @@ -614,8 +649,7 @@ namespace AlicizaX.UI.Editor return; } - _uiBindDatas.Clear(); - _arrayComponents.Clear(); + ResetCollectedBindData(); var bindSucceeded = false; CollectBindData(targetObject.transform); @@ -659,6 +693,11 @@ namespace AlicizaX.UI.Editor EditorPrefs.DeleteKey(GenerateTypeNameKey); EditorPrefs.DeleteKey(GenerateInstanceIdKey); EditorPrefs.DeleteKey(GenerateAssetPathKey); + ResetCollectedBindData(); + } + + private static void ResetCollectedBindData() + { _uiBindDatas.Clear(); _arrayComponents.Clear(); _componentTypeCache.Clear();