Пример #1
0
        internal async Task Hide(bool force = false)
        {
            if (!_isOverlayShow)
            {
                return;
            }

            await Task.Delay(HideMillisecondsDelay);

            if (!force && !IsContainTrigger(TriggerType.Click) && (_isPreventHide || _mouseInOverlay || _isChildOverlayShow))
            {
                return;
            }

            _isOverlayFirstRender        = true;
            _isWaitForOverlayFirstRender = false;
            _isOverlayHiding             = true;

            _overlayCls = Trigger.GetOverlayLeaveClass();

            await Trigger.OnOverlayHiding.InvokeAsync(true);

            await UpdateParentOverlayState(false);

            StateHasChanged();

            // wait for leave animation
            await Task.Delay(WaitForHideAnimMilliseconds);

            _isOverlayShow   = false;
            _isOverlayHiding = false;

            await Trigger.OnVisibleChange.InvokeAsync(false);

            StateHasChanged();

            OnHide?.Invoke();
        }
Пример #2
0
    /// <summary>
    /// Change the visibilty of the object by playing the desired animation.
    /// </summary>
    /// <param name="visible">Should this element be visible?</param>
    /// <param name="trivial">If true, sounds won't play and events won't fire</param>
    public override void ChangeVisibility(bool visible, bool trivial = false)
    {
        forceVisibilityCall = true;

        if (!Initialized)
        {
            Initialize();
        }

        //If this GameObject is not active, then change to the desired visibility immediatly and enable it.
        if (!gameObject.activeSelf)
        {
            ChangeVisibilityImmediate(Visible);
            gameObject.SetActive(true);
        }

        //If there's a change in visibility, then play the sound clips. (to avoid playing them if the element is already at the desired visibility when a new call is made)
        if (Visible != visible && !trivial)
        {
            if (SFXManager.Instance)
            {
                if (soundEnum != null)
                {
                    StopCoroutine(soundEnum);
                }

                if (visible)
                {
                    soundEnum = PlaySoundAfter(ShowingClip, ShowAfter);
                }
                else
                {
                    soundEnum = PlaySoundAfter(HidingClip, HideAfter);
                }

                //Since coroutines can only start on active objects, then don't try starting them if the object isn't active.
                if (gameObject.activeInHierarchy)
                {
                    StartCoroutine(soundEnum);
                }
            }
            else if (ShowingClip || HidingClip)
            {
                Debug.LogError("You're trying to play sounds with no SFXManager in the scene. Please add one via Tools>ZUI>Creation Window...>Setup", gameObject);
            }
        }

        Visible = visible;

        #region Events Handling
        if (!trivial)
        {
            if (startEventEnum != null)
            {
                StopCoroutine(startEventEnum);
            }
            if (completeEventEnum != null)
            {
                StopCoroutine(completeEventEnum);
            }

            if (visible)
            {
                if (OnShow != null)
                {
                    startEventEnum = FireEventAfter(OnShow, ShowAfter);
                }
                if (OnShowComplete != null)
                {
                    completeEventEnum = FireEventAfter(OnShowComplete, showingTime);
                }
            }
            else if (!visible)
            {
                if (OnHide != null)
                {
                    startEventEnum = FireEventAfter(OnHide, HideAfter);
                }
                //Only start waiting to fire the hide complete event if the element will not deactivate (because if it's deactivated before firing then the event won't fire)..
                //...and fire it in DeactivateMe function instead
                if (OnHideComplete != null && !DeactivateWhileInvisible)
                {
                    completeEventEnum = FireEventAfter(OnHideComplete, hidingTime);
                }
            }

            //Since coroutines can only start on active objects, then don't try starting them if the object isn't active.
            if (gameObject.activeInHierarchy)
            {
                StartCoroutine(startEventEnum);
                StartCoroutine(completeEventEnum);
            }
        }
        #endregion

        //If this element is set to use simple activation (enabling and disabling the gameObject) then do it and get out of the function.
        if (UseSimpleActivation)
        {
            ControlActivation(visible);
            if (visible && OnShow != null)
            {
                OnShow.Invoke();
            }
            else if (!visible && OnHide != null)
            {
                OnHide.Invoke();
            }
            return;
        }

        if (MovementSection.UseSection)
        {
            #region Movement Control
            MotionType type     = GetSectionType(MovementSection);
            float      duration = GetSectionDuration(MovementSection);
            EasingEquationsParameters easingParams = GetEasingParams(MovementSection);

            ControlMovement(visible, type, HidingPosition, duration, easingParams, EdgeGap, false, MovementSection.WantedVectorValue, LocalCustomPosition);
            #endregion
        }
        if (RotationSection.UseSection)
        {
            #region Rotation Control
            MotionType type     = GetSectionType(RotationSection);
            float      duration = GetSectionDuration(RotationSection);
            EasingEquationsParameters easingParams = GetEasingParams(RotationSection);

            ControlRotation(visible, type, visible ? ShowingDirection : HidingDirection, RotationSection.WantedVectorValue, duration, easingParams, false);
            #endregion
        }
        if (ScaleSection.UseSection)
        {
            #region Scale Control
            MotionType type     = GetSectionType(ScaleSection);
            float      duration = GetSectionDuration(ScaleSection);
            EasingEquationsParameters easingParams = GetEasingParams(ScaleSection);

            ControlScale(visible, type, ScaleSection.WantedVectorValue, duration, easingParams, false);
            #endregion
        }
        if (OpacitySection.UseSection)
        {
            #region Opacity Control
            MotionType type     = GetSectionType(OpacitySection);
            float      duration = GetSectionDuration(OpacitySection);
            EasingEquationsParameters easingParams = GetEasingParams(OpacitySection);

            ControlOpacity(visible, type, OpacitySection.WantedFloatValue, duration, easingParams, false);
            #endregion
        }
        if (SliceSection.UseSection)
        {
            #region Slice Control
            MotionType type     = GetSectionType(SliceSection);
            float      duration = GetSectionDuration(SliceSection);
            EasingEquationsParameters easingParams = GetEasingParams(SliceSection);

            ControlSlice(visible, type, SliceSection.WantedFloatValue, duration, easingParams, false);
            #endregion
        }

        //If set to deactivate while invisible, then wait until the total hiding time passes and deactivate.
        if (DeactivateWhileInvisible)
        {
            if (!visible)
            {
                Invoke("DeactivateMe", hidingTime);
            }
            else
            {
                CancelInvoke("DeactivateMe");
            }
        }
    }
