/// <summary> /// Triggers the bound pointer down action /// </summary> public virtual void OnPointerDown(PointerEventData data) { if (!Interactable) { return; } if (Time.time - _lastClickTimestamp < BufferDuration) { return; } if (CurrentState != ButtonStates.Off) { return; } CurrentState = ButtonStates.ButtonDown; _lastClickTimestamp = Time.time; ButtonStateChange?.Invoke(PointerEventData.FramePressState.Pressed, data); if ((Time.timeScale != 0) && (PressedFirstTimeDelay > 0)) { Invoke("InvokePressedFirstTime", PressedFirstTimeDelay); } else { ButtonPressedFirstTime.Invoke(); } }
private void OnDisable() { bool wasActive = CurrentState != ButtonStates.Off && CurrentState != ButtonStates.Disabled; DisableButton(); CurrentState = ButtonStates.Off; // cause it's what is tested to StopInput (for weapon by example) if (wasActive) { ButtonStateChange?.Invoke(PointerEventData.FramePressState.Released, null); ButtonReleased?.Invoke(); } }
/// <summary> /// Triggers the bound pointer up action /// </summary> public virtual void OnPointerUp(PointerEventData data) { if (CurrentState != ButtonStates.ButtonPressed && CurrentState != ButtonStates.ButtonDown) { return; } CurrentState = ButtonStates.ButtonUp; ButtonStateChange?.Invoke(PointerEventData.FramePressState.Released, data); if ((Time.timeScale != 0) && (ReleasedDelay > 0)) { Invoke("InvokeReleased", ReleasedDelay); } else { ButtonReleased.Invoke(); } }
/// <summary> /// button state /// </summary> /// <param name="arg">0:release,1:press</param> private void ButtonPressChanged(int arg) { ButtonStateChange?.Invoke(arg); }