Пример #1
0
 public static RotationCurveInterpolation.State GetCurveState(AnimationClip clip, EditorCurveBinding[] selection)
 {
     RotationCurveInterpolation.State result;
     result.allAreNonBaked  = true;
     result.allAreBaked     = false;
     result.allAreRotations = false;
     for (int i = 0; i < selection.Length; i++)
     {
         EditorCurveBinding data = selection[i];
         RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(data);
         if (modeFromCurveData == RotationCurveInterpolation.Mode.NonBaked)
         {
             result.allAreNonBaked = false;
         }
         else
         {
             if (modeFromCurveData == RotationCurveInterpolation.Mode.Baked)
             {
                 result.allAreBaked = false;
             }
             else
             {
                 result.allAreRotations = false;
             }
         }
     }
     return(result);
 }
        public static string GetPrefixForInterpolation(RotationCurveInterpolation.Mode newInterpolationMode)
        {
            string result;

            if (newInterpolationMode == RotationCurveInterpolation.Mode.Baked)
            {
                result = "localEulerAnglesBaked";
            }
            else if (newInterpolationMode == RotationCurveInterpolation.Mode.NonBaked)
            {
                result = "localEulerAngles";
            }
            else if (newInterpolationMode == RotationCurveInterpolation.Mode.RawEuler)
            {
                result = "localEulerAnglesRaw";
            }
            else if (newInterpolationMode == RotationCurveInterpolation.Mode.RawQuaternions)
            {
                result = "m_LocalRotation";
            }
            else
            {
                result = null;
            }
            return(result);
        }
        public static EditorCurveBinding RemapAnimationBindingForRotationCurves(EditorCurveBinding curveBinding, AnimationClip clip)
        {
            EditorCurveBinding result;

            if (!AnimationWindowUtility.IsTransformType(curveBinding.type))
            {
                result = curveBinding;
            }
            else
            {
                RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(curveBinding);
                if (modeFromCurveData != RotationCurveInterpolation.Mode.Undefined)
                {
                    string str = curveBinding.propertyName.Split(new char[]
                    {
                        '.'
                    })[1];
                    EditorCurveBinding editorCurveBinding = curveBinding;
                    if (modeFromCurveData != RotationCurveInterpolation.Mode.NonBaked)
                    {
                        editorCurveBinding.propertyName = RotationCurveInterpolation.GetPrefixForInterpolation(RotationCurveInterpolation.Mode.NonBaked) + "." + str;
                        AnimationCurve editorCurve = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);
                        if (editorCurve != null)
                        {
                            result = editorCurveBinding;
                            return(result);
                        }
                    }
                    if (modeFromCurveData != RotationCurveInterpolation.Mode.Baked)
                    {
                        editorCurveBinding.propertyName = RotationCurveInterpolation.GetPrefixForInterpolation(RotationCurveInterpolation.Mode.Baked) + "." + str;
                        AnimationCurve editorCurve2 = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);
                        if (editorCurve2 != null)
                        {
                            result = editorCurveBinding;
                            return(result);
                        }
                    }
                    if (modeFromCurveData != RotationCurveInterpolation.Mode.RawEuler)
                    {
                        editorCurveBinding.propertyName = RotationCurveInterpolation.GetPrefixForInterpolation(RotationCurveInterpolation.Mode.RawEuler) + "." + str;
                        AnimationCurve editorCurve3 = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);
                        if (editorCurve3 != null)
                        {
                            result = editorCurveBinding;
                            return(result);
                        }
                    }
                    result = curveBinding;
                }
                else
                {
                    result = curveBinding;
                }
            }
            return(result);
        }
        internal static void SetInterpolation(AnimationClip clip, EditorCurveBinding[] curveBindings, RotationCurveInterpolation.Mode newInterpolationMode)
        {
            Undo.RegisterCompleteObjectUndo(clip, "Rotation Interpolation");
            if (clip.legacy && newInterpolationMode == RotationCurveInterpolation.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> list  = new List <EditorCurveBinding>();
            List <AnimationCurve>     list2 = new List <AnimationCurve>();
            List <EditorCurveBinding> list3 = new List <EditorCurveBinding>();

            for (int i = 0; i < curveBindings.Length; i++)
            {
                EditorCurveBinding editorCurveBinding             = curveBindings[i];
                RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(editorCurveBinding);
                if (modeFromCurveData != RotationCurveInterpolation.Mode.Undefined)
                {
                    if (modeFromCurveData == RotationCurveInterpolation.Mode.RawQuaternions)
                    {
                        Debug.LogWarning("Can't convert quaternion curve: " + editorCurveBinding.propertyName);
                    }
                    else
                    {
                        AnimationCurve editorCurve = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);
                        if (editorCurve != null)
                        {
                            string propertyName = RotationCurveInterpolation.GetPrefixForInterpolation(newInterpolationMode) + '.' + RotationCurveInterpolation.ExtractComponentCharacter(editorCurveBinding.propertyName);
                            list.Add(new EditorCurveBinding
                            {
                                propertyName = propertyName,
                                type         = editorCurveBinding.type,
                                path         = editorCurveBinding.path
                            });
                            list2.Add(editorCurve);
                            list3.Add(new EditorCurveBinding
                            {
                                propertyName = editorCurveBinding.propertyName,
                                type         = editorCurveBinding.type,
                                path         = editorCurveBinding.path
                            });
                        }
                    }
                }
            }
            Undo.RegisterCompleteObjectUndo(clip, "Rotation Interpolation");
            foreach (EditorCurveBinding current in list3)
            {
                AnimationUtility.SetEditorCurve(clip, current, null);
            }
            foreach (EditorCurveBinding current2 in list)
            {
                AnimationUtility.SetEditorCurve(clip, current2, list2[list.IndexOf(current2)]);
            }
        }
