Beispiel #1
0
        //!
        //! updates the saved animation curve's keyframe with the current values of the keyframe in the GUI
        //! this is called when repositioning the keyframe
        //!
        public void updateKeyInCurve()
        {
            AnimationCurve transXcurve = animData.getAnimationCurve(clip, "m_LocalPosition.x");
            AnimationCurve transYcurve = animData.getAnimationCurve(clip, "m_LocalPosition.y");
            AnimationCurve transZcurve = animData.getAnimationCurve(clip, "m_LocalPosition.z");

            transXcurve.MoveKey(keyFrameNumber, new Keyframe(transXcurve.keys[keyFrameNumber].time, this.transform.position.x, transXcurve.keys[keyFrameNumber].inTangent, transXcurve.keys[keyFrameNumber].outTangent));
            transYcurve.MoveKey(keyFrameNumber, new Keyframe(transYcurve.keys[keyFrameNumber].time, this.transform.position.y, transYcurve.keys[keyFrameNumber].inTangent, transYcurve.keys[keyFrameNumber].outTangent));
            transZcurve.MoveKey(keyFrameNumber, new Keyframe(transZcurve.keys[keyFrameNumber].time, this.transform.position.z, transZcurve.keys[keyFrameNumber].inTangent, transZcurve.keys[keyFrameNumber].outTangent));

            animData.changeAnimationCurve(clip, typeof(Transform), "m_LocalPosition.x", transXcurve);
            animData.changeAnimationCurve(clip, typeof(Transform), "m_LocalPosition.y", transYcurve);
            animData.changeAnimationCurve(clip, typeof(Transform), "m_LocalPosition.z", transZcurve);
        }