Пример #3
0
 /// <summary>
 /// Is invoked from animator
 /// </summary>
 public void Hide()
 {
     OnHide?.Invoke(this);
     gameObject.SetActive(false);
 }
Пример #4
0
    /// <summary>
    /// Change the visibilty of the menu by playing the desired animation.
    /// </summary>
    /// <param name="visible">Should this menu be visible or not?</param>
    /// <param name="trivial">If true, sounds won't play and events won't fire</param>
    public override void ChangeVisibility(bool visible, bool trivial = false)
    {
        forceVisibilityCall = true;

        if (!Initialized)
        {
            InitializeElements();
        }
        if (!gameObject.activeSelf)
        {
            ChangeVisibilityImmediate(Visible, true);
            gameObject.SetActive(true);
        }

        if (!UseSimpleActivation)
        {
            foreach (UIElement e in AnimatedElements)
            {
                if (e == null || !e.MenuDependent)
                {
                    continue;
                }

                e.ChangeVisibility(visible);
            }
        }
        else
        {
            gameObject.SetActive(visible);
        }

        if (Visible != visible && !trivial)
        {
            if (SFXManager.Instance)
            {
                SFXManager.Instance.PlayClip(visible ? ShowingClip : HidingClip);
            }
            else if (ShowingClip || HidingClip)
            {
                Debug.LogError("You're trying to play sounds with no SFXManager in the scene. Please add one via Tools>ZUI>Creation Window...>Setup", gameObject);
            }
        }

        Visible = visible;

        if (!trivial)
        {
            if (completeEventEnum != null)
            {
                StopCoroutine(completeEventEnum);
            }

            if (visible)
            {
                if (OnShow != null)
                {
                    OnShow.Invoke();
                }
                if (OnShowComplete != null)
                {
                    completeEventEnum = FireEventAfter(OnShowComplete, showingTime);
                }
            }
            else if (!visible)
            {
                if (OnHide != null)
                {
                    OnHide.Invoke();
                }
                //Only start waiting to fire the hide complete event if the element will not deactivate (because if it's deactivated before firing then the event won't fire)..
                //...and fire it in DeactivateMe function instead
                if (OnHideComplete != null && !DeactivateWhileInvisible)
                {
                    completeEventEnum = FireEventAfter(OnHideComplete, hidingTime);
                }
            }

            //Since coroutines can only start on active objects, then don't try starting them if the object isn't active.
            if (gameObject.activeInHierarchy && completeEventEnum != null)
            {
                StartCoroutine(completeEventEnum);
            }
        }

        if (DeactivateWhileInvisible)
        {
            if (!visible)
            {
                Invoke("DeactivateMe", hidingTime);
            }
            else
            {
                CancelInvoke("DeactivateMe");
            }
        }
    }
