Editor utility functions for modifying animation clips.

Exemplo n.º 1
0
 private bool CheckIfPropertyExists(EditorCurveBinding data)
 {
     return(AnimationUtility.GetEditorCurveValueType(this.animatedObject, data) != null);
 }
Exemplo n.º 2
0
 public void SetTangent(int leftRight, AnimationUtility.TangentMode mode, List<KeyIdentifier> keysToSet)
 {
     List<ChangedCurve> list = new List<ChangedCurve>();
     foreach (KeyIdentifier identifier in keysToSet)
     {
         AnimationCurve curve = identifier.curve;
         Keyframe key = identifier.keyframe;
         AnimationUtility.SetKeyBroken(ref key, true);
         if (leftRight == 2)
         {
             AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
             AnimationUtility.SetKeyRightTangentMode(ref key, mode);
         }
         else if (leftRight == 0)
         {
             AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
             if ((AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto) || (AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Auto))
             {
                 AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.TangentMode.Free);
             }
         }
         else
         {
             AnimationUtility.SetKeyRightTangentMode(ref key, mode);
             if ((AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto) || (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Auto))
             {
                 AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.TangentMode.Free);
             }
         }
         if ((mode == AnimationUtility.TangentMode.Constant) && ((leftRight == 0) || (leftRight == 2)))
         {
             key.inTangent = float.PositiveInfinity;
         }
         if ((mode == AnimationUtility.TangentMode.Constant) && ((leftRight == 1) || (leftRight == 2)))
         {
             key.outTangent = float.PositiveInfinity;
         }
         curve.MoveKey(identifier.key, key);
         AnimationUtility.UpdateTangentsFromModeSurrounding(curve, identifier.key);
         ChangedCurve item = new ChangedCurve(curve, identifier.curveId, identifier.binding);
         if (!list.Contains(item))
         {
             list.Add(item);
         }
     }
     this.updater.UpdateCurves(list, "Set Tangents");
 }
 public static void OnEditAnimationEvent(AnimationWindowEvent awevt)
 {
     AnimationEvent[] array = null;
     if (awevt.clip != null)
     {
         array = AnimationUtility.GetAnimationEvents(awevt.clip);
     }
     else if (awevt.clipInfo != null)
     {
         array = awevt.clipInfo.GetEvents();
     }
     if (array != null && awevt.eventIndex >= 0 && awevt.eventIndex < array.Length)
     {
         AnimationEvent evt = array[awevt.eventIndex];
         GUI.changed = false;
         if (awevt.root != null)
         {
             List <AnimationWindowEventMethod> list = AnimationWindowEventInspector.CollectSupportedMethods(awevt);
             List <string> list2 = new List <string>(list.Count);
             for (int i = 0; i < list.Count; i++)
             {
                 AnimationWindowEventMethod animationWindowEventMethod = list[i];
                 string str = " ( )";
                 if (animationWindowEventMethod.parameterType != null)
                 {
                     if (animationWindowEventMethod.parameterType == typeof(float))
                     {
                         str = " ( float )";
                     }
                     else if (animationWindowEventMethod.parameterType == typeof(int))
                     {
                         str = " ( int )";
                     }
                     else
                     {
                         str = string.Format(" ( {0} )", animationWindowEventMethod.parameterType.Name);
                     }
                 }
                 list2.Add(animationWindowEventMethod.name + str);
             }
             int count = list.Count;
             int num   = list.FindIndex((AnimationWindowEventMethod method) => method.name == evt.functionName);
             if (num == -1)
             {
                 num = list.Count;
                 list.Add(new AnimationWindowEventMethod
                 {
                     name          = evt.functionName,
                     parameterType = null
                 });
                 if (string.IsNullOrEmpty(evt.functionName))
                 {
                     list2.Add("(No Function Selected)");
                 }
                 else
                 {
                     list2.Add(evt.functionName + " (Function Not Supported)");
                 }
             }
             EditorGUIUtility.labelWidth = 130f;
             int num2 = num;
             num = EditorGUILayout.Popup("Function: ", num, list2.ToArray(), new GUILayoutOption[0]);
             if (num2 != num && num != -1 && num != count)
             {
                 evt.functionName    = list[num].name;
                 evt.stringParameter = string.Empty;
             }
             Type parameterType = list[num].parameterType;
             if (parameterType != null)
             {
                 EditorGUILayout.Space();
                 if (parameterType == typeof(AnimationEvent))
                 {
                     EditorGUILayout.PrefixLabel("Event Data");
                 }
                 else
                 {
                     EditorGUILayout.PrefixLabel("Parameters");
                 }
                 AnimationWindowEventInspector.DoEditRegularParameters(evt, parameterType);
             }
         }
         else
         {
             evt.functionName = EditorGUILayout.TextField(new GUIContent("Function"), evt.functionName, new GUILayoutOption[0]);
             AnimationWindowEventInspector.DoEditRegularParameters(evt, typeof(AnimationEvent));
         }
         if (GUI.changed)
         {
             if (awevt.clip != null)
             {
                 Undo.RegisterCompleteObjectUndo(awevt.clip, "Animation Event Change");
                 AnimationUtility.SetAnimationEvents(awevt.clip, array);
             }
             else if (awevt.clipInfo != null)
             {
                 awevt.clipInfo.SetEvent(awevt.eventIndex, evt);
             }
         }
     }
 }
