/// <summary>
        /// Adds the keyframe to clip at time based of current values of root GameObject.
        /// <param name="curveBindingCurrent">Curve binding current.</param>
        /// </summary>
        /// <param name="root">Root.</param>
        /// <param name="clip">Clip.</param>
        /// <param name="time">Time.</param>
        public static void AddKeyframeTo(EditorCurveBinding binding, GameObject root, AnimationClip clip, float time)
        {
            object valueCurrent = AnimationModeUtility.GetCurrentValue(root, binding);

            //if property is "m_LocalRotation.y" create "m_LocalRotation.x" "m_LocalRotation.z" and "m_LocalRotation.w"
            EditorCurveBinding[] array = RotationCurveInterpolationW.RemapAnimationBindingForAddKey(binding, clip);
            if (array != null)
            {
                for (int j = 0; j < array.Length; j++)
                {
                    AddKey(array [j], root, clip, valueCurrent, time);
                }
            }
            else
            {
                AddKey(binding, root, clip, valueCurrent, time);
            }
        }
        /// <summary>
        /// Removes the keyframe from clip (!!! Inserts hidden keyframes in between)
        /// </summary>
        /// <param name="clip">Clip.</param>
        /// <param name="keyframeInx">Keyframe inx.</param>
        public static void RemoveKeyframeFrom(AnimationClip clip, EditorCurveBinding binding, int keyframeInx)
        {
            if (keyframeInx < 0)
            {
                Debug.LogWarning("Try to remove keyframe at index " + keyframeInx + " from prop:" + binding.propertyName + " from " + clip.name);
                return;
            }

            EditorCurveBinding[] curveBindings = RotationCurveInterpolationW.RemapAnimationBindingForAddKey(binding, clip);
            AnimationCurve       curve;



            EditorCurveBinding curveBindingCurrent;

            if (curveBindings != null)
            {
                int curveBindingsNum = curveBindings.Length;

                for (int i = 0; i < curveBindingsNum; i++)
                {
                    curveBindingCurrent = curveBindings [i];
                    curve = AnimationUtility.GetEditorCurve(clip, curveBindingCurrent);

                    if (curve != null && curve.length > keyframeInx)
                    {
                        curve.RemoveKey(keyframeInx);

                        AnimationModeUtility.SaveCurve(curve, clip, curveBindingCurrent);
                    }
                }
            }
            else
            {
                curve = AnimationUtility.GetEditorCurve(clip, binding);

                if (curve != null && curve.length > keyframeInx)
                {
                    curve.RemoveKey(keyframeInx);

                    AnimationModeUtility.SaveCurve(curve, clip, binding);
                }
            }
        }
        /// <summary>
        /// Moves the key to time.
        /// </summary>
        /// <param name="binding">Binding.</param>
        /// <param name="clip">Clip.</param>
        /// <param name="keyframeInx">L.</param>
        /// <param name="time">New Time to be moved keyframe to</param>
        public static void MoveKeyToTime(EditorCurveBinding binding, AnimationClip clip, int keyframeInx, float time)
        {
            if (keyframeInx < 0)
            {
                Debug.LogWarning("Try to move keyframe at index " + keyframeInx + " from prop:" + binding.propertyName + " from " + clip.name);
                return;
            }

            //if property is "m_LocalRotation.y" create "m_LocalRotation.x" "m_LocalRotation.z" and "m_LocalRotation.w"
            EditorCurveBinding[] array = RotationCurveInterpolationW.RemapAnimationBindingForAddKey(binding, clip);
            if (array != null)
            {
                for (int j = 0; j < array.Length; j++)
                {
                    MoveKey(array [j], clip, keyframeInx, time);
                }
            }
            else
            {
                MoveKey(binding, clip, keyframeInx, time);
            }
        }
