예제 #1
0
        public override void updateCache(ITarget target)
        {
            base.updateCache(target);

            // save rotation
            //Quaternion temp = obj.rotation;

            for (int i = 0; i < keys.Count; i++)
            {
                OrientationKey key = keys[i] as OrientationKey;

                key.version = version;

                if (keys.Count > (i + 1))
                {
                    key.endFrame = keys[i + 1].frame;
                }
                else
                {
                    if (i > 0 && !keys[i - 1].canTween)
                    {
                        key.interp = Key.Interpolation.None;
                    }

                    key.endFrame = -1;
                }
            }
            // restore rotation
            //if(restoreRotation) obj.rotation = temp;
        }
예제 #2
0
        // add a new key
        public void addKey(ITarget itarget, int _frame, Transform target)
        {
            foreach (OrientationKey key in keys)
            {
                // if key exists on frame, update key
                if (key.frame == _frame)
                {
                    key.SetTarget(itarget, target);
                    // update cache
                    updateCache(itarget);
                    return;
                }
            }
            OrientationKey a = new OrientationKey();

            a.frame = _frame;
            if (target)
            {
                a.SetTarget(itarget, target);
            }
            // set default ease type to linear
            a.easeType = Ease.Linear;// AMTween.EaseType.linear;
            // add a new key
            keys.Add(a);
            // update cache
            updateCache(itarget);
        }
예제 #3
0
        public override void previewFrame(ITarget itarget, float frame, int frameRate, bool play, float playSpeed)
        {
            Transform t = GetTarget(itarget) as Transform;

            if (keys == null || keys.Count <= 0)
            {
                return;
            }

            // if before or equal to first frame, or is the only frame
            OrientationKey firstKey = keys[0] as OrientationKey;

            if (firstKey.endFrame == -1 || (frame <= (float)firstKey.frame && !firstKey.canTween))
            {
                Transform keyt = firstKey.GetTarget(itarget);
                if (keyt)
                {
                    t.LookAt(keyt);
                }
                return;
            }

            for (int i = 0; i < keys.Count; i++)
            {
                OrientationKey key     = keys[i] as OrientationKey;
                OrientationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as OrientationKey : null;

                if (frame >= (float)key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.endFrame != -1))
                {
                    continue;
                }

                Transform keyt = key.GetTarget(itarget);

                // if no ease
                if (!key.canTween || keyNext == null)
                {
                    if (keyt)
                    {
                        t.LookAt(keyt);
                    }
                    return;
                }
                // else easing function

                Transform keyet = keyNext.GetTarget(itarget);

                float numFrames = (float)key.getNumberOfFrames(frameRate);

                float framePositionInAction = Mathf.Clamp(frame - (float)key.frame, 0f, numFrames);

                t.rotation = key.getQuaternionAtPercent(t, keyt, keyet, framePositionInAction / numFrames);

                return;
            }
        }
예제 #4
0
        // draw gizmos
        public override void drawGizmos(ITarget itarget, float gizmo_size, bool inPlayMode, int frame)
        {
            if (!obj)
            {
                return;
            }

            // draw line to target
            bool isLineDrawn = false;

            if (!inPlayMode)
            {
                for (int i = 0; i < keys.Count; i++)
                {
                    OrientationKey key = keys[i] as OrientationKey;
                    if (key == null)
                    {
                        continue;
                    }

                    OrientationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as OrientationKey : null;

                    Transform t = key.GetTarget(itarget);
                    if (t)
                    {
                        //draw target
                        Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 1f);
                        Gizmos.DrawSphere(t.position, 0.2f * (AnimateTimeline.e_gizmoSize / 0.1f));

                        //draw line
                        if (!isLineDrawn)
                        {
                            if (key.frame > frame)
                            {
                                isLineDrawn = true;
                            }
                            if (frame >= key.frame && frame <= key.endFrame)
                            {
                                if (keyNext == null || t == keyNext.GetTarget(itarget))
                                {
                                    Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 0.2f);
                                    Gizmos.DrawLine(obj.transform.position, t.position);
                                }
                                isLineDrawn = true;
                            }
                        }
                    }
                }
            }
            // draw arrow
            Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 1f);
            Vector3 pos  = obj.transform.position;
            float   size = (1.2f * (gizmo_size / 0.1f));

            if (size < 0.1f)
            {
                size = 0.1f;
            }
            Vector3 direction       = obj.forward * size;
            float   arrowHeadAngle  = 20f;
            float   arrowHeadLength = 0.3f * size;

            Gizmos.DrawRay(pos, direction);

            Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0, 0, 1);
            Vector3 left  = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0, 0, 1);

            Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
            Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
        }