Ejemplo n.º 1
0
    public void updateKeyFrameOnCurve(Keyframe keyframe, AnimationCurveToUpdate curve)
    {
        // find which keyframe value was updated
        int keyFrameIndex;

        Debug.Log("updating key frame!");
        switch (curve)
        {
        case AnimationCurveToUpdate.x:
            for (int i = 0; i < curveX.keys.Length; i++)
            {
                // step 2) check if this keyframe time is the same
                if (curveX.keys[i].time == keyframe.time)
                {
                    Debug.Log("updating key frame x!");

                    keyFrameIndex = curveX.MoveKey(i, keyframe);
                    clip.SetCurve("", typeof(Transform), "localPosition.x", curveX);

                    if (animTrack.onKeyFrameUpdated != null)
                    {
                        animTrack.onKeyFrameUpdated(keyFrameIndex, keyframe.time, curve);
                    }
                    break;
                }
            }
            break;

        case AnimationCurveToUpdate.y:
            for (int i = 0; i < curveY.keys.Length; i++)
            {
                // step 2) check if this keyframe time is the same
                if (curveY.keys[i].time == keyframe.time)
                {
                    Debug.Log("updating key frame y!");

                    keyFrameIndex = curveY.MoveKey(i, keyframe);
                    clip.SetCurve("", typeof(Transform), "localPosition.y", curveY);

                    if (animTrack.onKeyFrameUpdated != null)
                    {
                        animTrack.onKeyFrameUpdated(keyFrameIndex, keyframe.time, curve);
                    }
                    break;
                }
            }
            break;

        case AnimationCurveToUpdate.z:
            for (int i = 0; i < curveZ.keys.Length; i++)
            {
                // step 2) check if this keyframe time is the same
                if (curveZ.keys[i].time == keyframe.time)
                {
                    Debug.Log("updating key frame z!");

                    keyFrameIndex = curveZ.MoveKey(i, keyframe);
                    clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ);

                    if (animTrack.onKeyFrameUpdated != null)
                    {
                        animTrack.onKeyFrameUpdated(keyFrameIndex, keyframe.time, curve);
                    }
                    break;
                }
            }
            break;

        case AnimationCurveToUpdate.rotationX:
        {
            for (int i = 0; i < rotationXcurve.keys.Length; i++)
            {
                // step 2) check if this keyframe time is the same
                if (rotationXcurve.keys[i].time == keyframe.time)
                {
                    keyFrameIndex = rotationXcurve.MoveKey(i, keyframe);
                    clip.SetCurve("", typeof(Transform), "localRotation.x", rotationXcurve);

                    if (animTrack.onKeyFrameUpdated != null)
                    {
                        animTrack.onKeyFrameUpdated(keyFrameIndex, keyframe.time, curve);
                    }
                    break;
                }
            }
        }
        break;

        case AnimationCurveToUpdate.rotationY:
            for (int i = 0; i < rotationYcurve.keys.Length; i++)
            {
                // step 2) check if this keyframe time is the same
                if (rotationYcurve.keys[i].time == keyframe.time)
                {
                    keyFrameIndex = rotationYcurve.MoveKey(i, keyframe);
                    clip.SetCurve("", typeof(Transform), "localRotation.y", rotationYcurve);

                    if (animTrack.onKeyFrameUpdated != null)
                    {
                        animTrack.onKeyFrameUpdated(keyFrameIndex, keyframe.time, curve);
                    }
                    break;
                }
            }
            break;

        case AnimationCurveToUpdate.rotationZ:
            for (int i = 0; i < rotationZcurve.keys.Length; i++)
            {
                // step 2) check if this keyframe time is the same
                if (rotationZcurve.keys[i].time == keyframe.time)
                {
                    keyFrameIndex = rotationZcurve.MoveKey(i, keyframe);
                    clip.SetCurve("", typeof(Transform), "localRotation.z", rotationZcurve);

                    if (animTrack.onKeyFrameUpdated != null)
                    {
                        animTrack.onKeyFrameUpdated(keyFrameIndex, keyframe.time, curve);
                    }
                    break;
                }
            }
            break;
        }
    }