Пример #5
0
 private void ChangeRotationInterpolation(object interpolationMode)
 {
     RotationCurveInterpolation.Mode mode          = (RotationCurveInterpolation.Mode)interpolationMode;
     AnimationWindowCurve[]          array         = this.state.activeCurves.ToArray();
     EditorCurveBinding[]            curveBindings = new EditorCurveBinding[array.Length];
     for (int index = 0; index < array.Length; ++index)
     {
         curveBindings[index] = array[index].binding;
     }
     RotationCurveInterpolation.SetInterpolation(this.state.activeAnimationClip, curveBindings, mode);
     this.MaintainTreeviewStateAfterRotationInterpolation(mode);
     this.state.hierarchyData.ReloadData();
 }
Пример #6
0
 private void ChangeRotationInterpolation(object interpolationMode)
 {
     RotationCurveInterpolation.Mode mode   = (RotationCurveInterpolation.Mode)((int)interpolationMode);
     AnimationWindowCurve[]          array  = this.state.activeCurves.ToArray();
     EditorCurveBinding[]            array2 = new EditorCurveBinding[array.Length];
     for (int i = 0; i < array.Length; i++)
     {
         array2[i] = array[i].binding;
     }
     RotationCurveInterpolation.SetInterpolation(this.state.activeAnimationClip, array2, mode);
     this.MaintainTreeviewStateAfterRotationInterpolation(mode);
     this.state.hierarchyData.ReloadData();
 }
Пример #7
0
        internal static void SetInterpolation(AnimationClip clip, EditorCurveBinding[] curveBindings, RotationCurveInterpolation.Mode newInterpolationMode)
        {
            Undo.RegisterCompleteObjectUndo(clip, "Rotation Interpolation");
            List <EditorCurveBinding> list  = new List <EditorCurveBinding>();
            List <AnimationCurve>     list2 = new List <AnimationCurve>();
            List <EditorCurveBinding> list3 = new List <EditorCurveBinding>();

            for (int i = 0; i < curveBindings.Length; i++)
            {
                EditorCurveBinding editorCurveBinding             = curveBindings[i];
                RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(editorCurveBinding);
                if (modeFromCurveData != RotationCurveInterpolation.Mode.Undefined)
                {
                    if (modeFromCurveData == RotationCurveInterpolation.Mode.RawQuaternions)
                    {
                        Debug.LogWarning("Can't convert quaternion curve: " + editorCurveBinding.propertyName);
                    }
                    else
                    {
                        AnimationCurve editorCurve = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);
                        if (editorCurve != null)
                        {
                            string propertyName = RotationCurveInterpolation.GetPrefixForInterpolation(newInterpolationMode) + '.' + RotationCurveInterpolation.ExtractComponentCharacter(editorCurveBinding.propertyName);
                            list.Add(new EditorCurveBinding
                            {
                                propertyName = propertyName,
                                type         = editorCurveBinding.type,
                                path         = editorCurveBinding.path
                            });
                            list2.Add(editorCurve);
                            list3.Add(new EditorCurveBinding
                            {
                                propertyName = editorCurveBinding.propertyName,
                                type         = editorCurveBinding.type,
                                path         = editorCurveBinding.path
                            });
                        }
                    }
                }
            }
            Undo.RegisterCompleteObjectUndo(clip, "Rotation Interpolation");
            foreach (EditorCurveBinding current in list3)
            {
                AnimationUtility.SetEditorCurve(clip, current, null);
            }
            foreach (EditorCurveBinding current2 in list)
            {
                AnimationUtility.SetEditorCurve(clip, current2, list2[list.IndexOf(current2)]);
            }
        }
        private void ChangeRotationInterpolation(System.Object interpolationMode)
        {
            RotationCurveInterpolation.Mode mode = (RotationCurveInterpolation.Mode)interpolationMode;

            AnimationWindowCurve[] activeCurves  = state.activeCurves.ToArray();
            EditorCurveBinding[]   curveBindings = new EditorCurveBinding[activeCurves.Length];

            for (int i = 0; i < activeCurves.Length; i++)
            {
                curveBindings[i] = activeCurves[i].binding;
            }

            RotationCurveInterpolation.SetInterpolation(state.activeAnimationClip, curveBindings, mode);
            MaintainTreeviewStateAfterRotationInterpolation(mode);
            state.hierarchyData.ReloadData();
        }