Пример #5
0
 private static void HideMessage()
 {
     OnHide?.Invoke(Instance.text.text);
     SetActive(false);
 }
Пример #6
0
 public void Hide()
 => OnHide?.Invoke();
Пример #7
0
 public void Hide()
 {
     show = false;
     OnHide.Invoke();
 }
Пример #8
0
        /// <summary>
        /// Performed when Hide processes completed.
        /// In inherited classes always use base.HideEnd() when overriding this method.
        /// </summary>
        protected virtual void HideEnd()
        {
            OnHide.InvokeIfNotNull();

            SetActive(false);
        }
Пример #9
0
 public void Hide()
 {
     _shown = false;
     OnHide?.Invoke();
 }
Пример #10
0
 private void HideToast(object source)
 {
     OnHide?.Invoke();
 }
Пример #11
0
 public void HideSpinner()
 {
     OnHide?.Invoke();
 }
Пример #12
0
        // ElementA hide completed
        private void ElementAHideWithoutCallbackCompleted()
        {
            OnHide.InvokeIfNotNull();

            _elementA.OnHide -= ElementAHideWithoutCallbackCompleted;
        }
 /// <summary>
 /// Handles pre-hide event called from the navigator.
 /// </summary>
 protected virtual void OnPreHide()
 {
     OnHide?.Invoke();
 }
Пример #14
0
    /// <summary>
    /// Change the visibility of this element instantly without playing animation.
    /// </summary>
    /// <param name="visible">Should this element be visible or not?</param>
    /// <param name="trivial">If true, sounds won't play and events won't fire</param>
    public override void ChangeVisibilityImmediate(bool visible, bool trivial = false)
    {
        forceVisibilityCall = true;

        if (!Initialized)
        {
            Initialize();
        }
        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }


        //Only play sound effects if visibility has changed.
        if (Visible != visible && !trivial)
        {
            if (SFXManager.Instance)
            {
                SFXManager.Instance.PlayClip(visible ? ShowingClip : HidingClip);
            }
            else if (ShowingClip || HidingClip)
            {
                Debug.LogError("You're trying to play sounds with no SFXManager in the scene. Please add one via Tools>ZUI>Creation Window...>Setup", gameObject);
            }
        }

        Visible = visible;

        if (!trivial)
        {
            if (visible)
            {
                if (OnShow != null)
                {
                    OnShow.Invoke();
                }
                if (OnShowComplete != null)
                {
                    OnShowComplete.Invoke();
                }
            }
            else if (!visible)
            {
                if (OnHide != null)
                {
                    OnHide.Invoke();
                }
                if (OnHideComplete != null)
                {
                    OnHideComplete.Invoke();
                }
            }
        }

        //If this element is set to use simple activation (enabling and disabling the gameObject) then do it and get out of the function.
        if (UseSimpleActivation)
        {
            gameObject.SetActive(visible);
            return;
        }

        //Switch visiblity states in all the used animation sections.
        if (MovementSection.UseSection)
        {
            Vector3 ePos = visible ? MovementSection.startVectorValue : outOfScreenPos;
            myRT.position = ePos;
        }
        if (RotationSection.UseSection)
        {
            Vector3 eEuler = visible ? RotationSection.startVectorValue : RotationSection.WantedVectorValue;
            myRT.eulerAngles = eEuler;
        }
        if (ScaleSection.UseSection)
        {
            Vector3 eScale = visible ? ScaleSection.startVectorValue : ScaleSection.WantedVectorValue;
            myRT.localScale = eScale;
        }
        if (OpacitySection.UseSection)
        {
            float eOpacity = visible ? OpacitySection.startFloatValue : OpacitySection.WantedFloatValue;
            if (TargetFader)
            {
                if (TargetFader is Graphic)
                {
                    Graphic tf  = TargetFader as Graphic;
                    Color   col = tf.color;
                    col.a    = eOpacity;
                    tf.color = col;
                }
                else if (TargetFader is CanvasGroup)
                {
                    CanvasGroup tf = TargetFader as CanvasGroup;
                    tf.alpha = eOpacity;
                }
            }
        }
        if (SliceSection.UseSection)
        {
            float eFill = visible ? SliceSection.startFloatValue : SliceSection.WantedFloatValue;
            if (SliceImage)
            {
                SliceImage.fillAmount = eFill;
            }
        }

        if (DeactivateWhileInvisible && !visible)
        {
            DeactivateMe(false);
        }
    }
