public static bool IsAnimated(MaterialProperty materialProp, Renderer target)
 {
     if (materialProp.type == MaterialProperty.PropType.Texture)
     {
         return(AnimationMode.IsPropertyAnimated((Object)target, "material." + materialProp.name + "_ST"));
     }
     return(AnimationMode.IsPropertyAnimated((Object)target, "material." + materialProp.name));
 }
        public static bool IsAnimated(MaterialProperty materialProp, Renderer target)
        {
            bool result;

            if (materialProp.type == MaterialProperty.PropType.Texture)
            {
                result = AnimationMode.IsPropertyAnimated(target, "material." + materialProp.name + "_ST");
            }
            else
            {
                result = AnimationMode.IsPropertyAnimated(target, "material." + materialProp.name);
            }
            return(result);
        }
        static public bool OverridePropertyColor(MaterialProperty materialProp, Renderer target, out Color color)
        {
            var    propertyPaths    = new List <string>();
            string basePropertyPath = kMaterialPrefix + materialProp.name;

            if (materialProp.type == MaterialProperty.PropType.Texture)
            {
                propertyPaths.Add(basePropertyPath + "_ST.x");
                propertyPaths.Add(basePropertyPath + "_ST.y");
                propertyPaths.Add(basePropertyPath + "_ST.z");
                propertyPaths.Add(basePropertyPath + "_ST.w");
            }
            else if (materialProp.type == MaterialProperty.PropType.Color)
            {
                propertyPaths.Add(basePropertyPath + ".r");
                propertyPaths.Add(basePropertyPath + ".g");
                propertyPaths.Add(basePropertyPath + ".b");
                propertyPaths.Add(basePropertyPath + ".a");
            }
            else if (materialProp.type == MaterialProperty.PropType.Vector)
            {
                propertyPaths.Add(basePropertyPath + ".x");
                propertyPaths.Add(basePropertyPath + ".y");
                propertyPaths.Add(basePropertyPath + ".z");
                propertyPaths.Add(basePropertyPath + ".w");
            }
            else
            {
                propertyPaths.Add(basePropertyPath);
            }

            if (propertyPaths.Exists(path => AnimationMode.IsPropertyAnimated(target, path)))
            {
                color = AnimationMode.animatedPropertyColor;
                if (AnimationMode.InAnimationRecording())
                {
                    color = AnimationMode.recordedPropertyColor;
                }
                else if (propertyPaths.Exists(path => AnimationMode.IsPropertyCandidate(target, path)))
                {
                    color = AnimationMode.candidatePropertyColor;
                }

                return(true);
            }

            color = Color.white;
            return(false);
        }
