示例#1
0
        protected void DrawCommonProperties()
        {
            UITweener tw = target as UITweener;

            if (NTweenEditorTools.DrawHeader("Tweener"))
            {
                NTweenEditorTools.BeginContents();
                NTweenEditorTools.SetLabelWidth(110f);

                GUI.changed = false;

                UITweener.Style style = (UITweener.Style)EditorGUILayout.EnumPopup("Play Style", tw.style);
                AnimationCurve  curve = EditorGUILayout.CurveField("Animation Curve", tw.animationCurve, GUILayout.Width(170f), GUILayout.Height(62f));
                //UITweener.Method method = (UITweener.Method)EditorGUILayout.EnumPopup("Play Method", tw.method);

                GUILayout.BeginHorizontal();
                float dur = EditorGUILayout.FloatField("Duration", tw.duration, GUILayout.Width(170f));
                GUILayout.Label("seconds");
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                int lt = EditorGUILayout.IntField("Loop Times", tw.loopTimes, GUILayout.Width(170f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                int fd = EditorGUILayout.IntField(new GUIContent("Frame Delay", "由于Tween自身的时间计算机制,预制键实例化引起的卡顿会造成绑定在上面的tween动画在开始播放时出现跳帧的情况,基于帧数延迟启动可以改善该问题(帧延迟结束后才开始时间延迟计时)"), tw.delayFrame, GUILayout.Width(170f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                float del = EditorGUILayout.FloatField("Time Delay", tw.delay, GUILayout.Width(170f));
                GUILayout.Label("seconds");
                GUILayout.EndHorizontal();

                int  tg           = EditorGUILayout.IntField("Tween Group", tw.tweenGroup, GUILayout.Width(170f));
                bool ts           = EditorGUILayout.Toggle("Ignore TimeScale", tw.ignoreTimeScale);
                bool resetAtStart = EditorGUILayout.Toggle(new GUIContent("Reset At Start"), tw.resetAtStart, GUILayout.Width(170f));

                Object receiver         = EditorGUILayout.ObjectField("Receiver", tw.eventReceiver, typeof(GameObject));
                string callWhenFinished = EditorGUILayout.TextField("Finished Callback", tw.callWhenFinished);

                if (GUI.changed)
                {
                    NTweenEditorTools.RegisterUndo("Tween Change", tw);
                    tw.animationCurve = curve;
                    //tw.method = method;
                    tw.style            = style;
                    tw.ignoreTimeScale  = ts;
                    tw.tweenGroup       = tg;
                    tw.resetAtStart     = resetAtStart;
                    tw.duration         = dur;
                    tw.loopTimes        = lt;
                    tw.delayFrame       = fd;
                    tw.delay            = del;
                    tw.eventReceiver    = receiver as GameObject;
                    tw.callWhenFinished = callWhenFinished;
                    NTweenTools.SetDirty(tw);
                }
                NTweenEditorTools.EndContents();
            }

            NTweenEditorTools.SetLabelWidth(80f);
            //NTweenEditorTools.DrawEvents("On Finished", tw, tw.onFinished);
        }
示例#2
0
        /// <summary>
        /// Update the tweening factor and call the virtual update function.
        /// </summary>

        void Update()
        {
            if (mStartFrame == 0)
            {
                mStartFrame = Time.frameCount + delayFrame;
            }
            if (Time.frameCount < mStartFrame)
            {
                return;
            }

            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;
            }

            // 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)
                {
                    mLoopTimes++;
                    if (loopTimes <= 0 || mLoopTimes < loopTimes)
                    {
                        mFactor -= Mathf.Floor(mFactor);
                    }
                }
            }
            else if (style == Style.PingPong)
            {
                // Ping-pong style reverses the direction
                if (mFactor > 1f)
                {
                    mLoopTimes++;
                    if (loopTimes <= 0 || mLoopTimes < loopTimes)
                    {
                        mFactor = 1f - (mFactor - Mathf.Floor(mFactor));
                    }
                    mAmountPerDelta = -mAmountPerDelta;
                }
                else if (mFactor < 0f)
                {
                    mLoopTimes++;
                    if (loopTimes <= 0 || mLoopTimes < loopTimes)
                    {
                        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) || (loopTimes > 0 && mLoopTimes >= loopTimes))
            {
                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) || (loopTimes > 0 && mLoopTimes >= loopTimes))
                {
                    enabled = false;
                }

                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.Add(onFinished, mTemp[i]);
                    }
                    mTemp = null;
                }

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

                if (onFinishCallback != null)
                {
                    onFinishCallback(this);
                }

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