Exemplo n.º 4
0
 internal static Type GetScriptableObjectEditorCurveValueType(ScriptableObject scriptableObject, EditorCurveBinding binding)
 {
     return(AnimationUtility.INTERNAL_CALL_GetScriptableObjectEditorCurveValueType(scriptableObject, ref binding));
 }
Exemplo n.º 5
0
 public static UnityEngine.Object GetAnimatedObject(GameObject root, EditorCurveBinding binding)
 {
     return(AnimationUtility.INTERNAL_CALL_GetAnimatedObject(root, ref binding));
 }
Exemplo n.º 6
0
 public static AnimationClip[] GetAnimationClips(Animation component)
 {
     return(AnimationUtility.GetAnimationClips(component.gameObject));
 }
Exemplo n.º 7
0
 public static bool GetFloatValue(GameObject root, EditorCurveBinding binding, out float data)
 {
     return(AnimationUtility.INTERNAL_CALL_GetFloatValue(root, ref binding, out data));
 }
        public void SetBroken(object _keysToSet)
        {
            List <ChangedCurve>  changedCurves = new List <ChangedCurve>();
            List <KeyIdentifier> keysToSet     = (List <KeyIdentifier>)_keysToSet;

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                AnimationUtility.SetKeyBroken(ref key, true);
                if (AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.Auto)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, TangentMode.Free);
                }
                if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.Auto)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, TangentMode.Free);
                }

                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }
        public void SetTangent(int leftRight, TangentMode mode, List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> changedCurves = new List <ChangedCurve>();

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                AnimationUtility.SetKeyBroken(ref key, true);
                if (leftRight == 2)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
                    AnimationUtility.SetKeyRightTangentMode(ref key, mode);
                }
                else
                {
                    if (leftRight == 0)
                    {
                        AnimationUtility.SetKeyLeftTangentMode(ref key, mode);

                        // Make sure other tangent is handled correctly
                        if (AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.Auto)
                        {
                            AnimationUtility.SetKeyRightTangentMode(ref key, TangentMode.Free);
                        }
                    }
                    else //if (leftRight == 1)
                    {
                        AnimationUtility.SetKeyRightTangentMode(ref key, mode);

                        // Make sure other tangent is handled correctly
                        if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.Auto)
                        {
                            AnimationUtility.SetKeyLeftTangentMode(ref key, TangentMode.Free);
                        }
                    }
                }

                if (mode == TangentMode.Constant && (leftRight == 0 || leftRight == 2))
                {
                    key.inTangent = Mathf.Infinity;
                }
                if (mode == TangentMode.Constant && (leftRight == 1 || leftRight == 2))
                {
                    key.outTangent = Mathf.Infinity;
                }

                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);
                // Debug.Log ("Before " + DebKey (key) + " after: " + DebKey (animationCurve[keyToSet.key]));

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }
Exemplo n.º 10
0
        static bool AnimationCurveSupportsProcedural(AnimationCurve curve, ref string failureReason)
        {
            switch (AnimationUtility.IsValidPolynomialCurve(curve))
            {
            case AnimationUtility.PolynomialValid.Valid:
                return(true);

            case AnimationUtility.PolynomialValid.InvalidPreWrapMode:
                failureReason = "Unsupported curve pre-wrap mode. Loop and ping-pong do not support procedural mode.";
                break;

            case AnimationUtility.PolynomialValid.InvalidPostWrapMode:
                failureReason = "Unsupported curve post-wrap mode. Loop and ping-pong do not support procedural mode.";
                break;

            case AnimationUtility.PolynomialValid.TooManySegments:
                failureReason = "Curve uses too many keys. Procedural mode does not support more than " + AnimationUtility.GetMaxNumPolynomialSegmentsSupported() + " keys";
                if (curve.keys[0].time != 0.0f || curve.keys[curve.keys.Length - 1].time != 1.0f)
                {
                    failureReason += " (Additional keys are added to curves that do not start at 0, or do not end at 1)";
                }
                failureReason += ".";
                break;
            }
            return(false);
        }
