示例#1
0
        /*
         * =====
         * Private Methods
         * =====
         */

        /*
         *  Starts the next tween in the tweens List
         */
        private void StartNextTween(float delay = 0f)
        {
            //remove any listeners from previous tween
            if (activeTween != null)
            {
                activeTween.OnTweenProgress -= OnTweenProgress;
                activeTween.OnTweenComplete -= OnTweenComplete;
            }

            //grab the next tween step
            NDTweenTimelineStep step = (NDTweenTimelineStep)tweens[currentTween];

            // start the tweem
            if (step.isTo)
            {
                activeTween = NDTween.To(
                    step.target,
                    step.timeInSeconds,
                    step.position,
                    step.scale,
                    step.rotation,
                    step.color,
                    step.colorTarget,
                    step.easing,
                    step.delay + delay,
                    true,
                    true,
                    true,
                    step.isUi
                    );
            }
            else
            {
                activeTween = NDTween.From(
                    step.target,
                    step.timeInSeconds,
                    step.position,
                    step.scale,
                    step.rotation,
                    step.color,
                    step.colorTarget,
                    step.easing,
                    step.delay + delay,
                    true,
                    true,
                    true,
                    step.isUi
                    );
            }

            // listen to tween events for new tween
            activeTween.OnTweenComplete += OnTweenComplete;
            activeTween.OnTweenProgress += OnTweenProgress;

            if (OnTimelineStart != null)
            {
                OnTimelineStart();
            }
        }
示例#2
0
        /*
         * =====
         * Private Methods
         * =====
         */

        /**
         *  Creates an NDTweenWorker component on the target game object
         */
        static private NDTweenWorker CreateTweenWorker(bool isTo, GameObject target, Vector3 position, Vector3 scale, Vector3 rotation, Color color, string colorTarget, float timeInSeconds, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = false, bool autoPlay = true, bool isUI = false, bool isGlobal = false)
        {
            //remove any previous tweens if needed
            if (clearCurrentTweens)
            {
                NDTween.RemoveAllTweens(target);
            }

            //create the component and add to the target game object
            NDTweenWorker tweenWorker = target.AddComponent <NDTweenWorker>();

            tweenWorker.targetGameObject = target;

            //set tween properties
            tweenWorker.startPosition = isTo ? isGlobal ? target.transform.position : target.transform.localPosition : position;
            tweenWorker.endPosition   = isTo ? position : isGlobal ? target.transform.position : target.transform.localPosition;

            tweenWorker.startScale = isTo ? target.transform.localScale : scale;
            tweenWorker.endScale   = isTo ? scale : target.transform.localScale;

            tweenWorker.startRotation = isTo ? target.transform.localRotation.eulerAngles : rotation;
            tweenWorker.endRotation   = isTo ? rotation : target.transform.localRotation.eulerAngles;

            tweenWorker.startColor = isTo ? NDTween.GetMaterialColor(target, colorTarget) : color;
            tweenWorker.endColor   = isTo ? color : NDTween.GetMaterialColor(target, colorTarget);

            tweenWorker.colorTarget = colorTarget;

            tweenWorker.tweenTimeInSeconds = timeInSeconds;
            tweenWorker.delay = delay;

            tweenWorker.isTo = isTo;

            tweenWorker.isUI = isUI;

            tweenWorker.easingEquation = NDTween.GetEasingEquation(easing);

            tweenWorker.destroyOnComplete = destroyOnComplete;

            //start it
            if (autoPlay)
            {
                tweenWorker.StartTween();
            }

            //return reference
            return(tweenWorker);
        }
示例#3
0
        static private NDTweenWorker CreateTweenWorker(bool isTo, GameObject target, Vector3 position, Vector3 scale, Vector3 rotation, float alpha, float timeInSeconds, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = false, bool autoPlay = true)
        {
            //remove any previous tweens if needed
            if (clearCurrentTweens)
            {
                NDTween.RemoveAllTweens(target);
            }

            //create the component and add to the target game object
            NDTweenWorker tweenWorker = target.AddComponent <NDTweenWorker>();

            tweenWorker.targetGameObject = target;

            //set tween properties
            tweenWorker.startPosition = isTo ? target.GetComponent <RectTransform>().localPosition : position;
            tweenWorker.endPosition   = isTo ? position : target.GetComponent <RectTransform>().localPosition;

            tweenWorker.startScale = isTo ? target.GetComponent <RectTransform>().localScale : scale;
            tweenWorker.endScale   = isTo ? scale : target.GetComponent <RectTransform>().localScale;

            tweenWorker.startRotation = isTo ? target.GetComponent <RectTransform>().localRotation.eulerAngles : rotation;
            tweenWorker.endRotation   = isTo ? rotation : target.GetComponent <RectTransform>().localRotation.eulerAngles;

            tweenWorker.startAlpha = isTo ? target.GetComponent <CanvasRenderer>().GetAlpha() : alpha;
            tweenWorker.endAlpha   = isTo ? alpha : target.GetComponent <CanvasRenderer>().GetAlpha();

            tweenWorker.tweenTimeInSeconds = timeInSeconds;
            tweenWorker.delay = delay;

            tweenWorker.isTo = isTo;

            tweenWorker.isUI = true;

            tweenWorker.easingEquation = NDTween.GetEasingEquation(easing);

            tweenWorker.destroyOnComplete = destroyOnComplete;

            //start it
            if (autoPlay)
            {
                tweenWorker.StartTween();
            }

            //return reference
            return(tweenWorker);
        }