Пример #9
0
 public static string GetPrefixForInterpolation(RotationCurveInterpolation.Mode newInterpolationMode)
 {
     if (newInterpolationMode == RotationCurveInterpolation.Mode.Baked)
     {
         return("localEulerAnglesBaked");
     }
     if (newInterpolationMode == RotationCurveInterpolation.Mode.NonBaked)
     {
         return("localEulerAngles");
     }
     if (newInterpolationMode == RotationCurveInterpolation.Mode.RawQuaternions)
     {
         return("m_LocalRotation");
     }
     return(null);
 }
Пример #10
0
 private RotationCurveInterpolation.Mode GetRotationInterpolationMode(EditorCurveBinding[] curves)
 {
     if (curves == null || curves.Length == 0)
     {
         return(RotationCurveInterpolation.Mode.Undefined);
     }
     RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(curves[0]);
     for (int i = 1; i < curves.Length; i++)
     {
         RotationCurveInterpolation.Mode modeFromCurveData2 = RotationCurveInterpolation.GetModeFromCurveData(curves[i]);
         if (modeFromCurveData != modeFromCurveData2)
         {
             return(RotationCurveInterpolation.Mode.Undefined);
         }
     }
     return(modeFromCurveData);
 }
Пример #11
0
 public static RotationCurveInterpolation.State GetCurveState(AnimationClip clip, EditorCurveBinding[] selection)
 {
     RotationCurveInterpolation.State state;
     state.allAreRaw       = true;
     state.allAreNonBaked  = true;
     state.allAreBaked     = true;
     state.allAreRotations = true;
     foreach (EditorCurveBinding data in selection)
     {
         RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(data);
         state.allAreBaked     &= modeFromCurveData == RotationCurveInterpolation.Mode.Baked;
         state.allAreNonBaked  &= modeFromCurveData == RotationCurveInterpolation.Mode.NonBaked;
         state.allAreRaw       &= modeFromCurveData == RotationCurveInterpolation.Mode.RawEuler;
         state.allAreRotations &= modeFromCurveData != RotationCurveInterpolation.Mode.Undefined;
     }
     return(state);
 }
        // Changing rotation interpolation will change the propertynames of the curves
        // Propertynames are used in treeview node IDs, so we need to anticipate the new IDs by injecting them into treeview state
        // This way treeview state (selection and expanding) will be preserved once the curve data is eventually reloaded
        private void MaintainTreeviewStateAfterRotationInterpolation(RotationCurveInterpolation.Mode newMode)
        {
            List <int> selectedInstaceIDs = state.hierarchyState.selectedIDs;
            List <int> expandedInstaceIDs = state.hierarchyState.expandedIDs;

            List <int> oldIDs = new List <int>();
            List <int> newIds = new List <int>();

            for (int i = 0; i < selectedInstaceIDs.Count; i++)
            {
                AnimationWindowHierarchyNode node = state.hierarchyData.FindItem(selectedInstaceIDs[i]) as AnimationWindowHierarchyNode;

                if (node != null && !node.propertyName.Equals(RotationCurveInterpolation.GetPrefixForInterpolation(newMode)))
                {
                    string oldPrefix       = node.propertyName.Split('.')[0];
                    string newPropertyName = node.propertyName.Replace(oldPrefix, RotationCurveInterpolation.GetPrefixForInterpolation(newMode));

                    // old treeview node id
                    oldIDs.Add(selectedInstaceIDs[i]);
                    // and its new replacement
                    newIds.Add((node.path + node.animatableObjectType.Name + newPropertyName).GetHashCode());
                }
            }

            // Replace old IDs with new ones
            for (int i = 0; i < oldIDs.Count; i++)
            {
                if (selectedInstaceIDs.Contains(oldIDs[i]))
                {
                    int index = selectedInstaceIDs.IndexOf(oldIDs[i]);
                    selectedInstaceIDs[index] = newIds[i];
                }
                if (expandedInstaceIDs.Contains(oldIDs[i]))
                {
                    int index = expandedInstaceIDs.IndexOf(oldIDs[i]);
                    expandedInstaceIDs[index] = newIds[i];
                }
                if (state.hierarchyState.lastClickedID == oldIDs[i])
                {
                    state.hierarchyState.lastClickedID = newIds[i];
                }
            }

            state.hierarchyState.selectedIDs = new List <int>(selectedInstaceIDs);
            state.hierarchyState.expandedIDs = new List <int>(expandedInstaceIDs);
        }
 public static RotationCurveInterpolation.State GetCurveState(AnimationClip clip, EditorCurveBinding[] selection)
 {
     RotationCurveInterpolation.State result;
     result.allAreRaw       = true;
     result.allAreNonBaked  = true;
     result.allAreBaked     = true;
     result.allAreRotations = true;
     for (int i = 0; i < selection.Length; i++)
     {
         EditorCurveBinding data = selection[i];
         RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(data);
         result.allAreBaked     &= (modeFromCurveData == RotationCurveInterpolation.Mode.Baked);
         result.allAreNonBaked  &= (modeFromCurveData == RotationCurveInterpolation.Mode.NonBaked);
         result.allAreRaw       &= (modeFromCurveData == RotationCurveInterpolation.Mode.RawEuler);
         result.allAreRotations &= (modeFromCurveData != RotationCurveInterpolation.Mode.Undefined);
     }
     return(result);
 }