Exemplo n.º 11
0
        public void OnGUI()
        {
            AnimationEvent[] events = (AnimationEvent[])null;
            if ((UnityEngine.Object) this.m_Clip != (UnityEngine.Object)null)
            {
                events = AnimationUtility.GetAnimationEvents(this.m_Clip);
            }
            else if (this.m_ClipInfo != null)
            {
                events = this.m_ClipInfo.GetEvents();
            }
            if (events == null || this.eventIndex < 0 || this.eventIndex >= events.Length)
            {
                return;
            }
            GUI.changed = false;
            AnimationEvent animationEvent = events[this.eventIndex];

            if ((bool)((UnityEngine.Object) this.m_Root))
            {
                List <string>      supportedMethods;
                List <System.Type> supportedMethodsParameter;
                AnimationEventPopup.CollectSupportedMethods(this.m_Root, out supportedMethods, out supportedMethodsParameter);
                List <string> stringList = new List <string>(supportedMethods.Count);
                for (int index = 0; index < supportedMethods.Count; ++index)
                {
                    string str = " ( )";
                    if (supportedMethodsParameter[index] != null)
                    {
                        str = supportedMethodsParameter[index] != typeof(float) ? (supportedMethodsParameter[index] != typeof(int) ? string.Format(" ( {0} )", (object)supportedMethodsParameter[index].Name) : " ( int )") : " ( float )";
                    }
                    stringList.Add(supportedMethods[index] + str);
                }
                int count         = supportedMethods.Count;
                int selectedIndex = supportedMethods.IndexOf(animationEvent.functionName);
                if (selectedIndex == -1)
                {
                    selectedIndex = supportedMethods.Count;
                    supportedMethods.Add(animationEvent.functionName);
                    if (string.IsNullOrEmpty(animationEvent.functionName))
                    {
                        stringList.Add("(No Function Selected)");
                    }
                    else
                    {
                        stringList.Add(animationEvent.functionName + " (Function Not Supported)");
                    }
                    supportedMethodsParameter.Add((System.Type)null);
                }
                EditorGUIUtility.labelWidth = 130f;
                int num    = selectedIndex;
                int index1 = EditorGUILayout.Popup("Function: ", selectedIndex, stringList.ToArray(), new GUILayoutOption[0]);
                if (num != index1 && index1 != -1 && index1 != count)
                {
                    animationEvent.functionName    = supportedMethods[index1];
                    animationEvent.stringParameter = string.Empty;
                }
                System.Type selectedParameter = supportedMethodsParameter[index1];
                if (selectedParameter != null)
                {
                    EditorGUILayout.Space();
                    if (selectedParameter == typeof(AnimationEvent))
                    {
                        EditorGUILayout.PrefixLabel("Event Data");
                    }
                    else
                    {
                        EditorGUILayout.PrefixLabel("Parameters");
                    }
                    AnimationEventPopup.DoEditRegularParameters(animationEvent, selectedParameter);
                }
            }
            else
            {
                animationEvent.functionName = EditorGUILayout.TextField(new GUIContent("Function"), animationEvent.functionName, new GUILayoutOption[0]);
                AnimationEventPopup.DoEditRegularParameters(animationEvent, typeof(AnimationEvent));
            }
            if (!GUI.changed)
            {
                return;
            }
            if ((UnityEngine.Object) this.m_Clip != (UnityEngine.Object)null)
            {
                Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this.m_Clip, "Animation Event Change");
                AnimationUtility.SetAnimationEvents(this.m_Clip, events);
            }
            else
            {
                if (this.m_ClipInfo == null)
                {
                    return;
                }
                this.m_ClipInfo.SetEvent(this.m_EventIndex, animationEvent);
            }
        }
Exemplo n.º 12
0
 private void Select(AnimationWindowEvent evt)
 {
     this.m_EventsSelected = new bool[AnimationUtility.GetAnimationEvents(evt.clip).Length];
     this.m_EventsSelected[evt.eventIndex] = true;
     Selection.activeObject = evt;
 }