示例#4
0
        /*
         *  Staggers the firing of tweens in the provided array by the specified delay
         */
        static public void Stagger(NDTweenWorker[] tweens, float delay)
        {
            NDTweenWorker tween;

            for (int i = 0; i < tweens.Length; i++)
            {
                tween = tweens[i];
                float newDelay = tween.delay + (delay * i);
                if (tween.isTo)
                {
                    NDTween.To(tween.targetGameObject, tween.tweenTimeInSeconds, tween.endPosition, tween.endScale, tween.endRotation, tween.endColor, tween.colorTarget, tween.easingEquation, newDelay, tween.destroyOnComplete, tween.clearCurrentTweens, true, tween.isUI);
                }
                else
                {
                    NDTween.From(tween.targetGameObject, tween.tweenTimeInSeconds, tween.startPosition, tween.startScale, tween.startRotation, tween.startColor, tween.colorTarget, tween.easingEquation, newDelay, tween.destroyOnComplete, tween.clearCurrentTweens, true, tween.isUI);
                }
            }
        }
示例#5
0
 static public NDTweenWorker From(GameObject target, float timeInSeconds, Vector3 position, Vector3 scale, Vector3 rotation, Color color, string colorTarget, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = true, bool autoPlay = true, bool isUI = false)
 {
     return(NDTween.CreateTweenWorker(
                false,
                target,
                position,
                scale,
                rotation,
                color,
                colorTarget,
                timeInSeconds,
                easing,
                delay,
                destroyOnComplete,
                clearCurrentTweens,
                autoPlay,
                isUI
                ));
 }
示例#6
0
 public void AddTo(GameObject target, float timeInSeconds, Vector3 position, Vector3 scale, Func <float, float> easing = null, float delay = 0f, bool isUI = false)
 {
     AddTo(target, timeInSeconds, position, scale, target.transform.localRotation.eulerAngles, NDTween.GetMaterialColor(target, "_Color"), "_Color", easing, delay, isUI);
 }
示例#7
0
 public void AddFrom(GameObject target, float timeInSeconds, Vector3 position, Vector3 scale, Vector3 rotation, Color color, Func <float, float> easing = null, float delay = 0f, bool isUI = false)
 {
     AddFrom(target, timeInSeconds, position, scale, rotation, NDTween.GetMaterialColor(target, "_Color"), "_Color", easing, delay, isUI);
 }
示例#8
0
        /*
         *  Fire the tween again, will reset object to it's start position before doing the same motion
         */
        public NDTweenWorker Retrigger(float extraDelay = 0f)
        {
            // check for any other NDTweenWorker components
            NDTweenWorker[] workers             = targetGameObject.GetComponents <NDTweenWorker>();
            bool            needsToBeAddedAgain = true;

            // loop through to see if this one exists on targetGameObject
            for (int i = 0; i < workers.Length; i++)
            {
                if (workers[i] == this)
                {
                    needsToBeAddedAgain = false;
                }
            }

            // reset targetGameObject properties
            SetTargetPosition(isTo ? startPosition : endPosition);
            SetTargetScale(isTo ? startScale : endScale);
            SetTargetRotation(isTo ? startRotation : endRotation);
            if (isUI)
            {
                targetGameObject.GetComponent <CanvasRenderer>().SetAlpha(isTo ? startAlpha : endAlpha);
            }
            else if (hasRenderer)
            {
                targetGameObject.GetComponent <Renderer>().material.SetColor(colorTarget, isTo ? startColor : endColor);
            }

            //if not present, fire through NDTween as initially fired
            if (needsToBeAddedAgain)
            {
                if (isUI)
                {
                    if (isTo)
                    {
                        return(NDUITween.To(targetGameObject, tweenTimeInSeconds, endPosition, endScale, endRotation, endAlpha, easingEquation, delay, destroyOnComplete, clearCurrentTweens));
                    }
                    else
                    {
                        return(NDUITween.From(targetGameObject, tweenTimeInSeconds, startPosition, startScale, startRotation, startAlpha, easingEquation, delay, destroyOnComplete, clearCurrentTweens));
                    }
                }
                else
                {
                    if (isTo)
                    {
                        return(NDTween.To(targetGameObject, tweenTimeInSeconds, endPosition, endScale, endRotation, endColor, colorTarget, easingEquation, delay, destroyOnComplete, clearCurrentTweens));
                    }
                    else
                    {
                        return(NDTween.From(targetGameObject, tweenTimeInSeconds, startPosition, startScale, startRotation, startColor, colorTarget, easingEquation, delay, destroyOnComplete, clearCurrentTweens));
                    }
                }
            }
            else
            {
                //otherwise call StartTween
                StartTween();
                return(this);
            }
        }