Esempio n. 4
0
        public static bool OverridePropertyColor(MaterialProperty materialProp, Renderer target, out Color color)
        {
            List <string> list = new List <string>();
            string        text = "material." + materialProp.name;

            if (materialProp.type == MaterialProperty.PropType.Texture)
            {
                list.Add(text + "_ST.x");
                list.Add(text + "_ST.y");
                list.Add(text + "_ST.z");
                list.Add(text + "_ST.w");
            }
            else if (materialProp.type == MaterialProperty.PropType.Color)
            {
                list.Add(text + ".r");
                list.Add(text + ".g");
                list.Add(text + ".b");
                list.Add(text + ".a");
            }
            else
            {
                list.Add(text);
            }
            bool result;

            if (list.Exists((string path) => AnimationMode.IsPropertyAnimated(target, path)))
            {
                color = AnimationMode.animatedPropertyColor;
                if (AnimationMode.InAnimationRecording())
                {
                    color = AnimationMode.recordedPropertyColor;
                }
                else if (list.Exists((string path) => AnimationMode.IsPropertyCandidate(target, path)))
                {
                    color = AnimationMode.candidatePropertyColor;
                }
                result = true;
            }
            else
            {
                color  = Color.white;
                result = false;
            }
            return(result);
        }
        private static void UpdateElementStyleFromProperty(VisualElement element, SerializedProperty prop)
        {
            if (element is IMixedValueSupport mixedValuePropertyField)
            {
                mixedValuePropertyField.showMixedValue = prop.hasMultipleDifferentValues;
            }

            // It's possible for there to be no label in a compound field, for example. So, nothing to style.
            if (element == null)
            {
                return;
            }

            // Handle prefab state.
            UpdatePrefabStateStyleFromProperty(element, prop);

            // Handle live property state.
            UpdateLivePropertyStyleFromProperty(element, prop);

            // Handle dynamic states
            updateBindingStateStyle?.Invoke(element, prop);

            // Handle animated state.

            // Since we handle compound fields above, the element here will always be a single field
            // (or not a field at all). This means we can perform a faster query and search for
            // a single element.
            var inputElement = element.Q(className: BaseField <int> .inputUssClassName);

            if (inputElement == null)
            {
                return;
            }

            bool animated  = AnimationMode.IsPropertyAnimated(prop.serializedObject.targetObject, prop.propertyPath);
            bool candidate = AnimationMode.IsPropertyCandidate(prop.serializedObject.targetObject, prop.propertyPath);
            bool recording = AnimationMode.InAnimationRecording();

            inputElement.EnableInClassList(BindingExtensions.animationRecordedUssClassName, animated && recording);
            inputElement.EnableInClassList(BindingExtensions.animationCandidateUssClassName, animated && !recording && candidate);
            inputElement.EnableInClassList(BindingExtensions.animationAnimatedUssClassName, animated && !recording && !candidate);
        }
        private AnimationModeDriver GetAnimationModeDriver()
        {
            if (m_Driver == null)
            {
                m_Driver                = CreateInstance <AnimationModeDriver>();
                m_Driver.hideFlags      = HideFlags.HideAndDontSave;
                m_Driver.name           = "AnimationWindowDriver";
                m_Driver.isKeyCallback += (Object target, string propertyPath) => {
                    if (AnimationMode.IsPropertyAnimated(target, propertyPath))
                    {
                        var modification = new PropertyModification();
                        modification.target       = target;
                        modification.propertyPath = propertyPath;

                        return(KeyExists(new PropertyModification[] { modification }));
                    }

                    return(false);
                };
            }

            return(m_Driver);
        }
        protected virtual void DrawParameters()
        {
#if !WORKAROUND_TIMELINE
            if (s_FakeObjectCache == null)
            {
                s_FakeObjectCache           = ScriptableObject.CreateInstance <FakeObject>();
                s_FakeObjectSerializedCache = new SerializedObject(s_FakeObjectCache);
            }
#endif
            var component = (VisualEffect)target;
            if (m_graph == null || m_asset != component.visualEffectAsset)
            {
                m_asset = component.visualEffectAsset;
                if (m_asset != null)
                {
                    m_graph = m_asset.GetResource().GetOrCreateGraph();
                }
            }

            GUI.enabled = true;

            if (m_graph != null)
            {
                if (m_graph.m_ParameterInfo == null)
                {
                    m_graph.BuildParameterInfo();
                }

                if (m_graph.m_ParameterInfo != null)
                {
                    ShowHeader(Contents.headerParameters, false, false, false, false);
                    var stack        = new List <int>();
                    int currentCount = m_graph.m_ParameterInfo.Length;
                    if (currentCount == 0)
                    {
                        GUILayout.Label("No Parameter exposed in the asset");
                    }

                    bool ignoreUntilNextCat = false;

                    foreach (var param in m_graph.m_ParameterInfo)
                    {
                        --currentCount;

                        var parameter = param;
                        if (parameter.descendantCount > 0)
                        {
                            stack.Add(currentCount);
                            currentCount = parameter.descendantCount;
                        }

                        if (currentCount == 0 && stack.Count > 0)
                        {
                            do
                            {
                                currentCount = stack.Last();
                                stack.RemoveAt(stack.Count - 1);
                            }while (currentCount == 0);
                        }

                        if (string.IsNullOrEmpty(parameter.sheetType))
                        {
                            if (!string.IsNullOrEmpty(parameter.name))
                            {
                                if (string.IsNullOrEmpty(parameter.realType)) // This is a category
                                {
                                    bool wasIgnored = ignoreUntilNextCat;
                                    ignoreUntilNextCat = false;
                                    var nameContent = GetGUIContent(parameter.name);

                                    bool prevState    = EditorPrefs.GetBool("VFX-category-" + parameter.name, true);
                                    bool currentState = ShowHeader(nameContent, !wasIgnored, false, true, prevState);
                                    if (currentState != prevState)
                                    {
                                        EditorPrefs.SetBool("VFX-category-" + parameter.name, currentState);
                                    }

                                    if (!currentState)
                                    {
                                        ignoreUntilNextCat = true;
                                    }
                                    else
                                    {
                                        GUILayout.Space(Styles.headerBottomMargin);
                                    }
                                }
                                else if (!ignoreUntilNextCat)
                                {
                                    EmptyLineControl(parameter.name, parameter.tooltip, stack.Count);
                                }
                            }
                        }
                        else if (!ignoreUntilNextCat)
                        {
                            //< Try find source property
                            var sourceVfxField = m_VFXPropertySheet.FindPropertyRelative(parameter.sheetType + ".m_Array");
                            SerializedProperty sourceProperty = null;
                            for (int i = 0; i < sourceVfxField.arraySize; ++i)
                            {
                                sourceProperty = sourceVfxField.GetArrayElementAtIndex(i);
                                var nameProperty = sourceProperty.FindPropertyRelative("m_Name").stringValue;
                                if (nameProperty == parameter.path)
                                {
                                    break;
                                }
                                sourceProperty = null;
                            }

                            //< Prepare potential indirection
                            bool wasNewProperty           = false;
                            bool wasNotOverriddenProperty = false;

                            SerializedProperty actualDisplayedPropertyValue      = null;
                            SerializedProperty actualDisplayedPropertyOverridden = null;
                            if (sourceProperty == null)
                            {
                                s_FakeObjectSerializedCache.Update();
                                var fakeField = s_FakeObjectSerializedCache.FindProperty("m_PropertySheet." + parameter.sheetType + ".m_Array");
                                fakeField.InsertArrayElementAtIndex(fakeField.arraySize);
                                var newFakeEntry = fakeField.GetArrayElementAtIndex(fakeField.arraySize - 1);
                                newFakeEntry.FindPropertyRelative("m_Name").stringValue     = param.path;
                                newFakeEntry.FindPropertyRelative("m_Overridden").boolValue = false;

                                actualDisplayedPropertyOverridden = newFakeEntry.FindPropertyRelative("m_Overridden");
                                actualDisplayedPropertyValue      = newFakeEntry.FindPropertyRelative("m_Value");
                                SetObjectValue(actualDisplayedPropertyValue, parameter.defaultValue.Get());

                                wasNewProperty = true;
                            }
                            else
                            {
                                actualDisplayedPropertyOverridden = sourceProperty.FindPropertyRelative("m_Overridden");
                                actualDisplayedPropertyValue      = sourceProperty.FindPropertyRelative("m_Value");
                                if (!actualDisplayedPropertyOverridden.boolValue)
                                {
                                    s_FakeObjectSerializedCache.Update();

                                    actualDisplayedPropertyOverridden = s_FakeObjectSerializedCache.FindProperty(actualDisplayedPropertyOverridden.propertyPath);
                                    actualDisplayedPropertyValue      = s_FakeObjectSerializedCache.FindProperty(actualDisplayedPropertyValue.propertyPath);
                                    SetObjectValue(actualDisplayedPropertyValue, parameter.defaultValue.Get());

                                    wasNotOverriddenProperty = true;
                                }
                            }

                            //< Actual display
                            GUIContent nameContent = GetGUIContent(parameter.name, parameter.tooltip);
                            EditorGUI.BeginChangeCheck();
                            DisplayProperty(ref parameter, nameContent, actualDisplayedPropertyOverridden, actualDisplayedPropertyValue, AnimationMode.IsPropertyAnimated(target, actualDisplayedPropertyValue.propertyPath));
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (wasNewProperty)
                                {
                                    //We start editing a new exposed value which wasn't stored in this Visual Effect Component
                                    sourceVfxField.InsertArrayElementAtIndex(sourceVfxField.arraySize);
                                    var newEntry = sourceVfxField.GetArrayElementAtIndex(sourceVfxField.arraySize - 1);

                                    newEntry.FindPropertyRelative("m_Overridden").boolValue = actualDisplayedPropertyOverridden.boolValue;
                                    SetObjectValue(newEntry.FindPropertyRelative("m_Value"), GetObjectValue(actualDisplayedPropertyValue));
                                    newEntry.FindPropertyRelative("m_Name").stringValue = param.path;
                                }
                                else if (wasNotOverriddenProperty)
                                {
                                    if (actualDisplayedPropertyOverridden.boolValue)
                                    {
                                        //The check box has simply been toggle, we should not restore value from asset but simply change overridden state
                                        sourceProperty.FindPropertyRelative("m_Overridden").boolValue = true;
                                    }
                                    else
                                    {
                                        //The value has been directly changed, change overridden state and recopy new value
                                        SetObjectValue(sourceProperty.FindPropertyRelative("m_Value"), GetObjectValue(actualDisplayedPropertyValue));
                                        sourceProperty.FindPropertyRelative("m_Overridden").boolValue = true;
                                    }
                                }
                                else //wasNewProperty == wasNotOverriddenProperty == false => there isn't any additionnal behavior needed, we are already using real serialized property
                                {
                                }
                                serializedObject.ApplyModifiedProperties();
                            }
                        }
                        EditorGUI.indentLevel = stack.Count;
                    }
                }
            }
            GUILayout.Space(1); // Space for the line if the last category is closed.
        }
 private AnimationModeDriver GetAnimationModeDriver()
 {
     if (this.m_Driver == null)
     {
         this.m_Driver      = ScriptableObject.CreateInstance <AnimationModeDriver>();
         this.m_Driver.name = "AnimationWindowDriver";
         AnimationModeDriver expr_34 = this.m_Driver;
         expr_34.isKeyCallback = (AnimationModeDriver.IsKeyCallback)Delegate.Combine(expr_34.isKeyCallback, new AnimationModeDriver.IsKeyCallback((UnityEngine.Object target, string propertyPath) => AnimationMode.IsPropertyAnimated(target, propertyPath) && this.KeyExists(new PropertyModification[]
         {
             new PropertyModification
             {
                 target       = target,
                 propertyPath = propertyPath
             }
         })));
     }
     return(this.m_Driver);
 }
 public bool DiscardModification(PropertyModification modification)
 {
     return(!AnimationMode.IsPropertyAnimated(modification.target, modification.propertyPath));
 }
