コード例 #1
0
        /// <summary>
        /// Start the tweening operation.
        /// </summary>

        static public UTweenTransform Begin(GameObject go, float duration, Transform from, Transform to)
        {
            UTweenTransform comp = UTweener.Begin <UTweenTransform>(go, duration);

            comp.from = from;
            comp.to   = to;

            if (duration <= 0f)
            {
                comp.Sample(1f, true);
                comp.enabled = false;
            }
            return(comp);
        }
コード例 #2
0
ファイル: UTweenPosition.cs プロジェクト: Mrhufenglei/GameJam
        /// <summary>
        /// Start the tweening operation.
        /// </summary>

        static public UTweenPosition Begin(GameObject go, float duration, Vector3 pos)
        {
            UTweenPosition comp = UTweener.Begin <UTweenPosition>(go, duration);

            comp.from = comp.value;
            comp.to   = pos;

            if (duration <= 0f)
            {
                comp.Sample(1f, true);
                comp.enabled = false;
            }
            return(comp);
        }
コード例 #3
0
ファイル: UTweenRotation.cs プロジェクト: Mrhufenglei/GameJam
        /// <summary>
        /// Start the tweening operation.
        /// </summary>

        static public UTweenRotation Begin(GameObject go, float duration, Quaternion rot)
        {
            UTweenRotation comp = UTweener.Begin <UTweenRotation>(go, duration);

            comp.from = comp.value.eulerAngles;
            comp.to   = rot.eulerAngles;

            if (duration <= 0f)
            {
                comp.Sample(1f, true);
                comp.enabled = false;
            }
            return(comp);
        }
コード例 #4
0
        /// <summary>
        /// Start the tweening operation.
        /// </summary>

        static public UTweenScale Begin(GameObject go, float duration, Vector3 scale)
        {
            UTweenScale comp = UTweener.Begin <UTweenScale>(go, duration);

            comp.from = comp.value;
            comp.to   = scale;

            if (duration <= 0f)
            {
                comp.Sample(1f, true);
                comp.enabled = false;
            }
            return(comp);
        }
コード例 #5
0
        /// <summary>
        /// Start the tweening operation.
        /// </summary>

        static public UTweenColor Begin(GameObject go, float duration, Color color)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return(null);
            }
#endif
            UTweenColor comp = UTweener.Begin <UTweenColor>(go, duration);
            comp.from = comp.value;
            comp.to   = color;

            if (duration <= 0f)
            {
                comp.Sample(1f, true);
                comp.enabled = false;
            }
            return(comp);
        }
コード例 #6
0
ファイル: UTweener.cs プロジェクト: Mrhufenglei/GameJam
        /// <summary>
        /// Update the tweening factor and call the virtual update function.
        /// </summary>
        void Update()
        {
            float delta = ignoreTimeScale ? URealTime.deltaTime : Time.deltaTime;
            float time  = ignoreTimeScale ? URealTime.time : 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);

                // Disable this script unless the function calls above changed something
                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 <UEventDelegate>();

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

                        // Re-add the previous persistent delegates
                        for (int i = 0; i < mTemp.Count; ++i)
                        {
                            UEventDelegate ed = mTemp[i];
                            if (ed != null && !ed.oneShot)
                            {
                                UEventDelegate.Add(onFinished, ed, ed.oneShot);
                            }
                        }
                        mTemp = null;
                    }

                    // Deprecated legacy functionality support
                    if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
                    {
                        eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
                    }

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