示例#9
0
 static public NDTweenWorker UITo(GameObject target, float timeInSeconds, Vector3 position, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = true, bool autoPlay = true)
 {
     return(NDTween.To(target, timeInSeconds, position));
 }
示例#10
0
 static public NDTweenWorker To(GameObject target, float timeInSeconds, Vector3 position, Vector3 scale, Vector3 rotation, Color color, string colorTarget, NDTweenOptions options)
 {
     return(NDTween.To(target, timeInSeconds, position, scale, rotation, color, colorTarget, options.easing, options.delay, options.destroyOnComplete, options.clearCurrentTweens, options.autoPlay, options.isUI));
 }
示例#11
0
 static public NDTweenWorker ColorTo(GameObject target, float timeInSeconds, Color color, string colorTarget, NDTweenOptions options)
 {
     return(NDTween.To(target, timeInSeconds, target.transform.localPosition, target.transform.localScale, target.transform.localRotation.eulerAngles, color, colorTarget, options.easing, options.delay, options.destroyOnComplete, options.clearCurrentTweens, options.autoPlay, options.isUI));
 }
示例#12
0
 static public NDTweenWorker ColorTo(GameObject target, float timeInSeconds, Color color, string colorTarget, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = true, bool autoPlay = true, bool isUI = false)
 {
     return(NDTween.To(target, timeInSeconds, target.transform.localPosition, target.transform.localScale, target.transform.localRotation.eulerAngles, color, colorTarget, easing, delay, destroyOnComplete, clearCurrentTweens, autoPlay, isUI));
 }
示例#13
0
 static public NDTweenWorker RotateTo(GameObject target, float timeInSeconds, Vector3 rotation, NDTweenOptions options)
 {
     return(NDTween.To(target, timeInSeconds, target.transform.localPosition, target.transform.localScale, rotation, NDTween.GetMaterialColor(target, "_Color"), "_Color", options.easing, options.delay, options.destroyOnComplete, options.clearCurrentTweens, options.autoPlay, options.isUI));
 }
示例#14
0
 static public NDTweenWorker RotateTo(GameObject target, float timeInSeconds, Vector3 rotation, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = true, bool autoPlay = true, bool isUI = false)
 {
     return(NDTween.To(target, timeInSeconds, target.transform.localPosition, target.transform.localScale, rotation, NDTween.GetMaterialColor(target, "_Color"), "_Color", easing, delay, destroyOnComplete, clearCurrentTweens, autoPlay, isUI));
 }
示例#15
0
 static public NDTweenWorker From(GameObject target, float timeInSeconds, Vector3 position, Vector3 scale, Vector3 rotation, NDTweenOptions options)
 {
     return(NDTween.From(target, timeInSeconds, position, scale, rotation, NDTween.GetMaterialColor(target, "_Color"), "_Color", options.easing, options.delay, options.destroyOnComplete, options.clearCurrentTweens, options.autoPlay, options.isUI));
 }
示例#16
0
 static public NDTweenWorker From(GameObject target, float timeInSeconds, Vector3 position, Vector3 scale, Func <float, float> easing = null, float delay = 0f, bool destroyOnComplete = true, bool clearCurrentTweens = true, bool autoPlay = true, bool isUI = false)
 {
     return(NDTween.From(target, timeInSeconds, position, scale, target.transform.localRotation.eulerAngles, NDTween.GetMaterialColor(target, "_Color"), "_Color", easing, delay, destroyOnComplete, clearCurrentTweens, autoPlay, isUI));
 }