Exemplo n.º 13
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            if (state.selectedItem != null)
            {
                AnimationClip animationClip  = state.selectedItem.animationClip;
                GameObject    rootGameObject = state.selectedItem.rootGameObject;
                GUI.BeginGroup(rect);
                Color color = GUI.color;
                Rect  rect2 = new Rect(0f, 0f, rect.width, rect.height);
                float time  = Mathf.Max((float)(((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate)) / state.frameRate), (float)0f);
                if (animationClip != null)
                {
                    int              num8;
                    float            num9;
                    float            num10;
                    AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(animationClip);
                    Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                    Rect[]           hitPositions    = new Rect[animationEvents.Length];
                    Rect[]           positions       = new Rect[animationEvents.Length];
                    int              num2            = 1;
                    int              num3            = 0;
                    for (int i = 0; i < animationEvents.Length; i++)
                    {
                        AnimationEvent event2 = animationEvents[i];
                        if (num3 == 0)
                        {
                            num2 = 1;
                            while (((i + num2) < animationEvents.Length) && (animationEvents[i + num2].time == event2.time))
                            {
                                num2++;
                            }
                            num3 = num2;
                        }
                        num3--;
                        float num5 = Mathf.Floor(state.FrameToPixel(event2.time * animationClip.frameRate, rect));
                        int   num6 = 0;
                        if (num2 > 1)
                        {
                            float num7 = Mathf.Min((int)((num2 - 1) * (image.width - 1)), (int)(((int)state.FrameDeltaToPixel(rect)) - (image.width * 2)));
                            num6 = Mathf.FloorToInt(Mathf.Max((float)0f, (float)(num7 - ((image.width - 1) * num3))));
                        }
                        Rect rect3 = new Rect((num5 + num6) - (image.width / 2), ((rect.height - 10f) * ((num3 - num2) + 1)) / ((float)Mathf.Max(1, num2 - 1)), (float)image.width, (float)image.height);
                        hitPositions[i] = rect3;
                        positions[i]    = rect3;
                    }
                    if (this.m_DirtyTooltip)
                    {
                        if ((this.m_HoverEvent >= 0) && (this.m_HoverEvent < hitPositions.Length))
                        {
                            this.m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(rootGameObject, animationEvents[this.m_HoverEvent]);
                            this.m_InstantTooltipPoint = new Vector2(((hitPositions[this.m_HoverEvent].xMin + ((int)(hitPositions[this.m_HoverEvent].width / 2f))) + rect.x) - 30f, rect.yMax);
                        }
                        this.m_DirtyTooltip = false;
                    }
                    if ((this.m_EventsSelected == null) || (this.m_EventsSelected.Length != animationEvents.Length))
                    {
                        this.m_EventsSelected = new bool[animationEvents.Length];
                    }
                    Vector2 zero = Vector2.zero;
                    switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), hitPositions, ref this.m_EventsSelected, null, out num8, out zero, out num9, out num10, GUIStyle.none))
                    {
                    case HighLevelEvent.DoubleClick:
                        if (num8 == -1)
                        {
                            this.EventLineContextMenuAdd(new EventLineContextMenuObject(rootGameObject, animationClip, time, -1));
                            break;
                        }
                        Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8);
                        break;

                    case HighLevelEvent.ContextClick:
                    {
                        GenericMenu menu = new GenericMenu();
                        EventLineContextMenuObject userData = new EventLineContextMenuObject(rootGameObject, animationClip, animationEvents[num8].time, num8);
                        menu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData);
                        menu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData);
                        menu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData);
                        menu.ShowAsContext();
                        this.m_InstantTooltipText = null;
                        this.m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }

                    case HighLevelEvent.BeginDrag:
                        this.m_EventsAtMouseDown = animationEvents;
                        this.m_EventTimes        = new float[animationEvents.Length];
                        for (int j = 0; j < animationEvents.Length; j++)
                        {
                            this.m_EventTimes[j] = animationEvents[j].time;
                        }
                        break;

                    case HighLevelEvent.Drag:
                    {
                        for (int k = animationEvents.Length - 1; k >= 0; k--)
                        {
                            if (this.m_EventsSelected[k])
                            {
                                AnimationEvent event6 = this.m_EventsAtMouseDown[k];
                                event6.time = this.m_EventTimes[k] + (zero.x * state.PixelDeltaToTime(rect));
                                event6.time = Mathf.Max(0f, event6.time);
                                event6.time = ((float)Mathf.RoundToInt(event6.time * animationClip.frameRate)) / animationClip.frameRate;
                            }
                        }
                        int[] items = new int[this.m_EventsSelected.Length];
                        for (int m = 0; m < items.Length; m++)
                        {
                            items[m] = m;
                        }
                        Array.Sort(this.m_EventsAtMouseDown, items, new EventComparer());
                        bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                        float[] numArray2 = (float[])this.m_EventTimes.Clone();
                        for (int n = 0; n < items.Length; n++)
                        {
                            this.m_EventsSelected[n] = flagArray[items[n]];
                            this.m_EventTimes[n]     = numArray2[items[n]];
                        }
                        Undo.RegisterCompleteObjectUndo(animationClip, "Move Event");
                        AnimationUtility.SetAnimationEvents(animationClip, this.m_EventsAtMouseDown);
                        this.m_DirtyTooltip = true;
                        break;
                    }

                    case HighLevelEvent.Delete:
                        this.DeleteEvents(animationClip, this.m_EventsSelected);
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        if (num8 != -1)
                        {
                            Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8);
                        }
                        break;
                    }
                    this.CheckRectsOnMouseMove(rect, animationEvents, hitPositions);
                }
                if ((Event.current.type == EventType.ContextClick) && rect2.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    GenericMenu menu2 = new GenericMenu();
                    menu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventLineContextMenuObject(rootGameObject, animationClip, time, -1));
                    menu2.ShowAsContext();
                }
                GUI.color = color;
                GUI.EndGroup();
            }
        }
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            //  We only display and manipulate animation events from the main
            //  game object in selection.  If we ever want to update to handle
            //  a multiple selection, a single timeline might not be sufficient...
            AnimationClip clip     = state.activeAnimationClip;
            GameObject    animated = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color backupCol = GUI.color;

            Rect eventLineRect = new Rect(0, 0, rect.width, rect.height);

            float mousePosTime = Mathf.Max(Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0.0f);

            // Draw events
            if (clip != null)
            {
                AnimationEvent[] events      = AnimationUtility.GetAnimationEvents(clip);
                Texture          eventMarker = EditorGUIUtility.IconContent("Animation.EventMarker").image;

                // Calculate rects
                Rect[] hitRects   = new Rect[events.Length];
                Rect[] drawRects  = new Rect[events.Length];
                int    shared     = 1;
                int    sharedLeft = 0;
                for (int i = 0; i < events.Length; i++)
                {
                    AnimationEvent evt = events[i];

                    if (sharedLeft == 0)
                    {
                        shared = 1;
                        while (i + shared < events.Length && events[i + shared].time == evt.time)
                        {
                            shared++;
                        }
                        sharedLeft = shared;
                    }
                    sharedLeft--;

                    // Important to take floor of positions of GUI stuff to get pixel correct alignment of
                    // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.
                    float keypos       = Mathf.Floor(state.FrameToPixel(evt.time * clip.frameRate, rect));
                    int   sharedOffset = 0;
                    if (shared > 1)
                    {
                        float spread = Mathf.Min((shared - 1) * (k_EventMarkerSize.x - 1), (int)(state.FrameDeltaToPixel(rect) - k_EventMarkerSize.x * 2));
                        sharedOffset = Mathf.FloorToInt(Mathf.Max(0, spread - (k_EventMarkerSize.x - 1) * (sharedLeft)));
                    }

                    Rect r = new Rect(
                        keypos + sharedOffset - k_EventMarkerSize.x / 2,
                        (rect.height - 10) * (float)(sharedLeft - shared + 1) / Mathf.Max(1, shared - 1),
                        k_EventMarkerSize.x,
                        k_EventMarkerSize.y);

                    hitRects[i]  = r;
                    drawRects[i] = r;
                }

                // Store tooptip info
                if (m_DirtyTooltip)
                {
                    if (m_HoverEvent >= 0 && m_HoverEvent < hitRects.Length)
                    {
                        m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(animated, events[m_HoverEvent]);
                        m_InstantTooltipPoint = new Vector2(hitRects[m_HoverEvent].xMin + (int)(hitRects[m_HoverEvent].width / 2) + rect.x - 30, rect.yMax);
                    }
                    m_DirtyTooltip = false;
                }

                bool[] selectedEvents = new bool[events.Length];
                m_HasSelectedEvents = false;

                Object[] selectedObjects = Selection.objects;
                foreach (Object selectedObject in selectedObjects)
                {
                    AnimationWindowEvent awe = selectedObject as AnimationWindowEvent;
                    if (awe != null)
                    {
                        if (awe.eventIndex >= 0 && awe.eventIndex < selectedEvents.Length)
                        {
                            selectedEvents[awe.eventIndex] = true;
                            m_HasSelectedEvents            = true;
                        }
                    }
                }

                Vector2 offset = Vector2.zero;
                int     clickedIndex;
                float   startSelection, endSelection;

                // TODO: GUIStyle.none has hopping margins that need to be fixed
                HighLevelEvent hEvent = EditorGUIExt.MultiSelection(
                    rect,
                    drawRects,
                    new GUIContent(eventMarker),
                    hitRects,
                    ref selectedEvents,
                    null,
                    out clickedIndex,
                    out offset,
                    out startSelection,
                    out endSelection,
                    GUIStyle.none
                    );

                if (hEvent != HighLevelEvent.None)
                {
                    switch (hEvent)
                    {
                    case HighLevelEvent.BeginDrag:
                        m_EventsAtMouseDown = events;
                        m_EventTimes        = new float[events.Length];
                        for (int i = 0; i < events.Length; i++)
                        {
                            m_EventTimes[i] = events[i].time;
                        }
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        EditEvents(animated, clip, selectedEvents);
                        break;

                    case HighLevelEvent.Delete:
                        DeleteEvents(clip, selectedEvents);
                        break;

                    case HighLevelEvent.Copy:
                        CopyEvents(clip, selectedEvents);
                        break;

                    case HighLevelEvent.Paste:
                        PasteEvents(animated, clip, state.currentTime);
                        break;

                    case HighLevelEvent.DoubleClick:

                        if (clickedIndex != -1)
                        {
                            EditEvents(animated, clip, selectedEvents);
                        }
                        else
                        {
                            EventLineContextMenuAdd(new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents));
                        }
                        break;

                    case HighLevelEvent.Drag:
                        for (int i = events.Length - 1; i >= 0; i--)
                        {
                            if (selectedEvents[i])
                            {
                                AnimationEvent evt = m_EventsAtMouseDown[i];
                                evt.time = m_EventTimes[i] + offset.x * state.PixelDeltaToTime(rect);
                                evt.time = Mathf.Max(0.0F, evt.time);
                                evt.time = Mathf.RoundToInt(evt.time * clip.frameRate) / clip.frameRate;
                            }
                        }
                        int[] order = new int[selectedEvents.Length];
                        for (int i = 0; i < order.Length; i++)
                        {
                            order[i] = i;
                        }
                        System.Array.Sort(m_EventsAtMouseDown, order, new EventComparer());
                        bool[]  selectedOld = (bool[])selectedEvents.Clone();
                        float[] timesOld    = (float[])m_EventTimes.Clone();
                        for (int i = 0; i < order.Length; i++)
                        {
                            selectedEvents[i] = selectedOld[order[i]];
                            m_EventTimes[i]   = timesOld[order[i]];
                        }

                        // Update selection to reflect new order.
                        EditEvents(animated, clip, selectedEvents);

                        Undo.RegisterCompleteObjectUndo(clip, "Move Event");
                        AnimationUtility.SetAnimationEvents(clip, m_EventsAtMouseDown);
                        m_DirtyTooltip = true;
                        break;

                    case HighLevelEvent.ContextClick:
                        CreateContextMenu(animated, clip, events[clickedIndex].time, clickedIndex, selectedEvents);

                        // Mouse may move while context menu is open - make sure instant tooltip is handled
                        m_InstantTooltipText = null;
                        m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }
                }

                CheckRectsOnMouseMove(rect, events, hitRects);

                // Bring up menu when context-clicking on an empty timeline area (context-clicking on events is handled above)
                if (Event.current.type == EventType.ContextClick && eventLineRect.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    CreateContextMenu(animated, clip, mousePosTime, -1, selectedEvents);
                }
            }

            GUI.color = backupCol;
            GUI.EndGroup();
        }
