Esempio n. 1
0
        /// <summary>
        /// helper function that creates a "from" Tween and adds it to the pool
        /// </summary>
        public static GoTween from(object target, float duration, GoTweenConfig config)
        {
            config.setIsFrom();
            var tween = new GoTween(target, duration, config);

            addTween(tween);

            return(tween);
        }
Esempio n. 2
0
        /// <summary>
        /// initializes a new instance and sets up the details according to the config parameter
        /// </summary>
        public GoTween(object target, float duration, GoTweenConfig config, Action <AbstractGoTween> onComplete = null)
        {
            // default to removing on complete
            autoRemoveOnComplete = true;

            // allow events by default
            allowEvents = true;

            // setup callback bools
            _didInit  = false;
            _didBegin = false;

            // flag the onIterationStart event to fire.
            // as long as goTo is not called on this tween, the onIterationStart event will fire
            // as soon as the delay, if any, is completed.
            _fireIterationStart = true;

            this.target           = target;
            this.targetTypeString = target.GetType().ToString();
            this.duration         = duration;

            // copy the TweenConfig info over
            id         = config.id;
            delay      = config.delay;
            loopType   = config.loopType;
            iterations = config.iterations;
            _easeType  = config.easeType;
            updateType = config.propertyUpdateType;
            isFrom     = config.isFrom;
            timeScale  = config.timeScale;

            _onInit           = config.onInitHandler;
            _onBegin          = config.onBeginHandler;
            _onIterationStart = config.onIterationStartHandler;
            _onUpdate         = config.onUpdateHandler;
            _onIterationEnd   = config.onIterationEndHandler;
            _onComplete       = config.onCompleteHandler;

            if (config.isPaused)
            {
                state = GoTweenState.Paused;
            }

            // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be
            // set and maintain clean code (Actions always try to be the last param of a method)
            if (onComplete != null)
            {
                _onComplete = onComplete;
            }

            // add all our properties
            for (var i = 0; i < config.tweenProperties.Count; ++i)
            {
                var tweenProp = config.tweenProperties[i];

                // if the tween property is initialized already it means it is being reused so we need to clone it
                if (tweenProp.isInitialized)
                {
                    tweenProp = tweenProp.clone();
                }

                addTweenProperty(tweenProp);
            }

            // calculate total duration
            if (iterations < 0)
            {
                totalDuration = float.PositiveInfinity;
            }
            else
            {
                totalDuration = iterations * duration;
            }
        }