static bool ProcessPlayableAssetRecording(UndoPropertyModification mod, WindowState state, ICurvesOwner curvesOwner)
        {
            if (mod.currentValue == null)
            {
                return(false);
            }

            if (!curvesOwner.IsParameterAnimatable(mod.currentValue.propertyPath))
            {
                return(false);
            }

            var localTime    = state.editSequence.time;
            var timelineClip = curvesOwner as TimelineClip;

            if (timelineClip != null)
            {
                // don't use time global to local since it will possibly loop.
                localTime = timelineClip.ToLocalTimeUnbound(state.editSequence.time);
            }

            if (localTime < 0)
            {
                return(false);
            }

            // grab the value from the current modification
            float fValue;

            if (!ExpressionEvaluator.Evaluate(mod.currentValue.value, out fValue))
            {
                // case 916913 -- 'Add Key' menu item will passes 'True' or 'False' (instead of 1, 0)
                // so we need a special case to parse the boolean string
                bool bValue;
                if (!bool.TryParse(mod.currentValue.value, out bValue))
                {
                    Debug.Assert(false, "Invalid type in PlayableAsset recording");
                    return(false);
                }

                fValue = bValue ? 1 : 0;
            }

            var added = curvesOwner.AddAnimatedParameterValueAt(mod.currentValue.propertyPath, fValue, (float)localTime);

            if (added && AnimationMode.InAnimationMode())
            {
                EditorCurveBinding binding = curvesOwner.GetCurveBinding(mod.previousValue.propertyPath);
                AnimationMode.AddPropertyModification(binding, mod.previousValue, true);
                curvesOwner.targetTrack.SetShowInlineCurves(true);
                if (state.GetWindow() != null && state.GetWindow().treeView != null)
                {
                    state.GetWindow().treeView.CalculateRowRects();
                }
            }

            return(added);
        }
Ejemplo n.º 2
0
 private static void AddRotationPropertyModification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification)
 {
     if (modification.previousValue != null)
     {
         EditorCurveBinding binding = baseBinding;
         binding.propertyName = modification.previousValue.propertyPath;
         AnimationMode.AddPropertyModification(binding, modification.previousValue, modification.keepPrefabOverride);
     }
 }
Ejemplo n.º 3
0
        public static UndoPropertyModification[] Process(IAnimationRecordingState state, UndoPropertyModification[] modifications)
        {
            GameObject activeRootGameObject = state.activeRootGameObject;

            if (activeRootGameObject == null)
            {
                return(modifications);
            }
            AnimationClip activeAnimationClip = state.activeAnimationClip;
            Animator      component           = activeRootGameObject.GetComponent <Animator>();

            if (!AnimationRecording.HasAnyRecordableModifications(activeRootGameObject, modifications))
            {
                return(modifications);
            }
            AnimationRecording.ProcessRotationModifications(state, ref modifications);
            List <UndoPropertyModification> list = new List <UndoPropertyModification>();

            for (int i = 0; i < modifications.Length; i++)
            {
                EditorCurveBinding   binding       = default(EditorCurveBinding);
                PropertyModification previousValue = modifications[i].previousValue;
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(previousValue, activeRootGameObject, out binding);
                if (type != null)
                {
                    if (component != null && component.isHuman && binding.type == typeof(Transform) && component.IsBoneTransform(previousValue.target as Transform))
                    {
                        Debug.LogWarning("Keyframing for humanoid rig is not supported!", previousValue.target as Transform);
                    }
                    else
                    {
                        AnimationMode.AddPropertyModification(binding, previousValue, modifications[i].keepPrefabOverride);
                        EditorCurveBinding[] array = RotationCurveInterpolation.RemapAnimationBindingForAddKey(binding, activeAnimationClip);
                        if (array != null)
                        {
                            for (int j = 0; j < array.Length; j++)
                            {
                                AnimationRecording.AddKey(state, array[j], type, AnimationRecording.FindPropertyModification(activeRootGameObject, modifications, array[j]));
                            }
                        }
                        else
                        {
                            AnimationRecording.AddKey(state, binding, type, previousValue);
                        }
                    }
                }
                else
                {
                    list.Add(modifications[i]);
                }
            }
            return(list.ToArray());
        }