Example #4
0
        void OnGUI()
        {
            if (__binding != default(EditorCurveBinding))
            {
                if (__curveEditor == null)
                {
                    CurveWrapperW[] curveWrappers;

                    __bindings = RotationCurveInterpolationW.RemapAnimationBindingForAddKey(__binding, __clip);


                    CurveWrapperW      curveWrapperNew;
                    Color              curveColor       = Color.red;
                    int                curveBindingsNum = 0;
                    EditorCurveBinding curveBindingCurrent;
                    if (__bindings != null)
                    {
                        curveBindingsNum = __bindings.Length;
                        __curves         = new AnimationCurve[curveBindingsNum];
                        curveWrappers    = new CurveWrapperW[curveBindingsNum];
                        for (int i = 0; i < curveBindingsNum; i++)
                        {
                            curveBindingCurrent = __bindings [i];
                            __curves [i]        = AnimationUtility.GetEditorCurve(__clip, curveBindingCurrent);

                            curveWrapperNew       = new CurveWrapperW();
                            curveWrapperNew.curve = __curves [i];
                            if (i == 1)
                            {
                                curveColor = Color.green;
                            }
                            else if (i == 2)
                            {
                                curveColor = Color.blue;
                            }

                            curveWrapperNew.color = curveColor;
                            curveWrappers [i]     = curveWrapperNew;
                        }
                    }
                    else
                    {
                        __bindings    = new EditorCurveBinding[] { __binding };
                        __curves      = new AnimationCurve[1];
                        __curves [0]  = AnimationUtility.GetEditorCurve(__clip, __binding);
                        curveWrappers = new CurveWrapperW[1];

                        curveWrapperNew       = new CurveWrapperW();
                        curveWrapperNew.curve = __curves [0];


                        curveWrapperNew.color = curveColor;
                        curveWrappers [0]     = curveWrapperNew;
                    }



                    //This makes layout to work (Reserving space)
                    __curveEditorRect = new Rect(0, 0, Screen.width, Screen.height);
                    //GUILayoutUtility.GetRect (Screen.width - 16f, 200);

                    __curveEditor = new CurveEditorW(__curveEditorRect, curveWrappers, false);

                    __curveEditor.FrameSelected(false, true);                                                             //scale y auto
                    __curveEditor.scaleWithWindow = true;
                    __curveEditor.hSlider         = false;
                    __curveEditor.vSlider         = false;

                    __curveEditor.hRangeMin    = __curves [0].keys [0].time;
                    __curveEditor.hRangeMax    = __clip.length;                                                               // __curves [0].keys [__curves [0].length - 1].time;
                    __curveEditor.hRangeLocked = true;
                    __curveEditor.Scale        = new Vector2(__window.position.width / __clip.length, __curveEditor.Scale.y); //scale x manually
                    __curveEditor.leftmargin   = 0f;

                    __curveEditor.rightmargin = 0;                                                            // __window.position.width - __curveEditor.hRangeMax * __clip.length / __window.position.width;


                    //__curveEditor.onSelect += onCurveSelect;
                }
                else
                {
                    __curveEditorRect  = new Rect(0, 0, Screen.width, Screen.height);
                    __curveEditor.rect = __curveEditorRect;
                    //__curveEditor.Scale=new Vector2(237,__curveEditor.Scale.y);
                    //__curveEditor.FrameSelected (false, false);
                }


                //if(Event.current.type==EventType.MouseMove || Event.current.type==EventType.ScrollWheel && !__window.position.Contains(Event.current.mousePosition))
                //this.Close();

                //EditorGUI.BeginChangeCheck ();

//								if (Event.current.type == EventType.MouseMove && !__window.position.Contains (Event.current.mousePosition)) {
//										this.Close ();
//								}

                if (Event.current.type == EventType.MouseDrag && Event.current.button == 0)
                {
                    //if change happen change curve
                    for (int k = 0; k < __bindings.Length; k++)
                    {
                        AnimationModeUtility.SaveCurve(__curves [k], __clip, __bindings [k]);
                        //Debug.Log ("Save");
                    }
                }

                __curveEditor.DoEditor();


                //	Debug.Log ("CurveEditorWindow:"+__curveEditor.Scale + " " + __window.position.width + " " + Event.current.type);

                //if (EditorGUI.EndChangeCheck ()) {


                //}
            }
        }