Esempio n. 1
0
        void Transition(TransitionSettings transitionSettings, TransitionModeType transitionMode)
        {
            if (transitionMode == TransitionModeType.In && TransitionInConfig.OnTransitionStart != null)
            {
                TransitionInConfig.OnTransitionStart.Invoke();
            }
            else if (transitionMode == TransitionModeType.Out && TransitionOutConfig.OnTransitionStart != null)
            {
                TransitionOutConfig.OnTransitionStart.Invoke();
            }

            // set new transition id to stop all old transitions.
            _activeTransitionId = Guid.NewGuid().ToString();
            _transitionSettings = transitionSettings;
            TransitionMode      = transitionMode;

            // get the easing function - will be null for unsupported types.
            _easingFunction = TweenMethods.GetEasingFunction(_transitionSettings.TransitionType);

            // if delay and duration are both zero then just set end state, otherwise run the transition.
            if (Mathf.Approximately(_transitionSettings.Delay, 0) && Mathf.Approximately(_transitionSettings.Duration, 0))
            {
                SetProgress(1);
                SetAmount(_endFloat);
            }
            else
            {
                SetProgress(0);
                StartCoroutine(TransitionInternal(_activeTransitionId, transitionMode));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor. Semi-internal - If you use this be prepared for changes. The best way is to use named
        /// parameters for all optional arguments!
        /// </summary>
        /// <param name="target"></param>
        /// <param name="delay"></param>
        /// <param name="duration"></param>
        /// <param name="transitionMode"></param>
        /// <param name="timeUpdateMethod"></param>
        /// <param name="tweenType"></param>
        /// <param name="animationCurve"></param>
        /// <param name="coordinateSpace"></param>
        /// <param name="onStart"></param>
        /// <param name="onUpdate"></param>
        /// <param name="onComplete"></param>
        public TransitionStep(UnityEngine.GameObject target = null,
                              float delay    = 0,
                              float duration = 0.5f,
                              TransitionModeType transitionMode     = TransitionModeType.Specified,
                              TimeUpdateMethodType timeUpdateMethod = TimeUpdateMethodType.GameTime,
                              TransitionHelper.TweenType tweenType  = TransitionHelper.TweenType.linear,
                              AnimationCurve animationCurve         = null,
                              CoordinateSpaceType coordinateSpace   = CoordinateSpaceType.Global,
                              Action <TransitionStep> onStart       = null,
                              Action <TransitionStep> onUpdate      = null,
                              Action <TransitionStep> onComplete    = null)
        {
            Target           = target;
            Delay            = delay;
            Duration         = duration;
            TransitionMode   = transitionMode;
            TimeUpdateMethod = timeUpdateMethod;
            TweenType        = tweenType;
            AnimationCurve   = animationCurve ?? AnimationCurve.EaseInOut(0, 0, 1, 1);
            CoordinateSpace  = coordinateSpace;

            AddOnStartAction(onStart);
            AddOnUpdateAction(onUpdate);
            AddOnCompleteAction(onComplete);
        }
Esempio n. 3
0
 public TransitionStepValue(GameObject target = null,
                            float delay       = 0,
                            float duration    = 0.5F,
                            TransitionModeType transitionMode     = TransitionModeType.Specified,
                            TimeUpdateMethodType timeUpdateMethod = TimeUpdateMethodType.GameTime,
                            TransitionHelper.TweenType tweenType  = TransitionHelper.TweenType.linear,
                            AnimationCurve animationCurve         = null,
                            CoordinateSpaceType coordinateSpace   = CoordinateSpaceType.Global,
                            Action <TransitionStep> onStart       = null,
                            Action <TransitionStep> onUpdate      = null,
                            Action <TransitionStep> onComplete    = null) :
     base(target, delay, duration, transitionMode, timeUpdateMethod, tweenType, animationCurve, coordinateSpace, onStart, onUpdate, onComplete)
 {
 }
Esempio n. 4
0
 public MoveTarget(UnityEngine.GameObject target,
                   Vector3?startPosition                = null,
                   Vector3?endPosition                  = null,
                   float delay                          = 0,
                   float duration                       = 0.5f,
                   TransitionModeType transitionMode    = TransitionModeType.Specified,
                   TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
                   AnimationCurve animationCurve        = null,
                   Action onStart                       = null,
                   Action <float> onUpdate              = null,
                   Action onComplete                    = null) :
     base(target, startPosition, endPosition, delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
          animationCurve: animationCurve, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
 }
 public MoveTarget(UnityEngine.GameObject target,
     Vector3? startPosition = null,
     Vector3? endPosition = null,
     float delay = 0,
     float duration = 0.5f,
     TransitionModeType transitionMode = TransitionModeType.Specified,
     TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
     AnimationCurve animationCurve = null,
     Action onStart = null,
     Action<float> onUpdate = null,
     Action onComplete = null)
     : base(target, startPosition, endPosition, delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
         animationCurve: animationCurve, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
 }
Esempio n. 6
0
 public Scale(UnityEngine.GameObject target,
              Vector3?startScale = null,
              Vector3?endScale   = null,
              float delay        = 0,
              float duration     = 0.5f,
              TransitionModeType transitionMode     = TransitionModeType.Specified,
              TimeUpdateMethodType timeUpdateMethod = TimeUpdateMethodType.GameTime,
              TransitionHelper.TweenType tweenType  = TransitionHelper.TweenType.linear,
              AnimationCurve animationCurve         = null,
              Action <TransitionStep> onStart       = null,
              Action <TransitionStep> onUpdate      = null,
              Action <TransitionStep> onComplete    = null) :
     base(target, startScale, endScale, delay: delay, duration: duration, transitionMode: transitionMode, timeUpdateMethod: timeUpdateMethod, tweenType: tweenType,
          animationCurve: animationCurve, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
 }
 public Fade(UnityEngine.GameObject target,
     float startTransparency = 0,
     float endTransparency = 1,
     float delay = 0,
     float duration = 0.5f,
     TransitionModeType transitionMode = TransitionModeType.Specified,
     TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
     AnimationCurve animationCurve = null,
     Action onStart = null,
     Action<float> onUpdate = null,
     Action onComplete = null)
     : base(target, startValue: startTransparency, endValue: endTransparency, 
             delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
             animationCurve: animationCurve, onStart: onStart,onUpdate: onUpdate, onComplete: onComplete)
 {
 }
Esempio n. 8
0
 public Fade(UnityEngine.GameObject target,
             float startTransparency              = 0,
             float endTransparency                = 1,
             float delay                          = 0,
             float duration                       = 0.5f,
             TransitionModeType transitionMode    = TransitionModeType.Specified,
             TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
             AnimationCurve animationCurve        = null,
             Action onStart                       = null,
             Action <float> onUpdate              = null,
             Action onComplete                    = null) :
     base(target, startValue: startTransparency, endValue: endTransparency,
          delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
          animationCurve: animationCurve, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
 }
 public Rotate(UnityEngine.GameObject target,
     Vector3? startRotation = null,
     Vector3? endRotation = null,
     float delay = 0,
     float duration = 0.5f,
     TransitionModeType transitionMode = TransitionModeType.Specified,
     TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
     AnimationCurve animationCurve = null,
     TransitionStep.CoordinateSpaceType coordinateSpace = TransitionStep.CoordinateSpaceType.Global,
     Action onStart = null,
     Action<float> onUpdate = null,
     Action onComplete = null)
     : base(target, startRotation, endRotation, delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
         animationCurve: animationCurve, coordinateSpace: coordinateSpace, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
     Assert.AreNotEqual(CoordinateSpaceType.AnchoredPosition, CoordinateSpace, "AnchoredPosition is not supported for Rotate. Please change");
 }
Esempio n. 10
0
 public Rotate(UnityEngine.GameObject target,
               Vector3?startRotation                = null,
               Vector3?endRotation                  = null,
               float delay                          = 0,
               float duration                       = 0.5f,
               TransitionModeType transitionMode    = TransitionModeType.Specified,
               TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
               AnimationCurve animationCurve        = null,
               TransitionStep.CoordinateSpaceType coordinateSpace = TransitionStep.CoordinateSpaceType.Global,
               Action onStart          = null,
               Action <float> onUpdate = null,
               Action onComplete       = null) :
     base(target, startRotation, endRotation, delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
          animationCurve: animationCurve, coordinateSpace: coordinateSpace, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
     Assert.AreNotEqual(CoordinateSpaceType.AnchoredPosition, CoordinateSpace, "AnchoredPosition is not supported for Rotate. Please change");
 }
Esempio n. 11
0
 public ColorTransition(UnityEngine.GameObject target,
                        UnityEngine.Gradient gradient = null,
                        float delay    = 0,
                        float duration = 0.5f,
                        TransitionModeType transitionMode     = TransitionModeType.Specified,
                        TimeUpdateMethodType timeUpdateMethod = TimeUpdateMethodType.GameTime,
                        TransitionHelper.TweenType tweenType  = TransitionHelper.TweenType.linear,
                        AnimationCurve animationCurve         = null,
                        Action <TransitionStep> onStart       = null,
                        Action <TransitionStep> onUpdate      = null,
                        Action <TransitionStep> onComplete    = null) :
     base(target,
          delay: delay, duration: duration, transitionMode: transitionMode, timeUpdateMethod: timeUpdateMethod, tweenType: tweenType,
          animationCurve: animationCurve, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
     Gradient      = gradient;
     OriginalValue = GetCurrent();
 }
Esempio n. 12
0
 public TransitionStepFloat(UnityEngine.GameObject target = null,
                            float?startValue = null,
                            float?endValue   = null,
                            float delay      = 0,
                            float duration   = 0.5f,
                            TransitionModeType transitionMode    = TransitionModeType.Specified,
                            TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
                            AnimationCurve animationCurve        = null,
                            CoordinateSpaceType coordinateSpace  = CoordinateSpaceType.Global,
                            Action onStart          = null,
                            Action <float> onUpdate = null,
                            Action onComplete       = null) :
     base(target, delay, duration, transitionMode, tweenType, animationCurve, coordinateSpace, onStart, onUpdate, onComplete)
 {
     StartValue    = startValue.GetValueOrDefault();
     EndValue      = endValue.GetValueOrDefault();
     OriginalValue = GetCurrent();
 }
Esempio n. 13
0
 public Move(UnityEngine.GameObject target,
     Vector3? startPosition = null,
     Vector3? endPosition = null,
     float delay = 0,
     float duration = 0.5f,
     TransitionModeType transitionMode = TransitionModeType.Specified,
     TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
     AnimationCurve animationCurve = null,
     CoordinateSpaceType coordinateSpace = CoordinateSpaceType.Global,
     Action onStart = null,
     Action<float> onUpdate = null,
     Action onComplete = null)
     : base(target, startPosition, endPosition, delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
         animationCurve: animationCurve, coordinateSpace: coordinateSpace, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
     //TODO: Validation . where to place!
     //if (MoveMode == MoveModeType.AnchoredPosition)
     //    Assert.IsNotNull(Target.transform as RectTransform, "The target of TransitionMove must contain a RectTransform component (not just a standard Transform component) when using MoveMode of type AnchoredPosition");
 }
Esempio n. 14
0
 public Move(UnityEngine.GameObject target,
             Vector3?startPosition                = null,
             Vector3?endPosition                  = null,
             float delay                          = 0,
             float duration                       = 0.5f,
             TransitionModeType transitionMode    = TransitionModeType.Specified,
             TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
             AnimationCurve animationCurve        = null,
             CoordinateSpaceType coordinateSpace  = CoordinateSpaceType.Global,
             Action onStart                       = null,
             Action <float> onUpdate              = null,
             Action onComplete                    = null) :
     base(target, startPosition, endPosition, delay: delay, duration: duration, transitionMode: transitionMode, tweenType: tweenType,
          animationCurve: animationCurve, coordinateSpace: coordinateSpace, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete)
 {
     //TODO: Validation . where to place!
     //if (MoveMode == MoveModeType.AnchoredPosition)
     //    Assert.IsNotNull(Target.transform as RectTransform, "The target of TransitionMove must contain a RectTransform component (not just a standard Transform component) when using MoveMode of type AnchoredPosition");
 }
        /// <summary>
        /// Constructor. Semi-internal - If you use this be prepared for changes. The best way is to use named 
        /// parameters for all optional arguments!
        /// </summary>
        /// <param name="target"></param>
        /// <param name="delay"></param>
        /// <param name="duration"></param>
        /// <param name="transitionMode"></param>
        /// <param name="tweenType"></param>
        /// <param name="animationCurve"></param>
        /// <param name="coordinateSpace"></param>
        /// <param name="onStart"></param>
        /// <param name="onUpdate"></param>
        /// <param name="onComplete"></param>
        public TransitionStep(UnityEngine.GameObject target = null,
            float delay = 0,
            float duration = 0.5f,
            TransitionModeType transitionMode = TransitionModeType.Specified,
            TransitionHelper.TweenType tweenType = TransitionHelper.TweenType.linear,
            AnimationCurve animationCurve = null,
            CoordinateSpaceType coordinateSpace = CoordinateSpaceType.Global,
            Action onStart = null,
            Action<float> onUpdate = null, 
            Action onComplete = null)
        {
            Target = target;
            Delay = delay;
            Duration = duration;
            TransitionMode = transitionMode;
            TweenType = tweenType;
            AnimationCurve = animationCurve == null ? AnimationCurve.EaseInOut(0, 0, 1, 1) : animationCurve;
            CoordinateSpace = coordinateSpace;

            AddOnStartAction(onStart);
            AddOnUpdateAction(onUpdate);
            AddOnCompleteAction(onComplete);
        }
 /// <summary>
 /// Initialise for a transition out.
 /// </summary>
 public virtual void InitTransitionOut()
 {
     TransitionMode = TransitionModeType.Out;
     CurrentTransitionStep = CreateTransitionStepOut();
     CurrentTransitionStep.SetProgressToStart();
 }
Esempio n. 17
0
        public void Transition(TransitionSettings transitionSettings, Vector3 startAmount, Vector3 endAmount, TransitionModeType transitionMode)
        {
            // if this transition should not run then return immediately
            if (transitionSettings.TransitionType == TransitionHelper.TransitionType.none)
            {
                return;
            }

            // save transition values
            _targetType   = TargetTypeEnum.Vector3;
            _startVector3 = startAmount;
            _endVector3   = endAmount;

            // start transition
            Transition(transitionSettings, transitionMode);
        }
Esempio n. 18
0
 public override void Reset()
 {
     base.Reset();
     Target         = null;
     TransitionMode = TransitionModeType.FromCurrent;
 }
Esempio n. 19
0
        /// <summary>
        /// Coroutine to handle the transition over time.
        /// </summary>
        /// <param name="currentTransitionId"></param>
        /// <param name="transitionMode"></param>
        /// <returns></returns>
        IEnumerator TransitionInternal(string currentTransitionId, TransitionModeType transitionMode)
        {
            bool currentTransitionisActiveTransition = true;

            // delay
            if (_transitionSettings.Delay != 0)
            {
                yield return(new WaitForSeconds(_transitionSettings.Delay));
            }

            var normalisedFactor = 1 / _transitionSettings.Duration;

            while (Progress < 1)
            {
                // exit if a newer transition has been started
                currentTransitionisActiveTransition = currentTransitionId == _activeTransitionId;
                if (!currentTransitionisActiveTransition)
                {
                    break;
                }

                // update progress
                Progress += normalisedFactor * Time.deltaTime;
                SetProgress(Progress);

                // update amount based upon the target type
                if (_targetType == TargetTypeEnum.Float)
                {
                    SetAmount(TransitionValue(_startFloat, _endFloat, Progress));
                }
                else
                {
                    SetAmount(new Vector3(
                                  TransitionValue(_startVector3.x, _endVector3.x, Progress),
                                  TransitionValue(_startVector3.y, _endVector3.y, Progress),
                                  TransitionValue(_startVector3.z, _endVector3.z, Progress)));
                }

                yield return(0);
            }

            // set end value if this transition is still running.
            currentTransitionisActiveTransition = currentTransitionId == _activeTransitionId;
            if (currentTransitionisActiveTransition)
            {
                if (_targetType == TargetTypeEnum.Float)
                {
                    SetAmount(_endFloat);
                }
                else
                {
                    SetAmount(_endVector3);
                }
            }

            // finally call callback
            if (transitionMode == TransitionModeType.In)
            {
                TransitionInComplete(currentTransitionisActiveTransition);
            }
            else if (transitionMode == TransitionModeType.Out)
            {
                TransitionOutComplete(currentTransitionisActiveTransition);
            }
        }
 /// <summary>
 /// Set the transition mode
 /// </summary>
 /// <param name="transitionMode"></param>
 /// <returns></returns>
 public TransitionStep SetTransitionMode(TransitionModeType transitionMode)
 {
     TransitionMode = transitionMode;
     return(this);
 }
 /// <summary>
 /// Called when an in transition has been completed (or interupted)
 /// </summary>
 public virtual void TransitionInComplete()
 {
     TransitionMode = TransitionModeType.Out;
     if (TransitionInConfig.OnTransitionComplete != null)
         TransitionInConfig.OnTransitionComplete.Invoke();
 }
 /// <summary>
 /// Set the transition mode
 /// </summary>
 /// <param name="transitionMode"></param>
 /// <returns></returns>
 public TransitionStep SetTransitionMode(TransitionModeType transitionMode)
 {
     TransitionMode = transitionMode;
     return this;
 }