示例#1
0
        public void ControlSlice(bool visible, enMotionType motionType, float fill, float duration, EquationsParameters easingParams)
        {
            if (!SliceImage)
            {
                FindSliceImage();
            }

            if (!SliceImage)
            {
                return;
            }

            float eFill = visible ? SliceSection.startFloatValue : fill;
            float sFill = 0;

            if (!gameObject.activeInHierarchy)
            {
                SliceImage.fillAmount = eFill;
                return;
            }
            sFill = SliceImage.fillAmount;

            if (SliceSection.motionEnum != null)
            {
                StopCoroutine(SliceSection.motionEnum);
                SliceSection.motionEnum = null;
            }

            SliceSection.motionEnum = FloatMotion((f) => { SliceImage.fillAmount = f; }, sFill, eFill, SliceSection.HideAfter,
                                                  SliceSection.ShowAfter, duration, easingParams, motionType);

            StartCoroutine(SliceSection.motionEnum);
        }
示例#2
0
        public void ControlMovement(bool visible, enMotionType motionType, enScreenSides side, float duration, EquationsParameters easingParams, float edgeGap = 0.25f, Vector3 customPosition = new Vector3(), bool customLocal = false)
        {
            Vector3 outPos = outOfScreenPos;

            if (side != HidingPosition || edgeGap != EdgeGap || (side == enScreenSides.Custom && customLocal != LocalCustomPosition))
            {
                outPos = GetHidingPosition(side, edgeGap, customPosition, customLocal);
            }

            Vector3 ePos = visible ? MovementSection.startVectorValue : outPos;
            Vector3 sPos = selfRectTransform.position;

            if (!gameObject.activeInHierarchy)
            {
                selfRectTransform.position = ePos;
                return;
            }

            if (MovementSection.motionEnum != null)
            {
                StopCoroutine(MovementSection.motionEnum);
                MovementSection.motionEnum = null;
            }

            MovementSection.motionEnum = VectorMotion((v) => {
                selfRectTransform.position = v;
            }, sPos, ePos, MovementSection.HideAfter, MovementSection.ShowAfter,
                                                      duration, easingParams, motionType);
            StartCoroutine(MovementSection.motionEnum);
        }
示例#3
0
 public UIAnimationSection(bool use)
 {
     UseSection             = use;
     HideType               = enMotionType.EaseOut;
     ShowType               = enMotionType.EaseOut;
     ShowIsUseHideSameValue = true;
     ShowAfter              = -1;
     HideAfter              = -1;
     ShowingDuration        = -1;
     HidingDuration         = -1;
 }
        public static float GetEaseFloat(float t, enMotionType type, EquationsParameters p)
        {
            float ease = 0;

            switch (type)
            {
            case enMotionType.Custom:
                ease = Custom(t, p.Custom);
                break;

            case enMotionType.Linear:
                ease = Linear(t);
                break;

            case enMotionType.EaseIn:
                ease = EaseIn(t, p.EaseIn);
                break;

            case enMotionType.EaseOut:
                ease = EaseOut(t, p.EaseOut);
                break;

            case enMotionType.EaseInOut:
                ease = EaseInOut(t, p.EaseInOut);
                break;

            case enMotionType.EaseInElastic:
                ease = EaseInElastic(t, p.EaseInElastic);
                break;

            case enMotionType.EaseOutElastic:
                ease = EaseOutElastic(t, p.EaseOutElastic);
                break;

            case enMotionType.EaseInOutElastic:
                ease = EaseInOutElastic(t, p.EaseInOutElastic);
                break;

            case enMotionType.EaseInBounce:
                ease = EaseInBounce(t);
                break;

            case enMotionType.EaseOutBounce:
                ease = EaseOutBounce(t);
                break;

            case enMotionType.EaseInOutBounce:
                ease = EaseInOutBounce(t);
                break;
            }
            return(ease);
        }
示例#5
0
        public void ControlScale(bool visible, enMotionType motionType, Vector3 scale, float duration, EquationsParameters easingParams)
        {
            Vector3 eScale = visible ? ScaleSection.startVectorValue : scale;
            Vector3 sScale = selfRectTransform.localScale;

            if (!gameObject.activeInHierarchy)
            {
                selfRectTransform.localScale = eScale;
                return;
            }

            if (ScaleSection.motionEnum != null)
            {
                StopCoroutine(ScaleSection.motionEnum);
                ScaleSection.motionEnum = null;
            }

            ScaleSection.motionEnum = VectorMotion((v) => { selfRectTransform.localScale = v; }, sScale, eScale, ScaleSection.HideAfter, ScaleSection.ShowAfter, duration, easingParams, motionType);
            StartCoroutine(ScaleSection.motionEnum);
        }