Exemplo n.º 15
0
        public void UpdateTangentsFromMode(int index, int componentIndex)
        {
            AnimationCurve curve = GetCurve(componentIndex);

            if (index < 0 || index >= curve.length)
            {
                return;
            }

            Keyframe key = curve[index];

            // Adjust linear tangent
            if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.Linear && index >= 1)
            {
                key.inTangent = CalculateLinearTangent(index, index - 1, componentIndex);
                curve.MoveKey(index, key);
            }
            if (AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.Linear && index + 1 < curve.length)
            {
                key.outTangent = CalculateLinearTangent(index, index + 1, componentIndex);
                curve.MoveKey(index, key);
            }

            // Adjust smooth tangents
            if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.ClampedAuto)
            {
                key.inTangent = key.outTangent = CalculateSmoothTangent(index, componentIndex);
                curve.MoveKey(index, key);
            }
        }
        public void AddTangentMenuItems(GenericMenu menu, List <KeyIdentifier> keyList)
        {
            bool anyKeys = (keyList.Count > 0);
            // Find out which qualities apply to all the keys
            bool allClampedAuto   = anyKeys;
            bool allAuto          = anyKeys;
            bool allFreeSmooth    = anyKeys;
            bool allFlat          = anyKeys;
            bool allBroken        = anyKeys;
            bool allLeftWeighted  = anyKeys;
            bool allLeftFree      = anyKeys;
            bool allLeftLinear    = anyKeys;
            bool allLeftConstant  = anyKeys;
            bool allRightWeighted = anyKeys;
            bool allRightFree     = anyKeys;
            bool allRightLinear   = anyKeys;
            bool allRightConstant = anyKeys;

            foreach (KeyIdentifier sel in keyList)
            {
                Keyframe    key       = sel.keyframe;
                TangentMode leftMode  = AnimationUtility.GetKeyLeftTangentMode(key);
                TangentMode rightMode = AnimationUtility.GetKeyRightTangentMode(key);
                bool        broken    = AnimationUtility.GetKeyBroken(key);
                if (leftMode != TangentMode.ClampedAuto || rightMode != TangentMode.ClampedAuto)
                {
                    allClampedAuto = false;
                }
                if (leftMode != TangentMode.Auto || rightMode != TangentMode.Auto)
                {
                    allAuto = false;
                }
                if (broken || leftMode != TangentMode.Free || rightMode != TangentMode.Free)
                {
                    allFreeSmooth = false;
                }
                if (broken || leftMode != TangentMode.Free || key.inTangent != 0 || rightMode != TangentMode.Free || key.outTangent != 0)
                {
                    allFlat = false;
                }
                if (!broken)
                {
                    allBroken = false;
                }
                if (!broken || leftMode != TangentMode.Free)
                {
                    allLeftFree = false;
                }
                if (!broken || leftMode != TangentMode.Linear)
                {
                    allLeftLinear = false;
                }
                if (!broken || leftMode != TangentMode.Constant)
                {
                    allLeftConstant = false;
                }
                if (!broken || rightMode != TangentMode.Free)
                {
                    allRightFree = false;
                }
                if (!broken || rightMode != TangentMode.Linear)
                {
                    allRightLinear = false;
                }
                if (!broken || rightMode != TangentMode.Constant)
                {
                    allRightConstant = false;
                }


                if ((key.weightedMode & WeightedMode.In) == WeightedMode.None)
                {
                    allLeftWeighted = false;
                }
                if ((key.weightedMode & WeightedMode.Out) == WeightedMode.None)
                {
                    allRightWeighted = false;
                }
            }
            if (anyKeys)
            {
                menu.AddItem(EditorGUIUtility.TrTextContent("Clamped Auto"), allClampedAuto, SetClampedAuto, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Auto"), allAuto, SetAuto, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Free Smooth"), allFreeSmooth, SetEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Flat"), allFlat, SetFlat, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Broken"), allBroken, SetBroken, keyList);
                menu.AddSeparator("");
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Free"), allLeftFree, SetLeftEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Linear"), allLeftLinear, SetLeftLinear, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Constant"), allLeftConstant, SetLeftConstant, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Weighted"), allLeftWeighted, ToggleLeftWeighted, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Free"), allRightFree, SetRightEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Linear"), allRightLinear, SetRightLinear, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Constant"), allRightConstant, SetRightConstant, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Weighted"), allRightWeighted, ToggleRightWeighted, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Free"), allRightFree && allLeftFree, SetBothEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Linear"), allRightLinear && allLeftLinear, SetBothLinear, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Constant"), allRightConstant && allLeftConstant, SetBothConstant, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Weighted"), allRightWeighted && allLeftWeighted, ToggleBothWeighted, keyList);
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Weighted"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Auto"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Free Smooth"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Flat"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Broken"));
                menu.AddSeparator("");
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Weighted"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Weighted"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Weighted"));
            }
        }
        void CopyEvents(AnimationClip clip, bool[] selected, int explicitIndex = -1)
        {
            var allEvents = new List <AnimationEvent>(AnimationUtility.GetAnimationEvents(clip));

            AnimationWindowEventsClipboard.CopyEvents(allEvents, selected, explicitIndex);
        }