Пример #14
0
        private void MaintainTreeviewStateAfterRotationInterpolation(RotationCurveInterpolation.Mode newMode)
        {
            List <int> selectedIDs = this.state.hierarchyState.selectedIDs;
            List <int> expandedIDs = this.state.hierarchyState.expandedIDs;
            List <int> list        = new List <int>();
            List <int> list2       = new List <int>();

            for (int i = 0; i < selectedIDs.Count; i++)
            {
                AnimationWindowHierarchyNode animationWindowHierarchyNode = this.state.hierarchyData.FindItem(selectedIDs[i]) as AnimationWindowHierarchyNode;
                if (animationWindowHierarchyNode != null && !animationWindowHierarchyNode.propertyName.Equals(RotationCurveInterpolation.GetPrefixForInterpolation(newMode)))
                {
                    string oldValue = animationWindowHierarchyNode.propertyName.Split(new char[]
                    {
                        '.'
                    })[0];
                    string str = animationWindowHierarchyNode.propertyName.Replace(oldValue, RotationCurveInterpolation.GetPrefixForInterpolation(newMode));
                    list.Add(selectedIDs[i]);
                    list2.Add((animationWindowHierarchyNode.path + animationWindowHierarchyNode.animatableObjectType.Name + str).GetHashCode());
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                if (selectedIDs.Contains(list[j]))
                {
                    int index = selectedIDs.IndexOf(list[j]);
                    selectedIDs[index] = list2[j];
                }
                if (expandedIDs.Contains(list[j]))
                {
                    int index2 = expandedIDs.IndexOf(list[j]);
                    expandedIDs[index2] = list2[j];
                }
                if (this.state.hierarchyState.lastClickedID == list[j])
                {
                    this.state.hierarchyState.lastClickedID = list2[j];
                }
            }
            this.state.hierarchyState.selectedIDs = new List <int>(selectedIDs);
            this.state.hierarchyState.expandedIDs = new List <int>(expandedIDs);
        }
Пример #15
0
        private void MaintainTreeviewStateAfterRotationInterpolation(RotationCurveInterpolation.Mode newMode)
        {
            List <int> selectedIds = this.state.hierarchyState.selectedIDs;
            List <int> expandedIds = this.state.hierarchyState.expandedIDs;
            List <int> intList1    = new List <int>();
            List <int> intList2    = new List <int>();

            for (int index = 0; index < selectedIds.Count; ++index)
            {
                AnimationWindowHierarchyNode windowHierarchyNode = this.state.hierarchyData.FindItem(selectedIds[index]) as AnimationWindowHierarchyNode;
                if (windowHierarchyNode != null && !windowHierarchyNode.propertyName.Equals(RotationCurveInterpolation.GetPrefixForInterpolation(newMode)))
                {
                    string oldValue = windowHierarchyNode.propertyName.Split('.')[0];
                    string str      = windowHierarchyNode.propertyName.Replace(oldValue, RotationCurveInterpolation.GetPrefixForInterpolation(newMode));
                    intList1.Add(selectedIds[index]);
                    intList2.Add((windowHierarchyNode.path + windowHierarchyNode.animatableObjectType.Name + str).GetHashCode());
                }
            }
            for (int index1 = 0; index1 < intList1.Count; ++index1)
            {
                if (selectedIds.Contains(intList1[index1]))
                {
                    int index2 = selectedIds.IndexOf(intList1[index1]);
                    selectedIds[index2] = intList2[index1];
                }
                if (expandedIds.Contains(intList1[index1]))
                {
                    int index2 = expandedIds.IndexOf(intList1[index1]);
                    expandedIds[index2] = intList2[index1];
                }
                if (this.state.hierarchyState.lastClickedID == intList1[index1])
                {
                    this.state.hierarchyState.lastClickedID = intList2[index1];
                }
            }
            this.state.hierarchyState.selectedIDs = new List <int>((IEnumerable <int>)selectedIds);
            this.state.hierarchyState.expandedIDs = new List <int>((IEnumerable <int>)expandedIds);
        }
        private GenericMenu GenerateMenu(List <AnimationWindowHierarchyNode> interactedNodes, bool enabled)
        {
            List <AnimationWindowCurve> curves = GetCurvesAffectedByNodes(interactedNodes, false);
            // Linked curves are like regular affected curves but always include transform siblings
            List <AnimationWindowCurve> linkedCurves = GetCurvesAffectedByNodes(interactedNodes, true);

            bool forceGroupRemove = curves.Count == 1 ? AnimationWindowUtility.ForceGrouping(curves[0].binding) : false;

            GenericMenu menu = new GenericMenu();

            // Remove curves
            GUIContent removePropertyContent = new GUIContent(curves.Count > 1 || forceGroupRemove ? "Remove Properties" : "Remove Property");

            if (!enabled)
            {
                menu.AddDisabledItem(removePropertyContent);
            }
            else
            {
                menu.AddItem(removePropertyContent, false, RemoveCurvesFromSelectedNodes);
            }

            // Change rotation interpolation
            bool showInterpolation = true;

            EditorCurveBinding[] curveBindings = new EditorCurveBinding[linkedCurves.Count];
            for (int i = 0; i < linkedCurves.Count; i++)
            {
                curveBindings[i] = linkedCurves[i].binding;
            }
            RotationCurveInterpolation.Mode rotationInterpolation = GetRotationInterpolationMode(curveBindings);
            if (rotationInterpolation == RotationCurveInterpolation.Mode.Undefined)
            {
                showInterpolation = false;
            }
            else
            {
                foreach (var node in interactedNodes)
                {
                    if (!(node is AnimationWindowHierarchyPropertyGroupNode))
                    {
                        showInterpolation = false;
                    }
                }
            }
            if (showInterpolation)
            {
                string legacyWarning = state.activeAnimationClip.legacy ? " (Not fully supported in Legacy)" : "";
                GenericMenu.MenuFunction2 nullMenuFunction2 = null;
                menu.AddItem(EditorGUIUtility.TrTextContent("Interpolation/Euler Angles" + legacyWarning), rotationInterpolation == RotationCurveInterpolation.Mode.RawEuler, enabled ? ChangeRotationInterpolation : nullMenuFunction2, RotationCurveInterpolation.Mode.RawEuler);
                menu.AddItem(EditorGUIUtility.TrTextContent("Interpolation/Euler Angles (Quaternion)"), rotationInterpolation == RotationCurveInterpolation.Mode.Baked, enabled ? ChangeRotationInterpolation : nullMenuFunction2, RotationCurveInterpolation.Mode.Baked);
                menu.AddItem(EditorGUIUtility.TrTextContent("Interpolation/Quaternion"), rotationInterpolation == RotationCurveInterpolation.Mode.NonBaked, enabled ? ChangeRotationInterpolation : nullMenuFunction2, RotationCurveInterpolation.Mode.NonBaked);
            }

            // Menu items that are only applicaple when in animation mode:
            if (state.previewing)
            {
                menu.AddSeparator("");

                bool allHaveKeys  = true;
                bool noneHaveKeys = true;
                foreach (AnimationWindowCurve curve in curves)
                {
                    bool curveHasKey = curve.HasKeyframe(state.time);
                    if (!curveHasKey)
                    {
                        allHaveKeys = false;
                    }
                    else
                    {
                        noneHaveKeys = false;
                    }
                }

                string str;

                str = "Add Key";
                if (allHaveKeys || !enabled)
                {
                    menu.AddDisabledItem(new GUIContent(str));
                }
                else
                {
                    menu.AddItem(new GUIContent(str), false, AddKeysAtCurrentTime, curves);
                }

                str = "Delete Key";
                if (noneHaveKeys || !enabled)
                {
                    menu.AddDisabledItem(new GUIContent(str));
                }
                else
                {
                    menu.AddItem(new GUIContent(str), false, DeleteKeysAtCurrentTime, curves);
                }
            }

            return(menu);
        }
 internal static EditorCurveBinding[] ConvertRotationPropertiesToInterpolationType(EditorCurveBinding[] selection, RotationCurveInterpolation.Mode newInterpolationMode)
 {
     EditorCurveBinding[] result;
     if (selection.Length != 4)
     {
         result = selection;
     }
     else if (RotationCurveInterpolation.GetModeFromCurveData(selection[0]) == RotationCurveInterpolation.Mode.RawQuaternions)
     {
         EditorCurveBinding[] array = new EditorCurveBinding[]
         {
             selection[0],
             selection[1],
             selection[2]
         };
         string prefixForInterpolation = RotationCurveInterpolation.GetPrefixForInterpolation(newInterpolationMode);
         array[0].propertyName = prefixForInterpolation + ".x";
         array[1].propertyName = prefixForInterpolation + ".y";
         array[2].propertyName = prefixForInterpolation + ".z";
         result = array;
     }
     else
     {
         result = selection;
     }
     return(result);
 }
Пример #18
0
        private GenericMenu GenerateMenu(List <AnimationWindowHierarchyNode> interactedNodes)
        {
            List <AnimationWindowCurve> curvesAffectedByNodes  = this.GetCurvesAffectedByNodes(interactedNodes, false);
            List <AnimationWindowCurve> curvesAffectedByNodes2 = this.GetCurvesAffectedByNodes(interactedNodes, true);
            bool        flag        = curvesAffectedByNodes.Count == 1 && AnimationWindowUtility.ForceGrouping(curvesAffectedByNodes[0].binding);
            GenericMenu genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent((curvesAffectedByNodes.Count <= 1 && !flag) ? "Remove Property" : "Remove Properties"), false, new GenericMenu.MenuFunction(this.RemoveCurvesFromSelectedNodes));
            bool flag2 = true;

            EditorCurveBinding[] array = new EditorCurveBinding[curvesAffectedByNodes2.Count];
            for (int i = 0; i < curvesAffectedByNodes2.Count; i++)
            {
                array[i] = curvesAffectedByNodes2[i].binding;
            }
            RotationCurveInterpolation.Mode rotationInterpolationMode = this.GetRotationInterpolationMode(array);
            if (rotationInterpolationMode == RotationCurveInterpolation.Mode.Undefined)
            {
                flag2 = false;
            }
            else
            {
                foreach (AnimationWindowHierarchyNode current in interactedNodes)
                {
                    if (!(current is AnimationWindowHierarchyPropertyGroupNode))
                    {
                        flag2 = false;
                    }
                }
            }
            if (flag2)
            {
                string str = (!this.state.activeAnimationClip.legacy) ? string.Empty : " (Not fully supported in Legacy)";
                genericMenu.AddItem(new GUIContent("Interpolation/Euler Angles" + str), rotationInterpolationMode == RotationCurveInterpolation.Mode.RawEuler, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), RotationCurveInterpolation.Mode.RawEuler);
                genericMenu.AddItem(new GUIContent("Interpolation/Euler Angles (Quaternion)"), rotationInterpolationMode == RotationCurveInterpolation.Mode.Baked, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), RotationCurveInterpolation.Mode.Baked);
                genericMenu.AddItem(new GUIContent("Interpolation/Quaternion"), rotationInterpolationMode == RotationCurveInterpolation.Mode.NonBaked, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), RotationCurveInterpolation.Mode.NonBaked);
            }
            if (AnimationMode.InAnimationMode())
            {
                genericMenu.AddSeparator(string.Empty);
                bool flag3 = true;
                bool flag4 = true;
                foreach (AnimationWindowCurve current2 in curvesAffectedByNodes)
                {
                    if (!current2.HasKeyframe(this.state.time))
                    {
                        flag3 = false;
                    }
                    else
                    {
                        flag4 = false;
                    }
                }
                string text = "Add Key";
                if (flag3)
                {
                    genericMenu.AddDisabledItem(new GUIContent(text));
                }
                else
                {
                    genericMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(this.AddKeysAtCurrentTime), curvesAffectedByNodes);
                }
                text = "Delete Key";
                if (flag4)
                {
                    genericMenu.AddDisabledItem(new GUIContent(text));
                }
                else
                {
                    genericMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(this.DeleteKeysAtCurrentTime), curvesAffectedByNodes);
                }
            }
            return(genericMenu);
        }