示例#6
0
        public void ControlRotation(bool visible, enMotionType motionType, enRotationDirection direction, Vector3 euler, float duration, EquationsParameters easingParams)
        {
            euler = ClampAngleVector(euler);
            Vector3 eEuler = visible ? RotationSection.startVectorValue : euler;
            Vector3 sEuler = selfRectTransform.eulerAngles;

            if (eEuler.z > sEuler.z)
            {
                if (direction == enRotationDirection.ClockWise)
                {
                    eEuler -= new Vector3(eEuler.x > 0 ? 360 : 0, eEuler.y > 0 ? 360 : 0, eEuler.z > 0 ? 360 : 0);
                }
            }
            else
            {
                if (direction == enRotationDirection.AntiClockWise)
                {
                    sEuler -= new Vector3(sEuler.x > 0 ? 360 : 0, sEuler.y > 0 ? 360 : 0, sEuler.z > 0 ? 360 : 0);
                }
            }

            if (!gameObject.activeInHierarchy)
            {
                selfRectTransform.eulerAngles = eEuler;
                return;
            }

            if (RotationSection.motionEnum != null)
            {
                StopCoroutine(RotationSection.motionEnum);
                RotationSection.motionEnum = null;
            }

            RotationSection.motionEnum = VectorMotion((v) => { selfRectTransform.eulerAngles = v; }, sEuler, eEuler, RotationSection.HideAfter, RotationSection.ShowAfter, duration, easingParams, motionType);
            StartCoroutine(RotationSection.motionEnum);
        }
示例#7
0
        IEnumerator FloatMotion(UnityAction <float> output, float start, float end, float sectionHideAfter, float sectionShowAfter, float duration, EquationsParameters easingParams, enMotionType motionType)
        {
            float startAfter = Visible ? (sectionShowAfter < 0 ? ShowAfter : sectionShowAfter) : (sectionHideAfter < 0 ? HideAfter : sectionHideAfter);

            yield return(Yielders.GetWaitForSeconds(startAfter));

            float curTime   = UseUnscaledTime ? Time.unscaledTime : Time.time;
            float startTime = curTime;

            while (curTime < startTime + duration)
            {
                float t    = (curTime - startTime) / duration;
                float ease = UIAnimationEquations.GetEaseFloat(t, motionType, easingParams);
                output(UnClampedLerp(start, end, ease));
                yield return(null);

                curTime = UseUnscaledTime ? Time.unscaledTime : Time.time;
            }
            output(end);
        }
示例#8
0
        public void ControlOpacity(bool visible, enMotionType motionType, float opac, float duration, EquationsParameters easingParams)
        {
            if (!TargetFader)
            {
                FindTargetFader();
            }

            if (!TargetFader)
            {
                return;
            }

            float eOpacity = visible ? OpacitySection.startFloatValue : opac;
            float sOpacity = 0;

            if (!gameObject.activeInHierarchy)
            {
                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;
                }
                return;
            }

            if (TargetFader is Graphic)
            {
                Graphic tf = (Graphic)TargetFader;
                sOpacity = tf.color.a;
            }
            else if (TargetFader is CanvasGroup)
            {
                CanvasGroup tf = (CanvasGroup)TargetFader;
                sOpacity = tf.alpha;
            }

            if (OpacitySection.motionEnum != null)
            {
                StopCoroutine(OpacitySection.motionEnum);
                OpacitySection.motionEnum = null;
            }

            OpacitySection.motionEnum = FloatMotion((f) => {
                if (TargetFader is Graphic)
                {
                    Graphic tf = (Graphic)TargetFader;
                    Color col  = tf.color;
                    col.a      = f;
                    tf.color   = col;
                }
                else if (TargetFader is CanvasGroup)
                {
                    CanvasGroup tf = (CanvasGroup)TargetFader;
                    tf.alpha       = f;
                }
            }, sOpacity, eOpacity, OpacitySection.HideAfter, OpacitySection.ShowAfter, duration, easingParams, motionType);

            StartCoroutine(OpacitySection.motionEnum);
        }
示例#9
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);
            }
        }