Ejemplo n.º 4
0
        public static UndoPropertyModification[] Process(AnimationWindowState state, UndoPropertyModification[] modifications)
        {
            GameObject activeRootGameObject = state.activeRootGameObject;

            if ((UnityEngine.Object)activeRootGameObject == (UnityEngine.Object)null)
            {
                return(modifications);
            }
            AnimationClip activeAnimationClip = state.activeAnimationClip;
            Animator      component           = activeRootGameObject.GetComponent <Animator>();

            if (!AnimationRecording.HasAnyRecordableModifications(activeRootGameObject, modifications))
            {
                return(modifications);
            }
            AnimationRecording.ProcessRotationModifications(state, ref modifications);
            List <UndoPropertyModification> propertyModificationList = new List <UndoPropertyModification>();

            for (int index1 = 0; index1 < modifications.Length; ++index1)
            {
                EditorCurveBinding   binding            = new EditorCurveBinding();
                PropertyModification previousValue      = modifications[index1].previousValue;
                System.Type          editorCurveBinding = AnimationUtility.PropertyModificationToEditorCurveBinding(previousValue, activeRootGameObject, out binding);
                if (editorCurveBinding != null && editorCurveBinding != typeof(Animator))
                {
                    if ((UnityEngine.Object)component != (UnityEngine.Object)null && component.isHuman && (binding.type == typeof(Transform) && component.IsBoneTransform(previousValue.target as Transform)))
                    {
                        Debug.LogWarning((object)"Keyframing for humanoid rig is not supported!", (UnityEngine.Object)(previousValue.target as Transform));
                    }
                    else
                    {
                        AnimationMode.AddPropertyModification(binding, previousValue, modifications[index1].keepPrefabOverride);
                        EditorCurveBinding[] editorCurveBindingArray = RotationCurveInterpolation.RemapAnimationBindingForAddKey(binding, activeAnimationClip);
                        if (editorCurveBindingArray != null)
                        {
                            for (int index2 = 0; index2 < editorCurveBindingArray.Length; ++index2)
                            {
                                AnimationRecording.AddKey(state, editorCurveBindingArray[index2], editorCurveBinding, AnimationRecording.FindPropertyModification(activeRootGameObject, modifications, editorCurveBindingArray[index2]));
                            }
                        }
                        else
                        {
                            AnimationRecording.AddKey(state, binding, editorCurveBinding, previousValue);
                        }
                    }
                }
                else
                {
                    propertyModificationList.Add(modifications[index1]);
                }
            }
            return(propertyModificationList.ToArray());
        }
Ejemplo n.º 5
0
        private static void AddRotationPropertyModification(IAnimationRecordingState state, UndoPropertyModification modification)
        {
            if (modification.previousValue == null)
            {
                return;
            }
            EditorCurveBinding binding = default(EditorCurveBinding);

            if (AnimationUtility.PropertyModificationToEditorCurveBinding(modification.previousValue, state.activeRootGameObject, out binding) != null)
            {
                AnimationMode.AddPropertyModification(binding, modification.previousValue, modification.keepPrefabOverride);
            }
        }
Ejemplo n.º 6
0
        internal static void UpdatePreviewMode(UndoPropertyModification[] mods, GameObject go)
        {
            if (mods.Any(x => IsPositionOrRotation(x) && IsRootModification(x)))
            {
                bool hasPosition = false;
                bool hasRotation = false;

                foreach (var mod in mods)
                {
                    EditorCurveBinding binding = new EditorCurveBinding();
                    if (AnimationUtility.PropertyModificationToEditorCurveBinding(mod.previousValue, go, out binding) != null)
                    {
                        hasPosition |= IsPosition(mod);
                        hasRotation |= IsRotation(mod);
                        AnimationMode.AddPropertyModification(binding, mod.previousValue, true);
                    }
                }

                // case 931859 - if we are only changing one field, all fields must be registered before
                // any recording modifications
                var driver = WindowState.previewDriver;
                if (driver != null && AnimationMode.InAnimationMode(driver))
                {
                    if (hasPosition)
                    {
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalPosition + ".x");
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalPosition + ".y");
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalPosition + ".z");
                    }
                    else if (hasRotation)
                    {
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalRotation + ".x");
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalRotation + ".y");
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalRotation + ".z");
                        DrivenPropertyManager.RegisterProperty(driver, go.transform, kLocalRotation + ".w");
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void AddPropertyModification(EditorCurveBinding binding, PropertyModification propertyModification, bool keepPrefabOverride)
 {
     AnimationMode.AddPropertyModification(binding, propertyModification, keepPrefabOverride);
 }