Пример #19
0
        internal static EditorCurveBinding[] ConvertRotationPropertiesToInterpolationType(EditorCurveBinding[] selection, RotationCurveInterpolation.Mode newInterpolationMode)
        {
            if (selection.Length != 4 || RotationCurveInterpolation.GetModeFromCurveData(selection[0]) != RotationCurveInterpolation.Mode.RawQuaternions)
            {
                return(selection);
            }
            EditorCurveBinding[] editorCurveBindingArray = new EditorCurveBinding[3]
            {
                selection[0],
                selection[1],
                selection[2]
            };
            string forInterpolation = RotationCurveInterpolation.GetPrefixForInterpolation(newInterpolationMode);

            editorCurveBindingArray[0].propertyName = forInterpolation + ".x";
            editorCurveBindingArray[1].propertyName = forInterpolation + ".y";
            editorCurveBindingArray[2].propertyName = forInterpolation + ".z";
            return(editorCurveBindingArray);
        }
Пример #20
0
 internal static EditorCurveBinding[] ConvertRotationPropertiesToDefaultInterpolation(AnimationClip clip, EditorCurveBinding[] selection)
 {
     RotationCurveInterpolation.Mode newInterpolationMode = !clip.legacy ? RotationCurveInterpolation.Mode.RawEuler : RotationCurveInterpolation.Mode.Baked;
     return(RotationCurveInterpolation.ConvertRotationPropertiesToInterpolationType(selection, newInterpolationMode));
 }
