This commit is contained in:
陈思海 2025-07-29 15:57:51 +08:00
parent 06db141830
commit acd6338626

View File

@ -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);