Esempio n. 10
0
        private static AnimationClip CreateDefaultPose(RigBuilder rigBuilder)
        {
            if (rigBuilder == null)
            {
                throw new ArgumentNullException("It is not possible to bake curves without an RigBuilder.");
            }

            var defaultPoseClip = new AnimationClip()
            {
                name = "DefaultPose"
            };

            if (!AnimationMode.InAnimationMode())
            {
                return(defaultPoseClip);
            }

            var bindings = new List <EditorCurveBinding>();

            var gameObjects = new Queue <GameObject>();

            gameObjects.Enqueue(rigBuilder.gameObject);

            while (gameObjects.Count > 0)
            {
                var gameObject = gameObjects.Dequeue();

                EditorCurveBinding[] allBindings = AnimationUtility.GetAnimatableBindings(gameObject, rigBuilder.gameObject);
                foreach (var binding in allBindings)
                {
                    if (binding.isPPtrCurve)
                    {
                        continue;
                    }

                    if (binding.type == typeof(GameObject))
                    {
                        continue;
                    }

                    UnityEngine.Object target = gameObject.GetComponent(binding.type);
                    if (!AnimationMode.IsPropertyAnimated(target, binding.propertyName))
                    {
                        continue;
                    }

                    bindings.Add(binding);
                }

                // Iterate over all child GOs
                for (int i = 0; i < gameObject.transform.childCount; i++)
                {
                    Transform childTransform = gameObject.transform.GetChild(i);
                    gameObjects.Enqueue(childTransform.gameObject);
                }
            }

            // Flush out animation mode modifications
            AnimationMode.BeginSampling();
            AnimationMode.EndSampling();

            foreach (var binding in bindings)
            {
                float floatValue;
                AnimationUtility.GetFloatValue(rigBuilder.gameObject, binding, out floatValue);

                var key   = new Keyframe(0f, floatValue);
                var curve = new AnimationCurve(new Keyframe[] { key });
                defaultPoseClip.SetCurve(binding.path, binding.type, binding.propertyName, curve);
            }

            return(defaultPoseClip);
        }
        internal static void UpdateElementStyle(VisualElement element, SerializedProperty prop)
        {
            if (element == null)
            {
                return;
            }

            if (element is Foldout)
            {
                // We only want to apply override styles onto the Foldout header, not the entire contents.
                element = element.Q(className: Foldout.toggleUssClassName);
            }
            else if (element.ClassListContains(BaseCompositeField <int, IntegerField, int> .ussClassName) ||
                     element is BoundsField || element is BoundsIntField)
            {
                // The problem with compound fields is that they are bound at the parent level using
                // their parent value data type. For example, a Vector3Field is bound to the parent
                // SerializedProperty which uses the Vector3 data type. However, animation overrides
                // are not stored on the parent SerializedProperty but on the component child
                // SerializedProperties. So even though we're bound to the parent property, we still
                // have to dive inside and example the child SerializedProperties (ie. x, y, z, height)
                // and override the animation styles individually.

                var compositeField = element;

                // The element we style in the main pass is going to be just the label.
                element = element.Q(className: BaseField <int> .labelUssClassName);

                // Go through the inputs and find any that match the names of the child PropertyFields.
                var propCopy    = prop.Copy();
                var endProperty = propCopy.GetEndProperty();
                propCopy.NextVisible(true);     // Expand the first child.
                do
                {
                    if (SerializedProperty.EqualContents(propCopy, endProperty))
                    {
                        break;
                    }

                    var subInputName = "unity-" + propCopy.name + "-input";
                    var subInput     = compositeField.Q(subInputName);
                    if (subInput == null)
                    {
                        continue;
                    }

                    UpdateElementStyle(subInput, propCopy);
                }while (propCopy.NextVisible(false));     // Never expand children.
            }

            // It's possible for there to be no label in a compound field, for example. So, nothing to style.
            if (element == null)
            {
                return;
            }

            // Handle prefab state.
            UpdatePrefabStateStyle(element, prop);

            // Handle animated state.

            // Since we handle compound fields above, the element here will always be a single field
            // (or not a field at all). This means we can perform a faster query and search for
            // a single element.
            var inputElement = element.Q(className: BaseField <int> .inputUssClassName);

            if (inputElement == null)
            {
                return;
            }

            bool animated  = AnimationMode.IsPropertyAnimated(prop.serializedObject.targetObject, prop.propertyPath);
            bool candidate = AnimationMode.IsPropertyCandidate(prop.serializedObject.targetObject, prop.propertyPath);
            bool recording = AnimationMode.InAnimationRecording();

            inputElement.EnableInClassList(BindingExtensions.animationRecordedUssClassName, animated && recording);
            inputElement.EnableInClassList(BindingExtensions.animationCandidateUssClassName, animated && !recording && candidate);
            inputElement.EnableInClassList(BindingExtensions.animationAnimatedUssClassName, animated && !recording && !candidate);
        }
        protected virtual void DrawParameters()
        {
#if !WORKAROUND_TIMELINE
            if (s_FakeObjectCache == null)
            {
                s_FakeObjectCache           = ScriptableObject.CreateInstance <FakeObject>();
                s_FakeObjectSerializedCache = new SerializedObject(s_FakeObjectCache);
            }
#endif
            var component = (VisualEffect)target;
            if (m_graph == null || m_asset != component.visualEffectAsset)
            {
                m_asset = component.visualEffectAsset;
                if (m_asset != null)
                {
                    m_graph = m_asset.GetResource().GetOrCreateGraph();
                }
            }

            GUI.enabled = true;

            if (m_graph != null)
            {
                if (m_graph.m_ParameterInfo == null)
                {
                    m_graph.BuildParameterInfo();
                }

                if (m_graph.m_ParameterInfo != null)
                {
                    ShowHeader(Contents.headerParameters, false, false, false, false);
                    List <int> stack        = new List <int>();
                    int        currentCount = m_graph.m_ParameterInfo.Length;
                    if (currentCount == 0)
                    {
                        GUILayout.Label("No Parameter exposed in the asset");
                    }

                    bool ignoreUntilNextCat = false;

                    foreach (var param in m_graph.m_ParameterInfo)
                    {
                        --currentCount;

                        var parameter = param;

                        if (parameter.descendantCount > 0)
                        {
                            stack.Add(currentCount);
                            currentCount = parameter.descendantCount;
                        }

                        if (currentCount == 0 && stack.Count > 0)
                        {
                            do
                            {
                                currentCount = stack.Last();
                                stack.RemoveAt(stack.Count - 1);
                            }while (currentCount == 0);
                        }

                        if (string.IsNullOrEmpty(parameter.sheetType))
                        {
                            if (!string.IsNullOrEmpty(parameter.name))
                            {
                                if (string.IsNullOrEmpty(parameter.realType)) // This is a category
                                {
                                    bool wasIgnored = ignoreUntilNextCat;
                                    ignoreUntilNextCat = false;
                                    var nameContent = GetGUIContent(parameter.name);

                                    bool prevState    = EditorPrefs.GetBool("VFX-category-" + parameter.name, true);
                                    bool currentState = ShowHeader(nameContent, !wasIgnored, false, true, prevState);
                                    if (currentState != prevState)
                                    {
                                        EditorPrefs.SetBool("VFX-category-" + parameter.name, currentState);
                                    }

                                    if (!currentState)
                                    {
                                        ignoreUntilNextCat = true;
                                    }
                                    else
                                    {
                                        GUILayout.Space(Styles.headerBottomMargin);
                                    }
                                }
                                else if (!ignoreUntilNextCat)
                                {
                                    EmptyLineControl(parameter.name, parameter.tooltip, stack.Count);
                                }
                            }
                        }
                        else if (!ignoreUntilNextCat)
                        {
                            var vfxField = m_VFXPropertySheet.FindPropertyRelative(parameter.sheetType + ".m_Array");
                            SerializedProperty property = null;
                            if (vfxField != null)
                            {
                                for (int i = 0; i < vfxField.arraySize; ++i)
                                {
                                    property = vfxField.GetArrayElementAtIndex(i);
                                    var nameProperty = property.FindPropertyRelative("m_Name").stringValue;
                                    if (nameProperty == parameter.path)
                                    {
                                        break;
                                    }

                                    property = null;
                                }
                            }

                            if (property != null)
                            {
                                SerializedProperty overrideProperty = property.FindPropertyRelative("m_Overridden");
                                property = property.FindPropertyRelative("m_Value");
                                string firstpropName = property.name;

                                Color previousColor = GUI.color;
                                var   animated      = AnimationMode.IsPropertyAnimated(target, property.propertyPath);
                                if (animated)
                                {
                                    GUI.color = AnimationMode.animatedPropertyColor;
                                }

                                DisplayProperty(ref parameter, overrideProperty, property);

                                if (animated)
                                {
                                    GUI.color = previousColor;
                                }
                            }
                        }

                        EditorGUI.indentLevel = stack.Count;
                    }
                }
            }
            GUILayout.Space(1); // Space for the line if the last category is closed.
        }