Пример #1
0
        void Update()
        {
            float delta = ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime;
            float time  = ignoreTimeScale ? RealTime.time : Time.time;

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

            if (time < mStartTime)
            {
                return;
            }

            mFactor += amountPerDelta * delta;

            if (style == Style.Loop)
            {
                if (mFactor > 1f)
                {
                    mFactor -= Mathf.Floor(mFactor);
                }
            }
            else if (style == Style.PingPong)
            {
                if (mFactor > 1f)
                {
                    mFactor         = 1f - (mFactor - Mathf.Floor(mFactor));
                    mAmountPerDelta = -mAmountPerDelta;
                }
                else if (mFactor < 0f)
                {
                    mFactor         = -mFactor;
                    mFactor        -= Mathf.Floor(mFactor);
                    mAmountPerDelta = -mAmountPerDelta;
                }
            }

            if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
            {
                mFactor = Mathf.Clamp01(mFactor);
                Sample(mFactor, true);

                if (duration == 0f || (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f))
                {
                    enabled = false;
                }

                if (current == null)
                {
                    current = this;

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

                        EventDelegate.Execute(mTemp);

                        for (int i = 0; i < mTemp.Count; ++i)
                        {
                            EventDelegate ed = mTemp[i];
                            if (ed != null)
                            {
                                EventDelegate.Add(onFinished, ed, ed.oneShot);
                            }
                        }
                        mTemp = null;
                    }

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