/// <summary> /// 按下时 /// </summary> /// <param name="eventData">指针事件</param> public void OnPointerDown(PointerEventData eventData) { if (m_Button && m_Button.isActiveAndEnabled && m_Button.interactable && eventData.button == PointerEventData.InputButton.Left) { m_PressTime = Time.time; if (m_State.Mode == HotkeyManager.HotkeyMode.Press) { HotkeyManager.Instance.PlayHotKeySound(m_State, InputActionPhase.Started); if (m_State.Callback != null) { m_State.Callback.Invoke(HotkeyCallback.CreateFrom(HotkeyPhase.Started, Time.time, m_PressTime, Time.time - m_PressTime, true)); } } else if (m_State.Mode == HotkeyManager.HotkeyMode.Hold) { if (!m_State.Holding) { PlayStartAnim(); HotkeyManager.Instance.PlayHotKeySound(m_State, InputActionPhase.Started); if (m_State.Callback != null) { m_State.Callback.Invoke(HotkeyCallback.CreateFrom(HotkeyPhase.Started, Time.time, m_PressTime, m_State.HoldDuration, true)); } Progress = 0; } } } }
/// <summary> /// 更新 /// </summary> private void Update() { if (!gameObject.activeInHierarchy) { return; } if (!m_Button || !m_Button.isActiveAndEnabled || !m_Button.interactable) { return; } if (m_State.Mode != HotkeyManager.HotkeyMode.Hold) { return; } if (m_State.Holding) { return; } if (m_PressTime > 0) { float progress = Mathf.Clamp01((Time.time - m_PressTime) / m_State.HoldDuration); if (progress < 1) { if (m_State.Callback != null) { m_State.Callback.Invoke(HotkeyCallback.CreateFrom(HotkeyPhase.Started, Time.time, m_PressTime, m_State.HoldDuration, true)); } Progress = progress; float repc = progress * 10.0f; WwiseManager.SetParameter(WwiseRtpc.Rtpc_UI_Hotkey, repc); } else { PlayFinishAnim(); HotkeyManager.Instance.PlayHotKeySound(m_State, InputActionPhase.Performed); if (m_State.Callback != null) { m_State.Callback.Invoke(HotkeyCallback.CreateFrom(HotkeyPhase.Performed, Time.time, m_PressTime, m_State.HoldDuration, true)); } Progress = 0; m_PressTime = 0; } } }
/// <summary> /// 松开时 /// </summary> /// <param name="eventData">指针事件</param> public void OnPointerUp(PointerEventData eventData) { if (m_Button && m_Button.isActiveAndEnabled && m_Button.interactable && eventData.button == PointerEventData.InputButton.Left) { if (m_State.Mode == HotkeyManager.HotkeyMode.Press) { if (m_PressTime > 0) { HotkeyManager.Instance.PlayHotKeySound(m_State, InputActionPhase.Performed); if (m_State.Callback != null) { m_State.Callback.Invoke(HotkeyCallback.CreateFrom(HotkeyPhase.Performed, Time.time, m_PressTime, Time.time - m_PressTime, true)); } } } else if (m_State.Mode == HotkeyManager.HotkeyMode.Hold) { if (!m_State.Holding) { float progress = Mathf.Clamp01((Time.time - m_PressTime) / m_State.HoldDuration); if (progress < 1) { HotkeyManager.Instance.PlayHotKeySound(m_State, InputActionPhase.Canceled); if (m_State.Callback != null) { m_State.Callback.Invoke(HotkeyCallback.CreateFrom(HotkeyPhase.Canceled, Time.time, m_PressTime, m_State.HoldDuration, true)); } Progress = 0; } } } m_PressTime = 0; } }