Beispiel #2
0
        //!
        //! sets the keyframe at the current time of the animation to a new value for the currently animated object
        //! automatically adds keyframe if there is none at this time of the animation
        //!
        public void setKeyframe()
        {
            bool movedSuccessfully = false;
            int  keyIndex          = -1;

            //x value
            Keyframe key = new Keyframe(animationController.currentAnimationTime, this.transform.position.x);

            for (int i = 0; i < this.transCurves[0].length; i++)
            {
                if (Mathf.Abs(this.transCurves[0].keys[i].time - animationController.currentAnimationTime) < 0.04)
                {
                    this.transCurves[0].MoveKey(i, key);
                    keyIndex          = i;
                    movedSuccessfully = true;
                }
            }
            if (!movedSuccessfully)
            {
                keyIndex          = this.transCurves[0].AddKey(key);
                movedSuccessfully = false;
            }
            if (transCurves[0].keys.Length > 1)
            {
                if (keyIndex == 0)
                {
                    this.transCurves[0].SmoothTangents(1, 0);
                }
                if (keyIndex == transCurves[0].keys.Length - 1)
                {
                    this.transCurves[0].SmoothTangents(transCurves[0].keys.Length - 2, 0);
                }
            }
            this.transCurves[0].SmoothTangents(keyIndex, 0);

            //y value
            key = new Keyframe(animationController.currentAnimationTime, this.transform.position.y);
            for (int i = 0; i < this.transCurves[1].length; i++)
            {
                if (Mathf.Abs(this.transCurves[1].keys[i].time - animationController.currentAnimationTime) < 0.04)
                {
                    this.transCurves[1].MoveKey(i, key);
                    keyIndex          = i;
                    movedSuccessfully = true;
                }
            }
            if (!movedSuccessfully)
            {
                keyIndex          = this.transCurves[1].AddKey(key);
                movedSuccessfully = false;
            }
            if (transCurves[1].keys.Length > 1)
            {
                if (keyIndex == 0)
                {
                    this.transCurves[1].SmoothTangents(1, 0);
                }
                if (keyIndex == transCurves[1].keys.Length - 1)
                {
                    this.transCurves[1].SmoothTangents(transCurves[1].keys.Length - 2, 0);
                }
            }
            this.transCurves[1].SmoothTangents(keyIndex, 0);

            //z value
            key = new Keyframe(animationController.currentAnimationTime, this.transform.position.z);
            for (int i = 0; i < this.transCurves[2].length; i++)
            {
                if (Mathf.Abs(this.transCurves[2].keys[i].time - animationController.currentAnimationTime) < 0.04)
                {
                    this.transCurves[2].MoveKey(i, key);
                    keyIndex          = i;
                    movedSuccessfully = true;
                }
            }
            if (!movedSuccessfully)
            {
                keyIndex          = this.transCurves[2].AddKey(key);
                movedSuccessfully = false;
            }

            if (transCurves[2].keys.Length > 1)
            {
                if (keyIndex == 0)
                {
                    this.transCurves[2].SmoothTangents(1, 0);
                }
                if (keyIndex == transCurves[2].keys.Length - 1)
                {
                    this.transCurves[2].SmoothTangents(transCurves[2].keys.Length - 2, 0);
                }
            }
            this.transCurves[2].SmoothTangents(keyIndex, 0);

            animData.changeAnimationCurve(animData.getAnimationClips(target.gameObject)[0], typeof(Transform), "m_LocalPosition.x", transCurves[0]);
            animData.changeAnimationCurve(animData.getAnimationClips(target.gameObject)[0], typeof(Transform), "m_LocalPosition.y", transCurves[1]);
            animData.changeAnimationCurve(animData.getAnimationClips(target.gameObject)[0], typeof(Transform), "m_LocalPosition.z", transCurves[2]);

            updateAnimationCurves();
        }
        public void setKeyFrame()
        {
            currentAnimationTime = timeLine.CurrentTime;

            if (animationTarget != null)
            {
                AnimationClip clip = initAnimationClip();



                // add animation curves if not there already
                if (animData.getAnimationCurve(clip, animationProperties[0]) == null)
                {
                    foreach (string prop in animationProperties)
                    {
                        // add property curve
                        AnimationCurve _curve = new AnimationCurve();

                        //add curve to runtime data representation
                        animData.addAnimationCurve(clip, typeof(Transform), prop, _curve);
                    }
                }


                for (int n = 0; n < animationProperties.Length; n++)
                {
                    // named property in curve
                    string prop = animationProperties[n];
                    // property delegate
                    PropertyInfo field = animationFields[n];


                    // get or create curve
                    AnimationCurve _curve = animData.getAnimationCurve(clip, prop);
                    if (_curve == null)
                    {
                        _curve = new AnimationCurve();
                    }

                    // add or move keyframe
                    bool     movedSuccessfully = false;
                    int      keyIndex          = -1;
                    Keyframe key = new Keyframe(currentAnimationTime, (float)field.GetValue(animationInstance, null));
                    for (int i = 0; i < _curve.length; i++)
                    {
                        if (Mathf.Abs(_curve.keys[i].time - currentAnimationTime) < 0.04)
                        {
                            _curve.MoveKey(i, key);
                            keyIndex          = i;
                            movedSuccessfully = true;
                        }
                    }
                    if (!movedSuccessfully)
                    {
                        keyIndex          = _curve.AddKey(key);
                        movedSuccessfully = false;
                    }
                    if (_curve.keys.Length > 1)
                    {
                        if (keyIndex == 0)
                        {
                            _curve.SmoothTangents(1, 0);
                        }
                        if (keyIndex == _curve.keys.Length - 1)
                        {
                            _curve.SmoothTangents(_curve.keys.Length - 2, 0);
                        }
                    }
                    _curve.SmoothTangents(keyIndex, 0);

                    // update animation data
                    animData.changeAnimationCurve(clip, typeof(Transform), prop, _curve);
                }

                // TODO: cheesy
                // animationTarget.GetComponent<SceneObject>().setKeyframe();
                animationTarget.GetComponent <SceneObject>().updateAnimationCurves();
                updateTimelineKeys();
                updateLine();
            }
        }