Пример #15
0
        public override void ChangeVisibility(bool visible, bool ignoreEvent = false)
        {
            forceVisibilityCall = true;

            if (!Initialized)
            {
                Initialize();
            }

            if (!gameObject.activeSelf)
            {
                if (!UseSimpleActivation)
                {
                    if (MovementSection.UseSection)
                    {
                        Vector3 ePos = visible ? MovementSection.startVectorValue : outOfScreenPos;
                        selfRectTransform.position = ePos;
                    }
                    if (RotationSection.UseSection)
                    {
                        Vector3 eEuler = visible ? RotationSection.startVectorValue : RotationSection.WantedVectorValue;
                        selfRectTransform.eulerAngles = eEuler;
                    }
                    if (ScaleSection.UseSection)
                    {
                        Vector3 eScale = visible ? ScaleSection.startVectorValue : ScaleSection.WantedVectorValue;
                        selfRectTransform.localScale = eScale;
                    }
                    if (OpacitySection.UseSection)
                    {
                        float eOpacity = visible ? OpacitySection.startFloatValue : OpacitySection.WantedFloatValue;
                        if (TargetFader)
                        {
                            if (TargetFader is Graphic)
                            {
                                Graphic tf  = (Graphic)TargetFader;
                                Color   col = tf.color;
                                col.a    = eOpacity;
                                tf.color = col;
                            }
                            else if (TargetFader is CanvasGroup)
                            {
                                CanvasGroup tf = (CanvasGroup)TargetFader;
                                tf.alpha = eOpacity;
                            }
                        }
                    }
                    if (SliceSection.UseSection)
                    {
                        float eFill = visible ? SliceSection.startFloatValue : SliceSection.WantedFloatValue;
                        if (SliceImage)
                        {
                            SliceImage.fillAmount = eFill;
                        }
                    }
                }
                gameObject.SetActive(true);
            }

            Visible = visible;
            if (!ignoreEvent)
            {
                if (startEventEnum != null)
                {
                    StopCoroutine(startEventEnum);
                    startEventEnum = null;
                }

                if (completeEventEnum != null)
                {
                    StopCoroutine(completeEventEnum);
                    completeEventEnum = null;
                }

                if (visible)
                {
                    if (OnShow != null)
                    {
                        startEventEnum = Yielders.DelayCallEvent(OnShow, ShowAfter);
                    }
                    if (OnShowComplete != null)
                    {
                        completeEventEnum = Yielders.DelayCallEvent(OnShowComplete, showingTime);
                    }
                }
                else
                {
                    if (OnHide != null)
                    {
                        startEventEnum = Yielders.DelayCallEvent(OnHide, HideAfter);
                    }
                    if (OnHideComplete != null)
                    {
                        completeEventEnum = Yielders.DelayCallEvent(OnHideComplete, hidingTime);
                    }
                }

                if (gameObject.activeInHierarchy)
                {
                    if (startEventEnum != null)
                    {
                        StartCoroutine(startEventEnum);
                    }
                    if (completeEventEnum != null)
                    {
                        StartCoroutine(completeEventEnum);
                    }
                }
            }

            if (UseSimpleActivation)
            {
                gameObject.SetActive(visible);
                if (startEventEnum != null)
                {
                    StopCoroutine(startEventEnum);
                    startEventEnum = null;
                }

                if (completeEventEnum != null)
                {
                    StopCoroutine(completeEventEnum);
                    completeEventEnum = null;
                }
                if (!ignoreEvent)
                {
                    if (visible)
                    {
                        OnShow?.Invoke();
                        OnShowComplete?.Invoke();
                    }
                    else
                    {
                        OnHide?.Invoke();
                        OnHideComplete?.Invoke();
                    }
                }
                return;
            }

            if (MovementSection.UseSection)
            {
                enMotionType        type         = GetSectionType(MovementSection);
                float               duration     = GetSectionDuration(MovementSection);
                EquationsParameters easingParams = GetEasingParams(MovementSection);
                ControlMovement(visible, type, HidingPosition, duration, easingParams, EdgeGap, MovementSection.WantedVectorValue, LocalCustomPosition);
            }
            if (RotationSection.UseSection)
            {
                enMotionType        type         = GetSectionType(RotationSection);
                float               duration     = GetSectionDuration(RotationSection);
                EquationsParameters easingParams = GetEasingParams(RotationSection);
                ControlRotation(visible, type, visible ? ShowingDirection : HidingDirection, RotationSection.WantedVectorValue, duration, easingParams);
            }
            if (ScaleSection.UseSection)
            {
                enMotionType        type         = GetSectionType(ScaleSection);
                float               duration     = GetSectionDuration(ScaleSection);
                EquationsParameters easingParams = GetEasingParams(ScaleSection);
                ControlScale(visible, type, ScaleSection.WantedVectorValue, duration, easingParams);
            }
            if (OpacitySection.UseSection)
            {
                enMotionType        type         = GetSectionType(OpacitySection);
                float               duration     = GetSectionDuration(OpacitySection);
                EquationsParameters easingParams = GetEasingParams(OpacitySection);
                ControlOpacity(visible, type, OpacitySection.WantedFloatValue, duration, easingParams);
            }
            if (SliceSection.UseSection)
            {
                enMotionType        type         = GetSectionType(SliceSection);
                float               duration     = GetSectionDuration(SliceSection);
                EquationsParameters easingParams = GetEasingParams(SliceSection);
                ControlSlice(visible, type, SliceSection.WantedFloatValue, duration, easingParams);
            }
        }
 AddCallback(OnHide, element.Q <Button>("ButtonHide"));