Пример #21
0
        internal static void SetInterpolation(AnimationClip clip, EditorCurveBinding[] curveBindings, RotationCurveInterpolation.Mode newInterpolationMode)
        {
            Undo.RegisterCompleteObjectUndo((UnityEngine.Object)clip, "Rotation Interpolation");
            if (clip.legacy && newInterpolationMode == RotationCurveInterpolation.Mode.RawEuler)
            {
                Debug.LogWarning((object)"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.", (UnityEngine.Object)clip);
            }
            List <EditorCurveBinding> editorCurveBindingList1 = new List <EditorCurveBinding>();
            List <AnimationCurve>     animationCurveList      = new List <AnimationCurve>();
            List <EditorCurveBinding> editorCurveBindingList2 = new List <EditorCurveBinding>();

            foreach (EditorCurveBinding curveBinding in curveBindings)
            {
                switch (RotationCurveInterpolation.GetModeFromCurveData(curveBinding))
                {
                case RotationCurveInterpolation.Mode.Undefined:
                    continue;

                case RotationCurveInterpolation.Mode.RawQuaternions:
                    Debug.LogWarning((object)("Can't convert quaternion curve: " + curveBinding.propertyName));
                    continue;

                default:
                    AnimationCurve editorCurve = AnimationUtility.GetEditorCurve(clip, curveBinding);
                    if (editorCurve != null)
                    {
                        string str = RotationCurveInterpolation.GetPrefixForInterpolation(newInterpolationMode) + (object)'.' + (object)RotationCurveInterpolation.ExtractComponentCharacter(curveBinding.propertyName);
                        editorCurveBindingList1.Add(new EditorCurveBinding()
                        {
                            propertyName = str,
                            type         = curveBinding.type,
                            path         = curveBinding.path
                        });
                        animationCurveList.Add(editorCurve);
                        editorCurveBindingList2.Add(new EditorCurveBinding()
                        {
                            propertyName = curveBinding.propertyName,
                            type         = curveBinding.type,
                            path         = curveBinding.path
                        });
                        continue;
                    }
                    continue;
                }
            }
            Undo.RegisterCompleteObjectUndo((UnityEngine.Object)clip, "Rotation Interpolation");
            using (List <EditorCurveBinding> .Enumerator enumerator = editorCurveBindingList2.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    EditorCurveBinding current = enumerator.Current;
                    AnimationUtility.SetEditorCurve(clip, current, (AnimationCurve)null);
                }
            }
            using (List <EditorCurveBinding> .Enumerator enumerator = editorCurveBindingList1.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    EditorCurveBinding current = enumerator.Current;
                    AnimationUtility.SetEditorCurve(clip, current, animationCurveList[editorCurveBindingList1.IndexOf(current)]);
                }
            }
        }
        private GenericMenu GenerateMenu(List <AnimationWindowHierarchyNode> interactedNodes)
        {
            List <AnimationWindowCurve> curvesAffectedByNodes = this.GetCurvesAffectedByNodes(interactedNodes, false);
            List <AnimationWindowCurve> list2 = this.GetCurvesAffectedByNodes(interactedNodes, true);
            bool        flag = (curvesAffectedByNodes.Count == 1) && AnimationWindowUtility.ForceGrouping(curvesAffectedByNodes[0].binding);
            GenericMenu menu = new GenericMenu();

            menu.AddItem(new GUIContent(((curvesAffectedByNodes.Count <= 1) && !flag) ? "Remove Property" : "Remove Properties"), false, new GenericMenu.MenuFunction(this.RemoveCurvesFromSelectedNodes));
            bool flag2 = true;

            EditorCurveBinding[] curves = new EditorCurveBinding[list2.Count];
            for (int i = 0; i < list2.Count; i++)
            {
                curves[i] = list2[i].binding;
            }
            RotationCurveInterpolation.Mode rotationInterpolationMode = this.GetRotationInterpolationMode(curves);
            if (rotationInterpolationMode == RotationCurveInterpolation.Mode.Undefined)
            {
                flag2 = false;
            }
            else
            {
                foreach (AnimationWindowHierarchyNode node in interactedNodes)
                {
                    if (!(node is AnimationWindowHierarchyPropertyGroupNode))
                    {
                        flag2 = false;
                    }
                }
            }
            if (flag2)
            {
                menu.AddItem(new GUIContent("Interpolation/Euler Angles"), rotationInterpolationMode == RotationCurveInterpolation.Mode.RawEuler, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), RotationCurveInterpolation.Mode.RawEuler);
                menu.AddItem(new GUIContent("Interpolation/Euler Angles (Quaternion Approximation)"), rotationInterpolationMode == RotationCurveInterpolation.Mode.Baked, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), RotationCurveInterpolation.Mode.Baked);
                menu.AddItem(new GUIContent("Interpolation/Quaternion"), rotationInterpolationMode == RotationCurveInterpolation.Mode.NonBaked, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), RotationCurveInterpolation.Mode.NonBaked);
            }
            if (AnimationMode.InAnimationMode())
            {
                menu.AddSeparator(string.Empty);
                bool flag3 = true;
                bool flag4 = true;
                bool flag5 = true;
                foreach (AnimationWindowCurve curve in curvesAffectedByNodes)
                {
                    if (!curve.HasKeyframe(this.state.time))
                    {
                        flag3 = false;
                    }
                    else
                    {
                        flag4 = false;
                        if (!curve.isPPtrCurve)
                        {
                            flag5 = false;
                        }
                    }
                }
                string text = "Add Key";
                if (flag3)
                {
                    menu.AddDisabledItem(new GUIContent(text));
                }
                else
                {
                    menu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(this.AddKeysAtCurrentTime), curvesAffectedByNodes);
                }
                text = "Delete Key";
                if (flag4)
                {
                    menu.AddDisabledItem(new GUIContent(text));
                }
                else
                {
                    menu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(this.DeleteKeysAtCurrentTime), curvesAffectedByNodes);
                }
                if (flag5)
                {
                    return(menu);
                }
                menu.AddSeparator(string.Empty);
                List <KeyIdentifier> list3 = new List <KeyIdentifier>();
                foreach (AnimationWindowCurve curve2 in curvesAffectedByNodes)
                {
                    if (!curve2.isPPtrCurve)
                    {
                        int keyframeIndex = curve2.GetKeyframeIndex(this.state.time);
                        if (keyframeIndex != -1)
                        {
                            CurveRenderer curveRenderer = CurveRendererCache.GetCurveRenderer(this.state.activeAnimationClip, curve2.binding);
                            int           curveID       = CurveUtility.GetCurveID(this.state.activeAnimationClip, curve2.binding);
                            list3.Add(new KeyIdentifier(curveRenderer, curveID, keyframeIndex));
                        }
                    }
                }
            }
            return(menu);
        }
