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);
        }
示例#2
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);
        }
示例#3
0
        public bool CandidateExists(PropertyModification[] modifications)
        {
            if (!HasAnyCandidates())
            {
                return(false);
            }

            for (int i = 0; i < modifications.Length; ++i)
            {
                var modification = modifications[i];
                if (AnimationMode.IsPropertyCandidate(modification.target, modification.propertyPath))
                {
                    return(true);
                }
            }

            return(false);
        }
        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);
        }
        public bool CandidateExists(PropertyModification[] modifications)
        {
            bool result;

            if (!this.HasAnyCandidates())
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < modifications.Length; i++)
                {
                    PropertyModification propertyModification = modifications[i];
                    if (AnimationMode.IsPropertyCandidate(propertyModification.target, propertyModification.propertyPath))
                    {
                        result = true;
                        return(result);
                    }
                }
                result = false;
            }
            return(result);
        }
        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);
        }