Example #1
0
 private void PrintBehaviorDebugMessage(UIButtonBehavior behavior, string action, bool debug = false)
 {
     if (DebugComponent || debug)
     {
         DDebug.Log("(" + ButtonName + ") UIButton - " + behavior.BehaviorType + " - " + action + ".", this);
     }
 }
Example #2
0
 private IEnumerator DisableButtonBehaviorEnumerator(UIButtonBehavior behavior)
 {
     behavior.Ready = false;
     if (Settings.IgnoreUnityTimescale)                                      //check if the UI ignores Unity's Time.Timescale or not
     {
         yield return(new WaitForSecondsRealtime(behavior.DisableInterval)); //wait for seconds realtime (ignore Unity's Time.Timescale)
     }
     else
     {
         yield return(new WaitForSeconds(behavior.DisableInterval)); //wait for seconds (respect Unity's Time.Timescale)
     }
     behavior.Ready = true;
 }
Example #3
0
        private void TriggerButtonBehavior(UIButtonBehavior behavior, bool debug = false)
        {
            switch (behavior.BehaviorType)
            {
            case UIButtonBehaviorType.OnClick:
                if (!Interactable || UIInteractionsDisabled)
                {
                    return;
                }
                if (!behavior.Ready)
                {
                    return;
                }
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                InitiateClick();
                break;

            case UIButtonBehaviorType.OnPointerEnter:
                StopNormalLoopAnimation();
                StopSelectedLoopAnimation();
                if (!Interactable || UIInteractionsDisabled)
                {
                    return;
                }
                if (!behavior.Ready)
                {
                    return;
                }
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                ExecutePointerEnter();
                break;

            case UIButtonBehaviorType.OnPointerExit:
                if (IsSelected)
                {
                    StartSelectedLoopAnimation();
                }
                else
                {
                    StartNormalLoopAnimation();
                }
                if (!Interactable || UIInteractionsDisabled)
                {
                    return;
                }
                if (!behavior.Ready)
                {
                    return;
                }
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                ExecutePointerExit();
                break;

            case UIButtonBehaviorType.OnPointerDown:
                if (!Interactable || UIInteractionsDisabled)
                {
                    return;
                }
                if (!behavior.Ready)
                {
                    return;
                }
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                ExecutePointerDown();
                break;

            case UIButtonBehaviorType.OnPointerUp:
                if (!Interactable || UIInteractionsDisabled)
                {
                    return;
                }
                if (!behavior.Ready)
                {
                    return;
                }
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                ExecutePointerUp();
                break;

            case UIButtonBehaviorType.OnSelected:
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                ExecuteOnButtonSelected();
                break;

            case UIButtonBehaviorType.OnDeselected:
                if (behavior.Enabled)
                {
                    PrintBehaviorDebugMessage(behavior, "triggered", debug);
                }
                ExecuteOnButtonDeselected();
                break;
            }
        }
Example #4
0
        private IEnumerator ExecuteButtonBehaviorEnumerator(UIButtonBehavior behavior)
        {
            if (!behavior.Enabled)
            {
                yield break;
            }

            if (!m_updateStartValuesRequired) //on the first interaction update the start values so that the reset method works as intended
            {
                UpdateStartValues();
                m_updateStartValuesRequired = true;
            }

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (behavior.BehaviorType)
            {
            case UIButtonBehaviorType.OnClick:
            case UIButtonBehaviorType.OnDoubleClick:
            case UIButtonBehaviorType.OnLongClick:
            case UIButtonBehaviorType.OnPointerEnter:
            case UIButtonBehaviorType.OnPointerExit:
            case UIButtonBehaviorType.OnPointerDown:
            case UIButtonBehaviorType.OnPointerUp:
                if (!Interactable || UIInteractionsDisabled)
                {
                    yield break;
                }
                break;
            }

            StopNormalLoopAnimation();
            StopSelectedLoopAnimation();
            behavior.PlayAnimation(this);
            behavior.OnTrigger.ExecuteEffect(behavior.OnTrigger.GetCanvas(gameObject));
            behavior.OnTrigger.InvokeAnimatorEvents();

            if (behavior.TriggerEventsAfterAnimation)
            {
                yield return(new WaitForSecondsRealtime(behavior.GetAnimationTotalDuration())); //wait for seconds realtime (ignore Unity's Time.Timescale)
            }
            behavior.OnTrigger.SendGameEvents(gameObject);

            if (IsBackButton &&
                (behavior.BehaviorType == UIButtonBehaviorType.OnClick ||
                 behavior.BehaviorType == UIButtonBehaviorType.OnDoubleClick ||
                 behavior.BehaviorType == UIButtonBehaviorType.OnLongClick))
            {
                BackButton.Instance.Execute();
            }
            else
            {
                behavior.OnTrigger.InvokeAction(gameObject);
                behavior.OnTrigger.InvokeUnityEvent();
                NotifySystemOfTriggeredBehavior(behavior.BehaviorType);
            }


            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (behavior.BehaviorType)
            {
            case UIButtonBehaviorType.OnSelected:
                StartSelectedLoopAnimation();
                break;

            case UIButtonBehaviorType.OnDeselected:
                StartNormalLoopAnimation();
                break;

            case UIButtonBehaviorType.OnClick:
            case UIButtonBehaviorType.OnDoubleClick:
            case UIButtonBehaviorType.OnLongClick:
                if (DeselectButtonAfterClick)
                {
                    if (DebugComponent)
                    {
                        DDebug.Log("(" + ButtonName + ") UIButton - " + behavior.BehaviorType + " - Deselect Button.", this);
                    }
                    DeselectButton();
                }

                break;

            case UIButtonBehaviorType.OnPointerEnter:
                if (behavior.SelectButton)
                {
                    if (DebugComponent)
                    {
                        DDebug.Log("(" + ButtonName + ") UIButton - " + behavior.BehaviorType + " - Select Button.", this);
                    }
                    SelectButton();
                }

                break;

            case UIButtonBehaviorType.OnPointerExit:
                if (behavior.DeselectButton)
                {
                    if (DebugComponent)
                    {
                        DDebug.Log("(" + ButtonName + ") UIButton - " + behavior.BehaviorType + " - Deselect Button.", this);
                    }
                    DeselectButton();
                }

                if (IsSelected)
                {
                    StartSelectedLoopAnimation();
                }
                else
                {
                    StartNormalLoopAnimation();
                }

                break;

            case UIButtonBehaviorType.OnPointerDown:
                if (behavior.SelectButton)
                {
                    if (DebugComponent)
                    {
                        DDebug.Log("(" + ButtonName + ") UIButton - " + behavior.BehaviorType + " - Select Button.", this);
                    }
                    SelectButton();
                }

                break;

            case UIButtonBehaviorType.OnPointerUp:
                if (behavior.DeselectButton)
                {
                    if (DebugComponent)
                    {
                        DDebug.Log("(" + ButtonName + ") UIButton - " + behavior.BehaviorType + " - Deselect Button.", this);
                    }
                    DeselectButton();
                }

                break;
            }
        }