修改
This commit is contained in:
parent
574ba0df7d
commit
6061b51dbd
@ -36,7 +36,6 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
|
|||||||
private bool m_IsDown;
|
private bool m_IsDown;
|
||||||
private bool m_HasExitedWhileDown;
|
private bool m_HasExitedWhileDown;
|
||||||
private bool _mTogSelected;
|
private bool _mTogSelected;
|
||||||
private Animator _animator;
|
|
||||||
private Coroutine _resetRoutine;
|
private Coroutine _resetRoutine;
|
||||||
private WaitForSeconds _waitFadeDuration;
|
private WaitForSeconds _waitFadeDuration;
|
||||||
|
|
||||||
@ -47,21 +46,10 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
|
|||||||
|
|
||||||
private bool m_IsNavFocused = false;
|
private bool m_IsNavFocused = false;
|
||||||
|
|
||||||
private static readonly Dictionary<string, int> _animTriggerCache = new()
|
|
||||||
{
|
|
||||||
{ "Normal", Animator.StringToHash("Normal") },
|
|
||||||
{ "Highlighted", Animator.StringToHash("Highlighted") },
|
|
||||||
{ "Pressed", Animator.StringToHash("Pressed") },
|
|
||||||
{ "Selected", Animator.StringToHash("Selected") },
|
|
||||||
{ "Disabled", Animator.StringToHash("Disabled") },
|
|
||||||
};
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
private Animator Animator => _animator ? _animator : _animator = GetComponent<Animator>();
|
|
||||||
|
|
||||||
public bool Selected
|
public bool Selected
|
||||||
{
|
{
|
||||||
get => _mTogSelected;
|
get => _mTogSelected;
|
||||||
@ -538,22 +526,6 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
|
|||||||
base.ApplyTransition(m_ChildTransitions[i], state, instant);
|
base.ApplyTransition(m_ChildTransitions[i], state, instant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 覆盖 PlayAnimation:使用 UXButton 的 Animator 与 trigger 缓存(保持原逻辑)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="trigger"></param>
|
|
||||||
protected override void PlayAnimation(string trigger)
|
|
||||||
{
|
|
||||||
if (!Animator || !Animator.isActiveAndEnabled || string.IsNullOrEmpty(trigger))
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (int id in _animTriggerCache.Values)
|
|
||||||
Animator.ResetTrigger(id);
|
|
||||||
|
|
||||||
if (_animTriggerCache.TryGetValue(trigger, out int hash))
|
|
||||||
Animator.SetTrigger(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PlayAudio(AudioClip clip)
|
private void PlayAudio(AudioClip clip)
|
||||||
{
|
{
|
||||||
if (clip && UXComponentExtensionsHelper.AudioHelper != null)
|
if (clip && UXComponentExtensionsHelper.AudioHelper != null)
|
||||||
@ -562,7 +534,6 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public void Focus()
|
public void Focus()
|
||||||
{
|
{
|
||||||
if (!IsInteractable())
|
if (!IsInteractable())
|
||||||
|
|||||||
@ -58,6 +58,19 @@ namespace UnityEngine.UI
|
|||||||
protected int m_CurrentIndex = -1;
|
protected int m_CurrentIndex = -1;
|
||||||
protected bool m_EnableCalled = false;
|
protected bool m_EnableCalled = false;
|
||||||
|
|
||||||
|
private Animator _animator;
|
||||||
|
public Animator Animator => _animator ? _animator : _animator = GetComponent<Animator>();
|
||||||
|
|
||||||
|
public static readonly Dictionary<string, int> _animTriggerCache = new()
|
||||||
|
{
|
||||||
|
{ "Normal", Animator.StringToHash("Normal") },
|
||||||
|
{ "Highlighted", Animator.StringToHash("Highlighted") },
|
||||||
|
{ "Pressed", Animator.StringToHash("Pressed") },
|
||||||
|
{ "Selected", Animator.StringToHash("Selected") },
|
||||||
|
{ "Disabled", Animator.StringToHash("Disabled") },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public Graphic targetGraphic
|
public Graphic targetGraphic
|
||||||
{
|
{
|
||||||
get { return m_MainTransition.targetGraphic; }
|
get { return m_MainTransition.targetGraphic; }
|
||||||
@ -644,7 +657,14 @@ namespace UnityEngine.UI
|
|||||||
/// <param name="trigger"></param>
|
/// <param name="trigger"></param>
|
||||||
protected virtual void PlayAnimation(string trigger)
|
protected virtual void PlayAnimation(string trigger)
|
||||||
{
|
{
|
||||||
// base does nothing — subclasses (e.g. UXButton) can override to use Animator.
|
if (!Animator || !Animator.isActiveAndEnabled || string.IsNullOrEmpty(trigger) || !gameObject.activeInHierarchy)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (int id in _animTriggerCache.Values)
|
||||||
|
Animator.ResetTrigger(id);
|
||||||
|
|
||||||
|
if (_animTriggerCache.TryGetValue(trigger, out int hash))
|
||||||
|
Animator.SetTrigger(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user