Exemplo n.º 18
0
 public static ObjectReferenceKeyframe[] GetObjectReferenceCurve(AnimationClip clip, EditorCurveBinding binding)
 {
     return(AnimationUtility.INTERNAL_CALL_GetObjectReferenceCurve(clip, ref binding));
 }
Exemplo n.º 19
0
 public static AnimationCurve GetEditorCurve(AnimationClip clip, string relativePath, Type type, string propertyName)
 {
     return(AnimationUtility.GetEditorCurve(clip, EditorCurveBinding.FloatCurve(relativePath, type, propertyName)));
 }
Exemplo n.º 20
0
 private static void Internal_SetObjectReferenceCurve(AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes)
 {
     AnimationUtility.INTERNAL_CALL_Internal_SetObjectReferenceCurve(clip, ref binding, keyframes);
 }
Exemplo n.º 21
0
 public static Type GetEditorCurveValueType(GameObject root, EditorCurveBinding binding)
 {
     return(AnimationUtility.INTERNAL_CALL_GetEditorCurveValueType(root, ref binding));
 }
Exemplo n.º 22
0
 public static AnimationCurve GetEditorCurve(AnimationClip clip, EditorCurveBinding binding)
 {
     return(AnimationUtility.INTERNAL_CALL_GetEditorCurve(clip, ref binding));
 }
