This commit is contained in:
陈思海 2025-07-29 17:25:18 +08:00
parent 1998b9db2d
commit b7bbd9f6c6
2 changed files with 25 additions and 17 deletions

View File

@ -18,7 +18,6 @@ internal class UXButtonEditor : Editor
Sound, Sound,
Event Event
} }
private SerializedProperty m_Interactable; private SerializedProperty m_Interactable;
private SerializedProperty m_Mode; private SerializedProperty m_Mode;
private SerializedProperty m_OnValueChanged; private SerializedProperty m_OnValueChanged;
@ -387,7 +386,7 @@ internal class UXButtonEditor : Editor
if (animator == null) if (animator == null)
{ {
Rect warningRect = new Rect(position.x, y, position.width, lineHeight); Rect warningRect = new Rect(position.x, y, position.width, lineHeight);
EditorGUI.HelpBox(warningRect, "需要Animation || Animator组件来使用动画切换", MessageType.Warning); EditorGUI.HelpBox(warningRect, "需要Animator组件来使用动画切换", MessageType.Warning);
y += lineHeight + spacing; y += lineHeight + spacing;
} }
@ -447,7 +446,7 @@ internal class UXButtonEditor : Editor
EditorGUILayout.PropertyField(transition); EditorGUILayout.PropertyField(transition);
var animator = graphic != null ? graphic.GetComponent<Animator>() : null; var animator = graphic != null ? graphic.GetComponent<Animator>() : (target as UXButton).GetComponent<Animator>();
switch (currentTransition) switch (currentTransition)
{ {
case Selectable.Transition.ColorTint: case Selectable.Transition.ColorTint:
@ -460,7 +459,7 @@ internal class UXButtonEditor : Editor
break; break;
case Selectable.Transition.Animation: case Selectable.Transition.Animation:
if (animator == null) if (animator == null)
EditorGUILayout.HelpBox("需要Animation || Animator组件来使用动画切换", MessageType.Warning); EditorGUILayout.HelpBox("需要Animator组件来使用动画切换", MessageType.Warning);
break; break;
} }

View File

@ -113,13 +113,17 @@ public class UXButton : UIBehaviour, IButton,
#region Unity Lifecycle #region Unity Lifecycle
protected override void Awake() #if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
if (!Application.isPlaying)
{ {
base.Awake();
_boardEvent = true; _boardEvent = true;
_waitTimeFadeDuration = new WaitForSeconds( _waitTimeFadeDuration = new WaitForSeconds(
Mathf.Max(0.01f, m_TransitionData.colors.fadeDuration)); Mathf.Max(0.01f, m_TransitionData.colors.fadeDuration));
_animTriggerIDs.Clear();
_animResetTriggerIDs.Clear();
var triggers = m_TransitionData.animationTriggers; var triggers = m_TransitionData.animationTriggers;
AddTriggerID(triggers.normalTrigger); AddTriggerID(triggers.normalTrigger);
AddTriggerID(triggers.highlightedTrigger); AddTriggerID(triggers.highlightedTrigger);
@ -127,8 +131,13 @@ public class UXButton : UIBehaviour, IButton,
AddTriggerID(triggers.selectedTrigger); AddTriggerID(triggers.selectedTrigger);
AddTriggerID(triggers.disabledTrigger); AddTriggerID(triggers.disabledTrigger);
UpdateVisualState(m_SelectionState, true); UpdateVisualState(m_SelectionState, true);
} }
}
#endif // if UNITY_EDITOR
protected override void OnDestroy() protected override void OnDestroy()
{ {
@ -274,7 +283,7 @@ public class UXButton : UIBehaviour, IButton,
private void ProcessTransitionData(TransitionData transition, SelectionState state, bool instant) private void ProcessTransitionData(TransitionData transition, SelectionState state, bool instant)
{ {
if (transition.targetGraphic == null) return; if ((transition.transition == Selectable.Transition.ColorTint || transition.transition == Selectable.Transition.SpriteSwap) && transition.targetGraphic == null) return;
Color tintColor; Color tintColor;
Sprite transitionSprite; Sprite transitionSprite;