Esempio n. 1
0
        public virtual void start()
        {
            if (!_isFromValueOverridden)
            {
                _fromValue = _target.getTweenedValue();
            }

            if (_tweenState == TweenState.Complete)
            {
                _tweenState = TweenState.Running;
                TweenManager.addTween(this);
            }
        }
Esempio n. 2
0
        // -------------------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------------------
        // METHODS
        // -------------------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------------------

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="time"></param>
        /// <param name="useFrames"></param>
        public Tween(object target, int time, bool useFrames)
        {
            _duration   = time;
            _elapsed    = 0;
            _delay      = 0;
            _numRepeats = 0;
            _target     = target;
            _useFrames  = useFrames;
            _state      = TweenState.START;
            _easing     = Easing.QuadEaseOut;
            _overwrite  = Overwrite.OVERWRITE_DEFAULT;
            _procedures = new List <ITweenProcedure>();
        }
Esempio n. 3
0
        public void Update(float deltaTime)
        {
            if (AdaptiveDuration)
            {
                elapsedMilliseconds += deltaTime;
                if (State == TweenState.Running)
                {
                    var propertiesFinished = 0;
                    foreach (var property in tweeningProperties)
                    {
                        if (!property.Update(elapsedMilliseconds)) //No Frames Left
                        {
                            propertiesFinished++;
                        }
                    }
                    if (propertiesFinished == tweeningProperties.Count)
                    {
                        elapsedMilliseconds = 0;
                        if (!Loop)
                        {
                            State = TweenState.Stopped;
                        }
                    }
                }
            }
            else if (State == TweenState.Running)
            {
                elapsedMilliseconds += deltaTime;

                if (elapsedMilliseconds >= duration)
                {
                    if (Loop)
                    {
                        elapsedMilliseconds = elapsedMilliseconds - duration;
                        ResetProperties();
                    }
                    else
                    {
                        Stop();
                    }
                }

                if (State == TweenState.Running)
                {
                    foreach (var property in tweeningProperties)
                    {
                        property.Update(elapsedMilliseconds);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Stop the tween
        /// </summary>
        public virtual TweenBase Stop()
        {
            if (this.State == TweenState.Stopped)
            {
                return(this);
            }

            unregisterWithTweenManager();

            this.State = TweenState.Stopped;
            raiseStopped();

            return(this);
        }
Esempio n. 5
0
        public void Play()
        {
            if (tweenerState == TweenState.Stopped)
            {
                timeRemaining = Duration;
                tValue        = 0;
                if (Style == TweenPlayStyle.PingPong)
                {
                    pingPongReflection = !pingPongReflection;
                }
            }

            tweenerState = TweenState.Play;
        }
Esempio n. 6
0
        protected TweenBase(SceneTime time, EasingType type, float duration, float startValue, float finishValue, Action finishCallback)
        {
            Assert.NotNull(time);

            _time           = time;
            _startTime      = time.CurrentFloat;
            _current        = 0;
            _duration       = duration;
            _finishTime     = _duration + _startTime;
            _function       = EasingFunctions.Get(type);
            _state          = TweenState.Working;
            _startValue     = startValue;
            _finishValue    = finishValue;
            _finishCallback = finishCallback;
        }
Esempio n. 7
0
        /// <summary>
        /// Updates the tween.
        /// </summary>
        /// <param name="elapsedTime">The elapsed time to add to the tween.</param>
        public void Update(float elapsedTime)
        {
            if (this._state != TweenState.Running)
            {
                return;
            }

            this._currentTime += elapsedTime;
            if (this._currentTime >= this._duration)
            {
                this._currentTime = this._duration;
                this._state       = TweenState.Stopped;
            }

            this.UpdateValue();
        }
 protected override void OnUpdate()
 {
     Entities
     .WithNone <TweenPause>()
     .ForEach((ref SpriteRenderer spriteRenderer, in DynamicBuffer <TweenState> tweenBuffer, in TweenTint tweenInfo) =>
     {
         for (int i = 0; i < tweenBuffer.Length; i++)
         {
             TweenState tween = tweenBuffer[i];
             if (tween.Id == tweenInfo.Id)
             {
                 spriteRenderer.Color = math.lerp(tweenInfo.Start, tweenInfo.End, tween.EasePercentage);
                 break;
             }
         }
     }).ScheduleParallel();
Esempio n. 9
0
        /// <summary>
        /// Updates the tween.
        /// </summary>
        /// <param name="elapsedTime">The elapsed time to add to the tween.</param>
        public void Update(float elapsedTime)
        {
            if (state != TweenState.Running)
            {
                return;
            }

            currentTime += elapsedTime;
            if (currentTime >= duration)
            {
                currentTime = duration;
                state       = TweenState.Stopped;
            }

            UpdateValue();
        }
Esempio n. 10
0
        public void Stop(TweenStopBehavior behavior)
        {
            switch (behavior)
            {
            case TweenStopBehavior.AsIs:
                State = TweenState.Stopped;
                break;

            case TweenStopBehavior.ForceComplete:
                _timer = _duration;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(behavior), behavior, null);
            }
        }
Esempio n. 11
0
        private IEnumerator OnExitTween()
        {
            _tweenState = TweenState.Exiting;
            float rate = (_bg.rectTransform.localScale.x - _enterScale.x) / (_normalScale.x - _enterScale.x);

            while (rate < 1.0f)
            {
                rate += (_TweenSpeed * Time.deltaTime);
                _bg.rectTransform.localScale = Vector3.Lerp(_enterScale, _normalScale, rate);
                _bg.color = Color.Lerp(_enteredColor, _normalColor, rate);
                yield return(null);
            }
            _bg.rectTransform.localScale = _normalScale;
            _bg.color   = _normalColor;
            _tweenState = TweenState.Exited;
        }
Esempio n. 12
0
        public virtual void start(MonoBehaviour ticker)
        {
            if (!_isFromValueOverridden)
            {
                _fromValue = _target.getTweenedValue();
            }

            if (_tweenState == TweenState.Complete)
            {
                _tweenState     = TweenState.Running;
                ienumeratorTick = TickByMonobehaviour();
                this.ticker     = ticker;
                ticker.StartCoroutine(ienumeratorTick);
                //ZestKit.instance.addTween( this );
            }
        }
Esempio n. 13
0
 protected override void OnUpdate()
 {
     Entities
     .WithNone <TweenPause>()
     .ForEach((ref Rotation rotation, in DynamicBuffer <TweenState> tweenBuffer, in TweenRotation tweenInfo) =>
     {
         for (int i = 0; i < tweenBuffer.Length; i++)
         {
             TweenState tween = tweenBuffer[i];
             if (tween.Id == tweenInfo.Id)
             {
                 rotation.Value = math.slerp(tweenInfo.Start, tweenInfo.End, tween.EasePercentage);
                 break;
             }
         }
     }).ScheduleParallel();
Esempio n. 14
0
        private void Test <TTweenInfo>(Entity entity)
            where TTweenInfo : struct, IComponentData
        {
            World.Update();
            World.Update();

            TweenState tween = GetSingletonTweenState(entity);

            tween.Time = tween.Duration;
            SetSingletonTweenState(entity, tween);

            World.Update();

            Assert.IsFalse(EntityManager.HasComponent <TweenState>(entity));
            Assert.IsFalse(EntityManager.HasComponent <TTweenInfo>(entity));
        }
Esempio n. 15
0
        public UITweener(Vector2 positionOut, TweenState state, TweenFunction function, float speed)
            : this(positionOut, state, 0, function, speed, function, speed)
        {
            switch (state)
            {
            case TweenState.TweeningOut:
            case TweenState.In:
                tween = 0;
                break;

            case TweenState.TweeningIn:
            case TweenState.Out:
                tween = 1;
                break;
            }
        }
Esempio n. 16
0
        public TweenState Update(float timeDelta)
        {
            if (State == TweenState.NotStarted || State == TweenState.Done)
            {
                return(State);
            }

            elapsedActiveTime += timeDelta;

            if (elapsedActiveTime <= Delay)
            {
                State      = TweenState.InDelay;
                ValueRatio = 0;
                return(State);
            }

            TweenState preCallbackState = State;

            if (State == TweenState.InDelay)
            {
                State            = TweenState.Tweening;
                preCallbackState = State;

                GetInitialValueFromSubject();
                onBegin?.Invoke(this);
            }

            if (elapsedActiveTime < Delay + Duration)
            {
                float timingRatio = (elapsedActiveTime - Delay) / Duration;
                ValueRatio = EasingMethod?.Invoke(timingRatio) ?? timingRatio;
                ApplyCurrentValueToSubject();
                onUpdate?.Invoke(this);
            }
            else
            {
                State            = TweenState.Done;
                preCallbackState = State;

                ValueRatio = 1;
                ApplyCurrentValueToSubject();
                onUpdate?.Invoke(this);
                onDone?.Invoke(this);
            }

            return(preCallbackState);
        }
Esempio n. 17
0
        // -------------------------------------------------------------------------------------------
        /// <summary>
        /// Ends the tween.
        /// </summary>
        /// <param name="completeTweens"></param>
        /// <param name="executeCompletionCallbacks"></param>
        public void End(bool completeTweens = false, bool executeCompletionCallbacks = false)
        {
            if (_state != TweenState.COMPLETE)
            {
                if (completeTweens)
                {
                    _elapsed = _duration;
                    UpdateProgress();
                }

                _state = TweenState.COMPLETE;
                if (executeCompletionCallbacks && _onComplete != null)
                {
                    _onComplete();
                }
            }
        }
 private unsafe void OnMapCellIndicatorHidingTweenComplete()
 {
     //IL_0070: Unknown result type (might be due to invalid IL or missing references)
     //IL_007a: Expected O, but got Unknown
     if (m_mapCellIndicator == MapCellIndicator.None)
     {
         m_mapCellIndicatorRenderer.set_enabled(false);
         m_tweenState            = TweenState.None;
         m_mapCellIndicatorTween = null;
     }
     else
     {
         m_mapCellIndicatorRenderer.set_sprite(GetMapIndicatorSprite(m_mapCellIndicator));
         m_tweenState            = TweenState.Showing;
         m_mapCellIndicatorTween = TweenSettingsExtensions.OnComplete <TweenerCore <float, float, FloatOptions> >(DOTween.To(new DOGetter <float>((object)this, (IntPtr)(void *) /*OpCode not supported: LdFtn*/), new DOSetter <float>((object)this, (IntPtr)(void *) /*OpCode not supported: LdFtn*/), 1f, 0.2f), new TweenCallback((object)this, (IntPtr)(void *) /*OpCode not supported: LdFtn*/));
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Stops the tween.
 /// </summary>
 /// <param name="stopBehavior">The behavior to use to handle the stop.</param>
 public void Stop(TweenStopBehavior stopBehavior)
 {
     if (state != TweenState.Stopped)
     {
         state = TweenState.Stopped;
         if (stopBehavior == TweenStopBehavior.Complete)
         {
             currentTime = duration;
             UpdateValue();
             if (completionCallback != null)
             {
                 completionCallback.Invoke(this);
                 completionCallback = null;
             }
         }
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Starts a tween.
        /// </summary>
        /// <param name="start">The start value.</param>
        /// <param name="end">The end value.</param>
        /// <param name="duration">The duration of the tween.</param>
        /// <param name="scaleFunc">A function used to scale progress over time.</param>
        public void Start(T start, T end, float duration, ScaleFunc scaleFunc)
        {
            if (duration <= 0)
            {
                throw new ArgumentException("duration must be greater than 0");
            }

            this._currentTime = 0;
            this._duration    = duration;
            this._scaleFunc   = scaleFunc ?? throw new ArgumentNullException("scaleFunc");
            this._state       = TweenState.Running;

            this._start = start;
            this._end   = end;

            this.UpdateValue();
        }
Esempio n. 21
0
        /// <summary>
        /// handles loop logic
        /// </summary>
        void handleLooping(float elapsedTimeExcess)
        {
            _loops--;
            if (_loopType == LoopType.PingPong)
            {
                reverseTween();
            }

            if (_loopType == LoopType.RestartFromBeginning || _loops % 2 == 0)
            {
                if (_loopCompleteHandler != null)
                {
                    _loopCompleteHandler(this);
                }
            }

            // if we have loops left to process reset our state back to Running so we can continue processing them
            if (_loops > 0)
            {
                _tweenState = TweenState.Running;

                // now we need to set our elapsed time and factor in our elapsedTimeExcess
                if (_loopType == LoopType.RestartFromBeginning)
                {
                    _elapsedTime = elapsedTimeExcess - _delayBetweenLoops;
                }
                else
                {
                    if (_isRunningInReverse)
                    {
                        _elapsedTime += _delayBetweenLoops - elapsedTimeExcess;
                    }
                    else
                    {
                        _elapsedTime = elapsedTimeExcess - _delayBetweenLoops;
                    }
                }

                // if we had an elapsedTimeExcess and no delayBetweenLoops update the value
                if (_delayBetweenLoops == 0f && elapsedTimeExcess > 0f)
                {
                    updateValue();
                }
            }
        }
Esempio n. 22
0
        public void stop(bool bringToCompletion = false)
        {
            _tweenState = TweenState.Complete;

            if (bringToCompletion)
            {
                // if we are running in reverse we finish up at 0 else we go to duration
                _elapsedTime = _isRunningInReverse ? 0f : _duration;
                _loopType    = LoopType.None;
                _loops       = 0;

                // ZestKit will handle removal on the next tick
            }
            else
            {
                ZestKit.instance.removeTween(this);
            }
        }
Esempio n. 23
0
        public void Ease()
        {
            Entity entity = EntityManager.CreateEntity();

            Tween.Move(EntityManager, entity, TestStartFloat3, TestEndFloat3, TestDuration);

            World.Update();
            World.Update();
            OverrideNextDeltaTime(TestDeltaTime);
            World.Update();

            TweenState tween = GetSingletonTweenState(entity);

            Assert.AreEqual(TestDeltaTime, tween.Time);

            float easePercentage = Math.Ease.CalculatePercentage(TestDeltaTime / TestDuration, tween.EaseType, tween.EaseExponent);

            Assert.AreEqual(easePercentage, tween.EasePercentage);
        }
Esempio n. 24
0
        public bool MoveNext()
        {
            switch (_state)
            {
            case TweenState.Working:
                return(Iterate());

            case TweenState.Callback:
                _state = TweenState.Finished;
                _finishCallback();
                return(false);

            case TweenState.Finished:
                return(false);

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 25
0
    public void Stop(TweenStopState stopState)
    {
        if (state != TweenState.Stopped)
        {
            state = TweenState.Stopped;

            if (stopState == TweenStopState.Complete)
            {
                currentTime = duration;
                UpdateValue();

                if (finishCallback != null)
                {
                    finishCallback.Invoke(this);
                    finishCallback = null;
                }
            }
        }
    }
Esempio n. 26
0
        private void HandleLooping(float elapsedTimeExcess)
        {
            numLoops--;
            if (loopType == LoopType.PingPong)
            {
                ReverseTween();
            }

            if (loopType == LoopType.RestartFromBeginning || numLoops % 2 == 0)
            {
                if (loopCompletionHandler != null)
                {
                    loopCompletionHandler(this.target.GetTweenedValue());
                }
            }

            if (numLoops > 0)
            {
                tweenState = TweenState.Running;

                if (loopType == LoopType.RestartFromBeginning)
                {
                    elapsedTime = elapsedTimeExcess - delayBetweenLoops;
                }
                else
                {
                    if (isRunningInReverse)
                    {
                        elapsedTime += delayBetweenLoops - elapsedTimeExcess;
                    }
                    else
                    {
                        elapsedTime = elapsedTimeExcess - delayBetweenLoops;
                    }
                }

                if (delayBetweenLoops == 0f && elapsedTimeExcess > 0f)
                {
                    UpdateValue();
                }
            }
        }
Esempio n. 27
0
    private void ShowWindowAni(float duration = 0.5f)
    {
        _onClick.Show();
        _tipsWindow.Show();
        float waitTime = _waitTime;

        _isPlaying = true;

        var pb   = _instance._attainmentAwardQueue.Dequeue();
        var list = pb.Award;

        _titleTxt.text = I18NManager.Get("Common_TipWindowTxt", pb.MissionDesc);
        PointerClickListener.Get(_tipsWindow.gameObject).onClick = null;
        PointerClickListener.Get(_tipsWindow.gameObject).onClick = go =>
        {
            OnClickSpeedUp();
            ModuleManager.Instance.EnterModule(ModuleConfig.MODULE_STAR_ACTIVITY, true, false, pb.Extra.Days
                                               );
        };



        foreach (var t in list)
        {
            RewardVo rewardVo = new RewardVo(t);
            _propImg.texture = ResourceManager.Load <Texture>(rewardVo.IconPath);
            _propNum.text    = rewardVo.Num.ToString();
        }



        var move1 = _rect.DOAnchorPosX(0f, duration);

        var move2 = _rect.DOAnchorPosX(_rect.GetWidth(), duration);

        _tween = DOTween.Sequence()
                 .Append(move1).AppendCallback(() => { _state = TweenState.WaitState; })
                 .AppendInterval(waitTime).AppendCallback(() => { _state = TweenState.Move2State; })
                 .Append(move2).AppendCallback(() => { _state = TweenState.Move1State; });

        _tween.OnComplete(_instance.TweenOver);//动画完成的回调
    }
Esempio n. 28
0
        // -------------------------------------------------------------------------------------------
        /// <summary>
        /// Cleanup.
        /// </summary>
        public void Dispose()
        {
            if (_state == TweenState.COMPLETE)
            {
                return;
            }

            _state      = TweenState.COMPLETE;
            _onStart    = null;
            _onUpdate   = null;
            _onComplete = null;
            _onRepeat   = null;
            _target     = null;

            foreach (ITweenProcedure p in _procedures)
            {
                p.Dispose();
            }
            _procedures = null;
        }
Esempio n. 29
0
        protected override void OnUpdate()
        {
            float deltaTime = Time.DeltaTime;

            Entities
            .WithNone <TweenPause>()
            .ForEach((ref DynamicBuffer <TweenState> tweenBuffer) =>
            {
                for (int i = 0; i < tweenBuffer.Length; i++)
                {
                    TweenState tween = tweenBuffer[i];
                    tween.Time      += tween.IsReverting ? -deltaTime : deltaTime;

                    float normalizedTime = tween.GetNormalizedTime();
                    tween.EasePercentage = Ease.CalculatePercentage(normalizedTime, tween.EaseType, tween.EaseExponent);

                    tweenBuffer[i] = tween;
                }
            }).ScheduleParallel();
        }
Esempio n. 30
0
        public void Update(float delta)
        {
            if (State != TweenState.Running)
            {
                return;
            }

            if (_progress >= 1f)
            {
                _progress    = 1f;
                CurrentValue = EndValue;
                State        = TweenState.Stopped;
            }
            else
            {
                _timer      += delta;
                _progress    = 1f / _duration * _timer;
                CurrentValue = _lerp(StartValue, EndValue, _easeFunc(_progress));
            }
        }
Esempio n. 31
0
		/// <summary>
		/// Stop the tween
		/// </summary>
		public virtual TweenBase Stop()
		{

			if( this.State == TweenState.Stopped )
				return this;

			unregisterWithTweenManager();

			this.State = TweenState.Stopped;
			raiseStopped();

			return this;

		}
Esempio n. 32
0
        public void Update(GameTime gameTime)
        {
            if(State!=TweenState.Running) return;

            switch (CurrentDirection)
            {
                case TweenDirection.Forward:
                    CurrentTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (CurrentTime >= TargetTime)
                    {
                        if (PingPong)
                        {
                            if (InitialDirection == TweenDirection.Reverse)
                            {
                                if(Looping) CurrentDirection = TweenDirection.Reverse;
                                else State = TweenState.Finished;
                            }
                            else CurrentDirection = TweenDirection.Reverse;
                            CurrentTime -= (CurrentTime - TargetTime);
                        }
                        else
                        {
                            if (Looping) CurrentTime = (CurrentTime-TargetTime);
                            else State = TweenState.Finished;
                        }
                    }
                    break;
                case TweenDirection.Reverse:
                    CurrentTime -= gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (CurrentTime <= 0)
                    {
                        if (PingPong)
                        {
                            if (InitialDirection == TweenDirection.Forward)
                            {
                                if(Looping) CurrentDirection = TweenDirection.Forward;
                                else State = TweenState.Finished;
                            }
                            else CurrentDirection = TweenDirection.Forward;
                            CurrentTime = -CurrentTime;
                        }
                        else
                        {
                            if (Looping) CurrentTime = TargetTime+CurrentTime;
                            else State = TweenState.Finished;
                        }
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            float pos = (1f/(float)TargetTime) * (float)CurrentTime;
            Value = _tweenFunc(pos);
            _callback(this);
        }
Esempio n. 33
0
		/// <summary>
		/// Resumes a paused tween
		/// </summary>
		public virtual TweenBase Resume()
		{

			if( this.State != TweenState.Paused )
				return this;

			this.State = TweenState.Playing;
			raiseResumed();

			return this;

		}
Esempio n. 34
0
 public void Resume()
 {
     State = TweenState.Running;
 }
Esempio n. 35
0
 public void Pause()
 {
     State = TweenState.Paused;
 }
Esempio n. 36
0
 public void Kill()
 {
     State = TweenState.Finished;
 }
Esempio n. 37
0
		/// <summary>
		/// Pause the tween, if it is playing
		/// </summary>
		public virtual TweenBase Pause()
		{

			if( this.State != TweenState.Playing && this.State != TweenState.Started )
			{
				return this;
			}

			this.State = TweenState.Paused;
			raisePaused();

			return this;

		}
Esempio n. 38
0
		/// <summary>
		/// Play the tween
		/// </summary>
		public virtual TweenBase Play()
		{

			this.State = TweenState.Started;
			this.CurrentTime = 0f;
			this.startTime = getCurrentTime();

			registerWithTweenManager();
			raiseStarted();

			return this;

		}