2using System.Collections.Generic;
6using UnityEngine.EventSystems;
11 [JsonObject(MemberSerialization.OptIn)]
19 public virtual string Name =>
null;
78 t.SetActive(enable:
false);
182 public static List<UIButton>
buttons =
new List<UIButton>();
193 if (base.targetGraphic !=
null)
200 foreach (Graphic graphic
in array)
227 if (Application.isPlaying)
238 if (!EventSystem.current)
246 if (EventSystem.current.currentSelectedGameObject == base.gameObject)
248 if (base.transition == Transition.SpriteSwap && base.spriteState.highlightedSprite != base.image.sprite)
271 bool flag =
item !=
null;
272 base.onClick.RemoveAllListeners();
274 base.interactable = flag;
277 icon.enabled =
false;
278 base.interactable =
false;
284 base.onClick.AddListener(delegate
293 icon.SetNativeSize();
297 icon.Rect().sizeDelta =
new Vector2(48f, 48f);
300 tooltip.onShowTooltip = delegate(
UITooltip t)
303 t.textMain.text = textTip;
341 public void SetToggle(
bool isOn, Action<bool> onToggle =
null)
344 base.onClick.RemoveAllListeners();
345 base.onClick.AddListener(delegate
348 if (onToggle !=
null)
358 subText.SetActive(enable:
false);
361 public void SetTooltip(Action<UITooltip> onShowTooltip =
null,
bool enable =
true)
366 public void SetTooltip(
string id, Action<UITooltip> onShowTooltip =
null,
bool enable =
true)
369 tooltip.enable = enable;
370 tooltip.onShowTooltip = onShowTooltip;
375 tooltip.enable =
true;
408 if (eventData.button != 0)
430 EventSystem.current.enabled =
false;
434 EventSystem.current.enabled =
true;
463 if (eventData.button != 0)
465 if (eventData.button == PointerEventData.InputButton.Right && onRightClick != null && !EInput.rightMouse.wasConsumed)
480 currentPressedButton =
null;
484 base.OnPointerUp(eventData);
490 base.OnPointerUp(eventData);
495 if (!locked && IsActive() && IsInteractable())
497 if ((
bool)soundClick)
499 SoundManager.current.Play(soundClick);
501 float realtimeSinceStartup = Time.realtimeSinceStartup;
502 if (lastButton ==
this && onDoubleClick !=
null && realtimeSinceStartup - lastClicked < doubleClickTime)
509 lastClicked = realtimeSinceStartup;
511 base.onClick.Invoke();
518 Invoke(
"_OnPress", 0.01f);
528 DoStateTransition(SelectionState.Highlighted, instant);
533 DoStateTransition(SelectionState.Normal, instant);
538 if ((waiting && state == SelectionState.Highlighted) || !Application.isPlaying)
542 if (!base.interactable)
544 state = SelectionState.Disabled;
546 if ((
bool)highlightTarget)
548 highlightTarget.DoStateTransition(state, instant:
false);
550 if (selected && !imageCheck)
552 if (state == SelectionState.Highlighted)
556 state = SelectionState.Selected;
560 case SelectionState.Normal:
563 icon.transform.localScale = originalIconScale;
566 case SelectionState.Highlighted:
567 currentHighlight =
this;
568 if (lastState != SelectionState.Pressed)
572 if (scaleIcon != 1f && base.interactable)
574 icon.transform.localScale =
new Vector3(scaleIcon, scaleIcon, 1f);
576 if (lastState != SelectionState.Pressed && (
bool)soundHighlight)
578 SoundManager.current.Play(soundHighlight);
581 case SelectionState.Pressed:
582 if (base.transition == Transition.SpriteSwap && base.spriteState.pressedSprite ==
null)
584 SpriteState spriteState = base.spriteState;
585 spriteState.pressedSprite = spriteState.highlightedSprite;
586 base.spriteState = spriteState;
590 icon.transform.localScale =
new Vector3(scaleIcon, scaleIcon, 1f) * 0.9f;
597 tween = animeHold.Play(animeTarget ? animeTarget : base.transform).SetAutoKill(autoKillOnCompletion:
false);
610 icon.transform.localScale = originalIconScale;
612 if ((
bool)animeHold && tween !=
null && !Input.GetMouseButton(0))
614 tween.PlayBackwards();
618 case SelectionState.Disabled:
622 if (base.transition != Transition.ColorTint)
624 base.DoStateTransition(state, instant);
627 ColorTween(state
switch
629 SelectionState.Normal => base.colors.normalColor,
630 SelectionState.Highlighted => base.colors.highlightedColor,
631 SelectionState.Pressed => base.colors.pressedColor,
632 SelectionState.Disabled => base.colors.disabledColor,
634 } * base.colors.colorMultiplier, instant);
639 if (!(base.targetGraphic ==
null))
641 for (
int i = 0; i < Graphics.Count; i++)
643 Graphics[i].CrossFadeColor(targetColor, (!instant) ? base.colors.fadeDuration : 0f, ignoreTimeScale:
true, useAlpha:
true);
650 if (base.navigation.selectOnDown !=
null)
652 return base.FindSelectableOnDown();
654 return FindSelectable(Quaternion.Euler(0f, 0f, navigationFix) * Vector3.down);
659 if (base.navigation.selectOnUp !=
null)
661 return base.FindSelectableOnUp();
663 return FindSelectable(Quaternion.Euler(0f, 0f, navigationFix) * Vector3.up);
668 if (base.navigation.selectOnLeft !=
null)
670 return base.FindSelectableOnLeft();
672 return FindSelectable(Quaternion.Euler(0f, 0f, navigationFix) * Vector3.left);
677 if (base.navigation.selectOnRight !=
null)
679 return base.FindSelectableOnRight();
681 return FindSelectable(Quaternion.Euler(0f, 0f, navigationFix) * Vector3.right);
686 Navigation navigation = base.navigation;
687 navigation.mode = Navigation.Mode.Explicit;
688 navigation.selectOnUp =
up;
689 navigation.selectOnDown =
down;
690 navigation.selectOnLeft =
left;
691 navigation.selectOnRight =
right;
692 base.navigation = navigation;
701 return base.IsActive();
706 if ((
bool)currentPressedButton && onPressed !=
null)
710 if (Input.GetMouseButton(0) || buttons.Count == 0)
714 foreach (
UIButton button
in buttons)
716 if ((
bool)button && (
bool)button.gameObject)
720 button.
tween.PlayBackwards();
721 button.animating =
false;
734 CanvasGroup canvasGroup = base.gameObject.GetComponent<CanvasGroup>();
737 canvasGroup = base.gameObject.AddComponent<CanvasGroup>();
739 canvasGroup.alpha = (enable ? 1f : 0.5f);
740 base.interactable = enable;
749 SpriteState spriteState = base.spriteState;
751 if (base.transition == Transition.ColorTint)
753 base.image.color =
Color.white;
754 ColorBlock colorBlock = base.colors;
755 colorBlock.normalColor = button.
color;
757 base.colors = colorBlock;
761 base.image.color = button.
color;
763 base.spriteState = spriteState;
772 if ((
bool)componentOf)
778 public static void TryShowTip(Transform root =
null,
bool highlight =
true,
bool ignoreWhenRightClick =
true)
780 TryShowTip<UIButton>(root, highlight, ignoreWhenRightClick);
783 public static void TryShowTip<T>(Transform root =
null,
bool highlight =
true,
bool ignoreWhenRightClick =
true) where T :
UIButton
785 actionTooltip = delegate
789 if ((
bool)componentOf && componentOf.tooltip.enable)
792 if ((
bool)componentOf && (root ==
null || componentOf.transform.IsChildOf(root)))
796 componentOf.DoHighlightTransition();
800 componentOf.ShowTooltipForced(ignoreWhenRightClick);
virtual Tween Play(Transform trans, UnityAction onComplete=null, float duration=-1f, float delay=0f)
void WaitForEndOfFrame(Action action)
static Sprite Get(string id)
void Select(UIButton button, bool check=true)