Пример #17
0
        public override void ChangeVisibilityImmediate(bool visible, bool ignoreEvent = false)
        {
            forceVisibilityCall = true;

            if (!Initialized)
            {
                Initialize();
            }
            if (!gameObject.activeSelf)
            {
                gameObject.SetActive(true);
            }

            Visible = visible;
            if (!ignoreEvent)
            {
                if (visible)
                {
                    OnShow?.Invoke();
                    OnShowComplete?.Invoke();
                }
                else
                {
                    OnHide?.Invoke();
                    OnHideComplete?.Invoke();
                }
            }

            if (UseSimpleActivation)
            {
                gameObject.SetActive(visible);
                return;
            }
            if (MovementSection.UseSection)
            {
                Vector3 ePos = visible ? MovementSection.startVectorValue : outOfScreenPos;
                selfRectTransform.position = ePos;
            }
            if (RotationSection.UseSection)
            {
                Vector3 eEuler = visible ? RotationSection.startVectorValue : RotationSection.WantedVectorValue;
                selfRectTransform.eulerAngles = eEuler;
            }
            if (ScaleSection.UseSection)
            {
                Vector3 eScale = visible ? ScaleSection.startVectorValue : ScaleSection.WantedVectorValue;
                selfRectTransform.localScale = eScale;
            }
            if (OpacitySection.UseSection)
            {
                float eOpacity = visible ? OpacitySection.startFloatValue : OpacitySection.WantedFloatValue;
                if (TargetFader)
                {
                    if (TargetFader is Graphic)
                    {
                        Graphic tf  = (Graphic)TargetFader;
                        Color   col = tf.color;
                        col.a    = eOpacity;
                        tf.color = col;
                    }
                    else if (TargetFader is CanvasGroup)
                    {
                        CanvasGroup tf = (CanvasGroup)TargetFader;
                        tf.alpha = eOpacity;
                    }
                }
            }
            if (SliceSection.UseSection)
            {
                float eFill = visible ? SliceSection.startFloatValue : SliceSection.WantedFloatValue;
                if (SliceImage)
                {
                    SliceImage.fillAmount = eFill;
                }
            }

            if (DeactivateWhileInvisible && !visible)
            {
                gameObject.SetActive(false);
            }
        }
 void Start()
 {
     rend   = GetComponent <Renderer>();
     coll   = GetComponent <Collider2D>();
     onHide = GetComponent <OnHide>();
 }
