Пример #1
0
 public static TweenPlugPathOrientTransform Get()
 {
     if (mInstance == null)
     {
         mInstance = new TweenPlugPathOrientTransform();
     }
     return(mInstance);
 }
Пример #2
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }
            else if (canTween)
            {
                //invalid or in-between keys
                if (endFrame == -1)
                {
                    return;
                }
            }

            var trans = obj as Transform;

            Rigidbody   body   = trans.GetComponent <Rigidbody>();
            Rigidbody2D body2D = !body?trans.GetComponent <Rigidbody2D>() : null;

            var   tTrack    = track as TranslationTrack;
            bool  pixelSnap = tTrack.pixelSnap;
            float ppu       = tTrack.pixelPerUnit;

            int   frameRate = seq.take.frameRate;
            float time      = getTime(frameRate);

            Tweener tween = null;

            if (interp == Interpolation.None)
            {
                //TODO: world position
                Vector3 pos = pixelSnap ? new Vector3(Mathf.Round(position.x * ppu) / ppu, Mathf.Round(position.y * ppu) / ppu, Mathf.Round(position.z * ppu) / ppu) : position;

                if (body2D)
                {
                    tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body2D.position = parent.TransformPoint(x);
                        }
                        else
                        {
                            body2D.position = x;
                        }
                    }, pos, time); //1.0f / frameRate
                }
                else if (body)
                {
                    tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body.position = parent.TransformPoint(x);
                        }
                        else
                        {
                            body.position = x;
                        }
                    }, pos, time); //1.0f / frameRate
                }
                else
                {
                    tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => trans.localPosition = x, pos, time); //1.0f / frameRate
                }
            }
            else if (interp == Interpolation.Linear || path == null)
            {
                Vector3 endPos = (track.keys[index + 1] as TranslationKey).position;

                DOSetter <Vector3> setter;
                if (body2D)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)));
                            }
                            else
                            {
                                body2D.MovePosition(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body2D.MovePosition(x);
                            }
                        }
                    };
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)));
                            }
                            else
                            {
                                body.MovePosition(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body.MovePosition(x);
                            }
                        }
                    };
                }
                else
                {
                    if (pixelSnap)
                    {
                        setter = x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu);
                    }
                    else
                    {
                        setter = x => trans.localPosition = x;
                    }
                }

                if (orientMode == OrientMode.None)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => position, setter, endPos, time);
                }
                else
                {
                    TweenerCore <Vector3, Vector3, TweenPlugVector3LookAtOptions> tweenOrient;

                    if (body)
                    {
                        tweenOrient        = DOTween.To(TweenPlugVector3LookAtRigidbody.Get(), () => position, setter, endPos, time);
                        tweenOrient.target = body;
                    }
                    else if (body2D)
                    {
                        tweenOrient        = DOTween.To(TweenPlugVector3LookAtRigidbody2D.Get(), () => position, setter, endPos, time);
                        tweenOrient.target = body2D;
                    }
                    else
                    {
                        tweenOrient        = DOTween.To(TweenPlugVector3LookAtTransform.Get(), () => position, setter, endPos, time);
                        tweenOrient.target = trans;
                    }

                    tweenOrient.plugOptions = new TweenPlugVector3LookAtOptions()
                    {
                        orientMode = orientMode, lockAxis = orientLockAxis, lookAtPt = endPos, lookAtIsLocal = true
                    };
                    tween = tweenOrient;
                }
            }
            else if (interp == Interpolation.Curve)
            {
                DOSetter <Vector3> setter;
                if (body2D)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)));
                            }
                            else
                            {
                                body2D.MovePosition(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body2D.MovePosition(x);
                            }
                        }
                    };
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)));
                            }
                            else
                            {
                                body.MovePosition(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body.MovePosition(x);
                            }
                        }
                    };
                }
                else
                {
                    if (pixelSnap)
                    {
                        setter = x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu);
                    }
                    else
                    {
                        setter = x => trans.localPosition = x;
                    }
                }

                if (orientMode == OrientMode.None)
                {
                    tween = DOTween.To(TweenPlugPathVector3.Get(), () => position, setter, path, time);
                }
                else
                {
                    TweenerCore <Vector3, TweenPlugPath, TweenPlugPathOrientOptions> tweenOrient;

                    if (body)
                    {
                        tweenOrient        = DOTween.To(TweenPlugPathOrientRigidbody.Get(), () => position, setter, path, time);
                        tweenOrient.target = body;
                    }
                    else if (body2D)
                    {
                        tweenOrient        = DOTween.To(TweenPlugPathOrientRigidbody2D.Get(), () => position, setter, path, time);
                        tweenOrient.target = body2D;
                    }
                    else
                    {
                        tweenOrient        = DOTween.To(TweenPlugPathOrientTransform.Get(), () => position, setter, path, time);
                        tweenOrient.target = trans;
                    }

                    tweenOrient.plugOptions = new TweenPlugPathOrientOptions {
                        orientMode = orientMode, lockAxis = orientLockAxis
                    };
                    tween = tweenOrient;
                }
            }

            if (tween != null)
            {
                if (canTween)
                {
                    if (hasCustomEase())
                    {
                        tween.SetEase(easeCurve);
                    }
                    else
                    {
                        tween.SetEase(easeType, amplitude, period);
                    }
                }

                seq.Insert(this, tween);
            }
        }