add generate property
This commit is contained in:
parent
357f47112a
commit
9bcf20ad6a
@ -37,6 +37,19 @@ namespace AlicizaX.UI.Editor
|
|||||||
Debug.Log("没有找到符合规则路径的生成配置 请检查!");
|
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)
|
public static bool CheckCanGenerate(GameObject targetObject, UIScriptGenerateData scriptGenerateData)
|
||||||
{
|
{
|
||||||
if (targetObject == null || scriptGenerateData == null) return false;
|
if (targetObject == null || scriptGenerateData == null) return false;
|
||||||
|
|||||||
@ -149,6 +149,12 @@ namespace AlicizaX.UI.Editor
|
|||||||
ScriptFileWriter != null;
|
ScriptFileWriter != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool EnsureVariableGenerationStrategyReady()
|
||||||
|
{
|
||||||
|
return IdentifierFormatter != null &&
|
||||||
|
ScriptCodeEmitter != null;
|
||||||
|
}
|
||||||
|
|
||||||
private static Type ResolveUIElementComponentType(string uiName)
|
private static Type ResolveUIElementComponentType(string uiName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(uiName))
|
if (string.IsNullOrEmpty(uiName))
|
||||||
@ -495,6 +501,37 @@ namespace AlicizaX.UI.Editor
|
|||||||
GenerateScript(generationContext);
|
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)
|
private static void InitializeGenerationContext(GameObject targetObject)
|
||||||
{
|
{
|
||||||
EditorPrefs.SetInt(GenerateInstanceIdKey, targetObject.GetInstanceID());
|
EditorPrefs.SetInt(GenerateInstanceIdKey, targetObject.GetInstanceID());
|
||||||
@ -504,9 +541,7 @@ namespace AlicizaX.UI.Editor
|
|||||||
EditorPrefs.SetString(GenerateAssetPathKey, assetPath);
|
EditorPrefs.SetString(GenerateAssetPathKey, assetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
_uiBindDatas.Clear();
|
ResetCollectedBindData();
|
||||||
_arrayComponents.Clear();
|
|
||||||
_componentTypeCache.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UIGenerationValidationResult ValidateGeneration(UIGenerationContext context)
|
private static UIGenerationValidationResult ValidateGeneration(UIGenerationContext context)
|
||||||
@ -614,8 +649,7 @@ namespace AlicizaX.UI.Editor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_uiBindDatas.Clear();
|
ResetCollectedBindData();
|
||||||
_arrayComponents.Clear();
|
|
||||||
|
|
||||||
var bindSucceeded = false;
|
var bindSucceeded = false;
|
||||||
CollectBindData(targetObject.transform);
|
CollectBindData(targetObject.transform);
|
||||||
@ -659,6 +693,11 @@ namespace AlicizaX.UI.Editor
|
|||||||
EditorPrefs.DeleteKey(GenerateTypeNameKey);
|
EditorPrefs.DeleteKey(GenerateTypeNameKey);
|
||||||
EditorPrefs.DeleteKey(GenerateInstanceIdKey);
|
EditorPrefs.DeleteKey(GenerateInstanceIdKey);
|
||||||
EditorPrefs.DeleteKey(GenerateAssetPathKey);
|
EditorPrefs.DeleteKey(GenerateAssetPathKey);
|
||||||
|
ResetCollectedBindData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ResetCollectedBindData()
|
||||||
|
{
|
||||||
_uiBindDatas.Clear();
|
_uiBindDatas.Clear();
|
||||||
_arrayComponents.Clear();
|
_arrayComponents.Clear();
|
||||||
_componentTypeCache.Clear();
|
_componentTypeCache.Clear();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user