Пример #19
0
 public async Task Hide()
 {
     await OnHide?.Invoke();
 }
Пример #20
0
 public void Hide()
 {
     Visible = false;
     OnHide?.Invoke();
 }
Пример #21
0
 private void HideToast(object sender, ElapsedEventArgs e)
 {
     OnHide?.Invoke();
 }
Пример #22
0
 private void Hide()
 {
     OnHide?.Invoke();
 }
Пример #23
0
 public void Hide()
 {
     _current.Hide();
     OnHide?.Invoke();
 }
Пример #24
0
 void OnHideScreen(string screenId, HideState state)
 {
     OnHide?.Invoke(new HideEv {
         ScreenId = screenId, State = state
     });
 }
Пример #25
0
    /// <summary>
    /// Change the visibilty of the menu instantly without playing animation.
    /// </summary>
    /// <param name="visible">Should this menu be visible or not?</param>
    /// <param name="trivial">If true, sounds won't play and events won't fire</param>
    public override void ChangeVisibilityImmediate(bool visible, bool trivial = false)
    {
        forceVisibilityCall = true;

        if (!Initialized)
        {
            InitializeElements();
        }
        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }

        if (!UseSimpleActivation)
        {
            foreach (UIElement e in AnimatedElements)
            {
                if (e == null || !e.MenuDependent)
                {
                    continue;
                }

                e.ChangeVisibilityImmediate(visible);
            }
        }
        else
        {
            gameObject.SetActive(visible);
        }

        if (Visible != visible && !trivial)
        {
            if (SFXManager.Instance)
            {
                SFXManager.Instance.PlayClip(visible ? ShowingClip : HidingClip);
            }
            else if (ShowingClip || HidingClip)
            {
                Debug.LogError("You're trying to play sounds with no SFXManager in the scene. Please add one via Tools>ZUI>Creation Window...>Setup", gameObject);
            }
        }

        Visible = visible;

        if (!trivial)
        {
            if (visible)
            {
                if (OnShow != null)
                {
                    OnShow.Invoke();
                }
                if (OnShowComplete != null)
                {
                    OnShowComplete.Invoke();
                }
            }
            else if (!visible)
            {
                if (OnHide != null)
                {
                    OnHide.Invoke();
                }
                if (OnHideComplete != null)
                {
                    OnHideComplete.Invoke();
                }
            }
        }

        if (DeactivateWhileInvisible && !visible)
        {
            DeactivateMe(false);
        }
    }
 public void HideToast()
 {
     OnHide?.Invoke();
 }
Пример #27
0
 public void Hide()
 {
     OnHide?.Invoke();
 }
 public void HideAutorize()
 {
     OnHide?.Invoke();
 }
Пример #29
0
 private void HideToast(object source, ElapsedEventArgs args)
 {
     OnHide?.Invoke();
 }
 private void hide(object s, ElapsedEventArgs args)
 {
     OnHide?.Invoke();
 }