Exemplo n.º 23
0
 public static bool GetObjectReferenceValue(GameObject root, EditorCurveBinding binding, out UnityEngine.Object targetObject)
 {
     return(AnimationUtility.INTERNAL_CALL_GetObjectReferenceValue(root, ref binding, out targetObject));
 }
Exemplo n.º 24
0
 private static void Internal_SetEditorCurve(AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve)
 {
     AnimationUtility.INTERNAL_CALL_Internal_SetEditorCurve(clip, ref binding, curve);
 }
Exemplo n.º 25
0
 public void SetBoth(AnimationUtility.TangentMode mode, List<KeyIdentifier> keysToSet)
 {
     List<ChangedCurve> list = new List<ChangedCurve>();
     foreach (KeyIdentifier identifier in keysToSet)
     {
         AnimationCurve curve = identifier.curve;
         Keyframe key = identifier.keyframe;
         AnimationUtility.SetKeyBroken(ref key, false);
         AnimationUtility.SetKeyRightTangentMode(ref key, mode);
         AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
         if (mode == AnimationUtility.TangentMode.Free)
         {
             float num = CurveUtility.CalculateSmoothTangent(key);
             key.inTangent = num;
             key.outTangent = num;
         }
         curve.MoveKey(identifier.key, key);
         AnimationUtility.UpdateTangentsFromModeSurrounding(curve, identifier.key);
         ChangedCurve item = new ChangedCurve(curve, identifier.curveId, identifier.binding);
         if (!list.Contains(item))
         {
             list.Add(item);
         }
     }
     this.updater.UpdateCurves(list, "Set Tangents");
 }
Exemplo n.º 26
0
 private static void Internal_UpdateTangents(AnimationCurve curve, int index)
 {
     if (index >= 0 && index < curve.length)
     {
         Keyframe key = curve[index];
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Linear && index >= 1)
         {
             key.inTangent = AnimationUtility.Internal_CalculateLinearTangent(curve, index, index - 1);
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Linear && index + 1 < curve.length)
         {
             key.outTangent = AnimationUtility.Internal_CalculateLinearTangent(curve, index, index + 1);
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto)
         {
             AnimationUtility.Internal_CalculateAutoTangent(curve, index);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Auto || AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Auto)
         {
             curve.SmoothTangents(index, 0f);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Free && AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Free && !AnimationUtility.GetKeyBroken(key))
         {
             key.outTangent = key.inTangent;
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Constant)
         {
             key.inTangent = float.PositiveInfinity;
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Constant)
         {
             key.outTangent = float.PositiveInfinity;
             curve.MoveKey(index, key);
         }
     }
 }
Exemplo n.º 27
0
        internal static void SetInterpolation(AnimationClip clip, EditorCurveBinding[] curveBindings, Mode newInterpolationMode)
        {
            Undo.RegisterCompleteObjectUndo(clip, "Rotation Interpolation");

            if (clip.legacy && newInterpolationMode == Mode.RawEuler)
            {
                Debug.LogWarning("Warning, Euler Angles interpolation mode is not fully supported for Legacy animation clips. If you mix clips using Euler Angles interpolation with clips using other interpolation modes (using Animation.CrossFade, Animation.Blend or other methods), you will get erroneous results. Use with caution.", clip);
            }
            List <EditorCurveBinding> newCurvesBindings = new List <EditorCurveBinding>();
            List <AnimationCurve>     newCurveDatas     = new List <AnimationCurve>();
            List <EditorCurveBinding> oldCurvesBindings = new List <EditorCurveBinding>();

            foreach (EditorCurveBinding curveBinding in curveBindings)
            {
                Mode currentMode = GetModeFromCurveData(curveBinding);

                if (currentMode == Mode.Undefined)
                {
                    continue;
                }

                if (currentMode == Mode.RawQuaternions)
                {
                    Debug.LogWarning("Can't convert quaternion curve: " + curveBinding.propertyName);
                    continue;
                }

                AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, curveBinding);

                if (curve == null)
                {
                    continue;
                }

                string newPropertyPath = GetPrefixForInterpolation(newInterpolationMode) + '.' + ExtractComponentCharacter(curveBinding.propertyName);

                EditorCurveBinding newBinding = new EditorCurveBinding();
                newBinding.propertyName = newPropertyPath;
                newBinding.type         = curveBinding.type;
                newBinding.path         = curveBinding.path;
                newCurvesBindings.Add(newBinding);
                newCurveDatas.Add(curve);

                EditorCurveBinding removeCurve = new EditorCurveBinding();
                removeCurve.propertyName = curveBinding.propertyName;
                removeCurve.type         = curveBinding.type;
                removeCurve.path         = curveBinding.path;
                oldCurvesBindings.Add(removeCurve);
            }

            Undo.RegisterCompleteObjectUndo(clip, "Rotation Interpolation");

            foreach (EditorCurveBinding binding in oldCurvesBindings)
            {
                AnimationUtility.SetEditorCurve(clip, binding, null);
            }

            foreach (EditorCurveBinding binding in newCurvesBindings)
            {
                AnimationUtility.SetEditorCurve(clip, binding, newCurveDatas[newCurvesBindings.IndexOf(binding)]);
            }
        }
