From acd6338626fafd344e6dd3738e97ef3950bdbb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Tue, 29 Jul 2025 15:57:51 +0800 Subject: [PATCH] modify --- Editor/UX/UXButtonEditor.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Editor/UX/UXButtonEditor.cs b/Editor/UX/UXButtonEditor.cs index 742a3fd..d717d93 100644 --- a/Editor/UX/UXButtonEditor.cs +++ b/Editor/UX/UXButtonEditor.cs @@ -479,7 +479,8 @@ internal class UXButtonEditor : Editor { if (GUILayout.Button("Auto Generate Animation")) { - var controller = GenerateSelectableAnimatorContoller((target as Selectable).animationTriggers, target as Selectable); + var animationTrigger = m_TransitionData.FindPropertyRelative("animationTriggers"); + var controller = GenerateSelectableAnimatorContoller(animationTrigger, target as UXButton); if (controller != null) { if (animator == null) @@ -505,7 +506,7 @@ internal class UXButtonEditor : Editor GUILayout.EndVertical(); } - private static UnityEditor.Animations.AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, Selectable target) + private static UnityEditor.Animations.AnimatorController GenerateSelectableAnimatorContoller(SerializedProperty property, UXButton target) { if (target == null) return null; @@ -513,12 +514,17 @@ internal class UXButtonEditor : Editor var path = GetSaveControllerPath(target); if (string.IsNullOrEmpty(path)) return null; + SerializedProperty normalTrigger = property.FindPropertyRelative("normalTrigger"); + SerializedProperty highlightedTrigger = property.FindPropertyRelative("highlightedTrigger"); + SerializedProperty pressedTrigger = property.FindPropertyRelative("pressedTrigger"); + SerializedProperty selectedTrigger = property.FindPropertyRelative("selectedTrigger"); + SerializedProperty disabledTrigger = property.FindPropertyRelative("disabledTrigger"); - var normalName = string.IsNullOrEmpty(animationTriggers.normalTrigger) ? "Normal" : animationTriggers.normalTrigger; - var highlightedName = string.IsNullOrEmpty(animationTriggers.highlightedTrigger) ? "Highlighted" : animationTriggers.highlightedTrigger; - var pressedName = string.IsNullOrEmpty(animationTriggers.pressedTrigger) ? "Pressed" : animationTriggers.pressedTrigger; - var selectedName = string.IsNullOrEmpty(animationTriggers.selectedTrigger) ? "Selected" : animationTriggers.selectedTrigger; - var disabledName = string.IsNullOrEmpty(animationTriggers.disabledTrigger) ? "Disabled" : animationTriggers.disabledTrigger; + var normalName = string.IsNullOrEmpty(normalTrigger.stringValue) ? "Normal" : normalTrigger.stringValue; + var highlightedName = string.IsNullOrEmpty(highlightedTrigger.stringValue) ? "Highlighted" : highlightedTrigger.stringValue; + var pressedName = string.IsNullOrEmpty(pressedTrigger.stringValue) ? "Pressed" : pressedTrigger.stringValue; + var selectedName = string.IsNullOrEmpty(selectedTrigger.stringValue) ? "Selected" : selectedTrigger.stringValue; + var disabledName = string.IsNullOrEmpty(disabledTrigger.stringValue) ? "Disabled" : disabledTrigger.stringValue; var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(path); GenerateTriggerableTransition(normalName, controller); @@ -551,7 +557,7 @@ internal class UXButtonEditor : Editor return clip; } - private static string GetSaveControllerPath(Selectable target) + private static string GetSaveControllerPath(UXButton target) { var defaultName = target.gameObject.name; var message = string.Format("Create a new animator for the game object '{0}':", defaultName);