public override void OnPointerUp(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } this.pressed = false; UITransitionVisualState newState = UITransitionVisualState.Normal; if (this.active) { newState = UITransitionVisualState.Active; } else if (this.selected) { newState = UITransitionVisualState.Selected; } else if (this.highlighted) { newState = UITransitionVisualState.Highlighted; } this.DoStateTransition(newState, false); }
private void DoStateTransition(UITransitionVisualState state, bool instant) { // Check if active in the scene if (!this.gameObject.activeInHierarchy) { return; } if (!this.IsInteractable()) { state = UITransitionVisualState.Normal; } Color color = this.NormalColor; // Prepare the transition values switch (state) { case UITransitionVisualState.Normal: color = this.NormalColor; break; case UITransitionVisualState.Highlighted: color = this.HighlightedColor; break; case UITransitionVisualState.Selected: color = this.SelectedColor; break; case UITransitionVisualState.Pressed: color = this.PressedColor; break; case UITransitionVisualState.Active: color = this.ActiveColor; break; } this.StartColorTween(this.GetEffectColor(), color, false, this.SetEffectColor); }
private void DoStateTransition(UITransitionVisualState state, bool instant) { // Check if the script is enabled if (!this.gameObject.activeInHierarchy) { return; } // Check if it's interactable if (!this.IsInteractable()) { state = UITransitionVisualState.Normal; } Color color = this.NormalColor; Sprite newSprite = null; string triggerName = this.NormalTrigger; // Prepare the transition values switch (state) { case UITransitionVisualState.Normal: { color = this.NormalColor; triggerName = this.NormalTrigger; break; } case UITransitionVisualState.Pressed: { color = this.PressedColor; newSprite = this.PressedSprite; triggerName = this.PressedTrigger; break; } } // Do the transition switch (this.TransitionMode) { case UITransitionMode.ColorTint: { this.StartColorTween(color * this.ColorMultiplier, instant); break; } case UITransitionMode.SpriteSwap: { this.DoSpriteSwap(newSprite); break; } case UITransitionMode.Animation: { this.TriggerAnimation(triggerName); break; } case UITransitionMode.TextColor: { this.StartColorTween((this.TargetGraphic as Text).color, color, false, this.SetTextColor); break; } case UITransitionMode.TextColorTMP: { this.StartColorTween((this.TargetGraphic as TextMeshProUGUI).color, color, false, this.SetTextColorTMP); break; } } }