Exemplo n.º 28
0
        public static AnimationClipCurveData[] GetAllCurves(AnimationClip clip)
        {
            bool includeCurveData = true;

            return(AnimationUtility.GetAllCurves(clip, includeCurveData));
        }
		private void CurveWasModified(AnimationClip clip, EditorCurveBinding binding, AnimationUtility.CurveModifiedType type)
		{
			if (clip != this.m_ActiveAnimationClip)
			{
				return;
			}
			if (type == AnimationUtility.CurveModifiedType.CurveModified)
			{
				bool flag = false;
				int hashCode = binding.GetHashCode();
				foreach (AnimationWindowCurve current in this.allCurves)
				{
					int hashCode2 = current.binding.GetHashCode();
					if (hashCode2 == hashCode)
					{
						this.m_ModifiedCurves.Add(hashCode2);
						flag = true;
					}
				}
				if (flag)
				{
					this.refresh = AnimationWindowState.RefreshType.CurvesOnly;
				}
				else
				{
					this.m_lastAddedCurveBinding = new EditorCurveBinding?(binding);
					this.refresh = AnimationWindowState.RefreshType.Everything;
				}
			}
			else
			{
				this.refresh = AnimationWindowState.RefreshType.Everything;
			}
		}
Exemplo n.º 30
0
 public static bool GetFloatValue(GameObject root, string relativePath, Type type, string propertyName, out float data)
 {
     return(AnimationUtility.GetFloatValue(root, EditorCurveBinding.FloatCurve(relativePath, type, propertyName), out data));
 }
Exemplo n.º 31
0
 public static string GetPath(Transform t)
 {
     return(AnimationUtility.CalculateTransformPath(t, t.root));
 }
Exemplo n.º 32
0
 public static void SetEditorCurve(AnimationClip clip, string relativePath, Type type, string propertyName, AnimationCurve curve)
 {
     AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(relativePath, type, propertyName), curve);
 }
Exemplo n.º 33
0
        // Move me to CurveEditor.cs
        public static void SetKeyModeFromContext(AnimationCurve curve, int keyIndex)
        {
            Keyframe key           = curve[keyIndex];
            bool     broken        = false;
            bool     smoothTangent = false;

            if (keyIndex > 0)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex - 1]))
                {
                    broken = true;
                }
                TangentMode prevTangentMode = AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]);
                if (prevTangentMode == TangentMode.ClampedAuto || prevTangentMode == TangentMode.Auto)
                {
                    smoothTangent = true;
                }
            }
            if (keyIndex < curve.length - 1)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex + 1]))
                {
                    broken = true;
                }
                TangentMode nextTangentMode = AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]);
                if (nextTangentMode == TangentMode.ClampedAuto || nextTangentMode == TangentMode.Auto)
                {
                    smoothTangent = true;
                }
            }

            AnimationUtility.SetKeyBroken(ref key, broken);

            if (broken && !smoothTangent)
            {
                if (keyIndex > 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]));
                }
                if (keyIndex < curve.length - 1)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]));
                }

                // Keys at boundaries.  Make sure left and right tangent modes are the same.
                if (keyIndex == 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.GetKeyRightTangentMode(key));
                }
                if (keyIndex == curve.length - 1)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.GetKeyLeftTangentMode(key));
                }
            }
            else
            {
                // If both neighbors or only neighbor are set to TangentMode.Auto or TangentMode.ClampedAuto, set new key to this mode as well.
                // If there are no neighbors, set new key to TangentMode.ClampedAuto.
                // Otherwise, fall back to TangentMode.Free.
                TangentMode mode = TangentMode.Free;
                if ((keyIndex == 0 || AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == TangentMode.ClampedAuto) &&
                    (keyIndex == curve.length - 1 || AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == TangentMode.ClampedAuto))
                {
                    mode = TangentMode.ClampedAuto;
                }
                else if ((keyIndex == 0 || AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == TangentMode.Auto) &&
                         (keyIndex == curve.length - 1 || AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == TangentMode.Auto))
                {
                    mode = TangentMode.Auto;
                }

                AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
                AnimationUtility.SetKeyRightTangentMode(ref key, mode);
            }

            curve.MoveKey(keyIndex, key);
        }
 private void CurveWasModified(AnimationClip clip, EditorCurveBinding binding, AnimationUtility.CurveModifiedType type)
 {
   if ((UnityEngine.Object) clip != (UnityEngine.Object) this.activeAnimationClip)
     return;
   if (type == AnimationUtility.CurveModifiedType.CurveModified)
   {
     bool flag = false;
     int hashCode1 = binding.GetHashCode();
     using (List<AnimationWindowCurve>.Enumerator enumerator = this.allCurves.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         int hashCode2 = enumerator.Current.binding.GetHashCode();
         if (hashCode2 == hashCode1)
         {
           this.m_ModifiedCurves.Add(hashCode2);
           flag = true;
         }
       }
     }
     if (flag)
     {
       this.refresh = AnimationWindowState.RefreshType.CurvesOnly;
     }
     else
     {
       this.m_lastAddedCurveBinding = new EditorCurveBinding?(binding);
       this.refresh = AnimationWindowState.RefreshType.Everything;
     }
   }
   else
     this.refresh = AnimationWindowState.RefreshType.Everything;
 }