Exemplo n.º 1
0
        /// <summary>
        /// Update the tweening factor and call the virtual update function.
        /// </summary>

        private void Update()
        {
            float delta = ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
            float time  = ignoreTimeScale ? Time.unscaledTime : Time.time;

            if (!mStarted)
            {
                mStarted   = true;
                mStartTime = time + delay;
            }

            if (time < mStartTime)
            {
                return;
            }

            // Advance the sampling factor
            mFactor += amountPerDelta * delta;

            // Loop style simply resets the play factor after it exceeds 1.
            if (style == Style.Loop)
            {
                if (mFactor > 1f)
                {
                    mFactor -= Mathf.Floor(mFactor);
                }
            }
            else if (style == Style.PingPong)
            {
                // Ping-pong style reverses the direction
                if (mFactor > 1f)
                {
                    mFactor         = 1f - (mFactor - Mathf.Floor(mFactor));
                    mAmountPerDelta = -mAmountPerDelta;
                }
                else if (mFactor < 0f)
                {
                    mFactor         = -mFactor;
                    mFactor        -= Mathf.Floor(mFactor);
                    mAmountPerDelta = -mAmountPerDelta;
                }
            }

            // If the factor goes out of range and this is a one-time tweening operation, disable the script
            if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
            {
                mFactor = Mathf.Clamp01(mFactor);
                Sample(mFactor, true);
                if (isEnableReplay == false)
                {
                    enabled = false;
                }

                if (current != this)
                {
                    UITweener before = current;
                    current = this;

                    //if (onFinished != null)
                    //{
                    //mTemp = onFinished;
                    //onFinished = new List<EventDelegate>();

                    //// Notify the listener delegates
                    //EventDelegate.Execute(mTemp);

                    //// Re-add the previous persistent delegates
                    //for (int i = 0; i < mTemp.Count; ++i)
                    //{
                    //	EventDelegate ed = mTemp[i];
                    //	if (ed != null && !ed.oneShot) EventDelegate.Add(onFinished, ed, ed.oneShot);
                    //}
                    //mTemp = null;
                    //}
                    if (FinishMathod != null)
                    {
                        FinishMathod(this);
                    }
                    // Deprecated legacy functionality support
                    if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
                    {
                        eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
                    }

                    current = before;
                }
            }
            else
            {
                Sample(mFactor, false);
            }
        }