Пример #23
0
        private GenericMenu GenerateMenu(List <AnimationWindowHierarchyNode> interactedNodes)
        {
            List <AnimationWindowCurve> curvesAffectedByNodes1 = this.GetCurvesAffectedByNodes(interactedNodes, false);
            List <AnimationWindowCurve> curvesAffectedByNodes2 = this.GetCurvesAffectedByNodes(interactedNodes, true);
            bool        flag1       = curvesAffectedByNodes1.Count == 1 && AnimationWindowUtility.ForceGrouping(curvesAffectedByNodes1[0].binding);
            GenericMenu genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent(curvesAffectedByNodes1.Count > 1 || flag1 ? "Remove Properties" : "Remove Property"), false, new GenericMenu.MenuFunction(this.RemoveCurvesFromSelectedNodes));
            bool flag2 = true;

            EditorCurveBinding[] curves = new EditorCurveBinding[curvesAffectedByNodes2.Count];
            for (int index = 0; index < curvesAffectedByNodes2.Count; ++index)
            {
                curves[index] = curvesAffectedByNodes2[index].binding;
            }
            RotationCurveInterpolation.Mode interpolationMode = this.GetRotationInterpolationMode(curves);
            if (interpolationMode == RotationCurveInterpolation.Mode.Undefined)
            {
                flag2 = false;
            }
            else
            {
                using (List <AnimationWindowHierarchyNode> .Enumerator enumerator = interactedNodes.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        if (!(enumerator.Current is AnimationWindowHierarchyPropertyGroupNode))
                        {
                            flag2 = false;
                        }
                    }
                }
            }
            if (flag2)
            {
                string str = !this.state.activeAnimationClip.legacy ? string.Empty : " (Not fully supported in Legacy)";
                genericMenu.AddItem(new GUIContent("Interpolation/Euler Angles" + str), interpolationMode == RotationCurveInterpolation.Mode.RawEuler, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), (object)RotationCurveInterpolation.Mode.RawEuler);
                genericMenu.AddItem(new GUIContent("Interpolation/Euler Angles (Quaternion Approximation)"), interpolationMode == RotationCurveInterpolation.Mode.Baked, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), (object)RotationCurveInterpolation.Mode.Baked);
                genericMenu.AddItem(new GUIContent("Interpolation/Quaternion"), interpolationMode == RotationCurveInterpolation.Mode.NonBaked, new GenericMenu.MenuFunction2(this.ChangeRotationInterpolation), (object)RotationCurveInterpolation.Mode.NonBaked);
            }
            if (AnimationMode.InAnimationMode())
            {
                genericMenu.AddSeparator(string.Empty);
                bool flag3 = true;
                bool flag4 = true;
                bool flag5 = true;
                using (List <AnimationWindowCurve> .Enumerator enumerator = curvesAffectedByNodes1.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        AnimationWindowCurve current = enumerator.Current;
                        if (!current.HasKeyframe(this.state.time))
                        {
                            flag3 = false;
                        }
                        else
                        {
                            flag4 = false;
                            if (!current.isPPtrCurve)
                            {
                                flag5 = false;
                            }
                        }
                    }
                }
                string text1 = "Add Key";
                if (flag3)
                {
                    genericMenu.AddDisabledItem(new GUIContent(text1));
                }
                else
                {
                    genericMenu.AddItem(new GUIContent(text1), false, new GenericMenu.MenuFunction2(this.AddKeysAtCurrentTime), (object)curvesAffectedByNodes1);
                }
                string text2 = "Delete Key";
                if (flag4)
                {
                    genericMenu.AddDisabledItem(new GUIContent(text2));
                }
                else
                {
                    genericMenu.AddItem(new GUIContent(text2), false, new GenericMenu.MenuFunction2(this.DeleteKeysAtCurrentTime), (object)curvesAffectedByNodes1);
                }
                if (!flag5)
                {
                    genericMenu.AddSeparator(string.Empty);
                    List <KeyIdentifier> keyIdentifierList = new List <KeyIdentifier>();
                    using (List <AnimationWindowCurve> .Enumerator enumerator = curvesAffectedByNodes1.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            AnimationWindowCurve current = enumerator.Current;
                            if (!current.isPPtrCurve)
                            {
                                int keyframeIndex = current.GetKeyframeIndex(this.state.time);
                                if (keyframeIndex != -1)
                                {
                                    CurveRenderer curveRenderer = CurveRendererCache.GetCurveRenderer(this.state.activeAnimationClip, current.binding);
                                    int           curveId       = CurveUtility.GetCurveID(this.state.activeAnimationClip, current.binding);
                                    keyIdentifierList.Add(new KeyIdentifier(curveRenderer, curveId, keyframeIndex));
                                }
                            }
                        }
                    }
                }
            }
            return(genericMenu);
        }