public static                VFXParameterInfo[] BuildParameterInfo(VFXGraph graph)
        {
            var categories = graph.UIInfos.categories;

            if (categories == null)
            {
                categories = new List <VFXUI.CategoryInfo>();
            }


            var parameters = graph.children.OfType <VFXParameter>().Where(t => t.exposed && (string.IsNullOrEmpty(t.category) || !categories.Any(u => u.name == t.category)) && !t.isOutput).OrderBy(t => t.order).ToArray();

            var infos = new List <VFXParameterInfo>();

            BuildCategoryParameterInfo(parameters, infos);

            foreach (var cat in categories)
            {
                parameters = graph.children.OfType <VFXParameter>().Where(t => t.exposed && t.category == cat.name && !t.isOutput).OrderBy(t => t.order).ToArray();
                if (parameters.Length > 0)
                {
                    VFXParameterInfo paramInfo = new VFXParameterInfo(cat.name, "");

                    paramInfo.descendantCount = 0;
                    infos.Add(paramInfo);
                    BuildCategoryParameterInfo(parameters, infos);
                }
            }


            return(infos.ToArray());
        }
        SerializedProperty GetFakeProperty(ref VFXParameterInfo parameter)
        {
            if (parameter.defaultValue == null)
            {
                return(null);
            }
            Type type = parameter.defaultValue.type;

            if (type == null)
            {
                return(null);
            }

            if (typeof(float) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aFloat"));
            }
            else if (typeof(Vector2) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aVector2"));
            }
            else if (typeof(Vector3) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aVector3"));
            }
            else if (typeof(Vector4) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aVector4"));
            }
            else if (typeof(Color) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aColor"));
            }
            else if (typeof(Gradient) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aGradient"));
            }
            else if (typeof(AnimationCurve) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("anAnimationCurve"));
            }
            else if (typeof(UnityObject).IsAssignableFrom(type))
            {
                return(s_FakeObjectSerializedCache.FindProperty("anObject"));
            }
            else if (typeof(int) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("anInt"));
            }
            else if (typeof(uint) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("anUInt"));
            }
            else if (typeof(bool) == type)
            {
                return(s_FakeObjectSerializedCache.FindProperty("aBool"));
            }

            return(null);
        }
        static int RecurseBuildParameterInfo(List <VFXParameterInfo> infos, System.Type type, string path, object obj)
        {
            if (!type.IsValueType)
            {
                return(0);
            }

            int count  = 0;
            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

            var subList = new List <VFXParameterInfo>();

            foreach (var field in fields)
            {
                var info   = new VFXParameterInfo(field.Name, field.FieldType.Name);
                var subObj = field.GetValue(obj);

                info.path = path + "_" + field.Name;

                var tooltip = field.GetCustomAttributes(typeof(TooltipAttribute), true).FirstOrDefault() as TooltipAttribute;
                if (tooltip != null)
                {
                    info.tooltip = tooltip.tooltip;
                }

                var fieldName = VisualEffectSerializationUtility.GetTypeField(field.FieldType);

                if (fieldName != null)
                {
                    info.sheetType = fieldName;
                    RangeAttribute attr = field.GetCustomAttributes(true).OfType <RangeAttribute>().FirstOrDefault();
                    if (attr != null)
                    {
                        info.min = attr.min;
                        info.max = attr.max;
                    }
                    info.descendantCount = 0;
                    info.defaultValue    = new VFXSerializableObject(field.FieldType, subObj);
                }
                else
                {
                    if (field.FieldType == typeof(VFXCoordinateSpace)) // For space
                    {
                        continue;
                    }
                    info.descendantCount = RecurseBuildParameterInfo(subList, field.FieldType, info.path, subObj);
                }
                infos.Add(info);
                infos.AddRange(subList);
                subList.Clear();
                count++;
            }
            return(count);
        }
Exemplo n.º 4
0
        static private bool GenerateMultipleField(ref VFXParameterInfo parameter, SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.Vector4 && parameter.realType != typeof(Color).Name)
            {
                return(true);
            }
            else if (property.propertyType == SerializedPropertyType.Vector3 || property.propertyType == SerializedPropertyType.Vector2)
            {
                return(true);
            }

            return(false);
        }
        static void BuildCategoryParameterInfo(VFXParameter[] parameters, List <VFXParameterInfo> infos)
        {
            var subList = new List <VFXParameterInfo>();

            foreach (var parameter in parameters)
            {
                string rootFieldName = VisualEffectSerializationUtility.GetTypeField(parameter.type);

                VFXParameterInfo paramInfo = new VFXParameterInfo(parameter.exposedName, parameter.type.Name);
                paramInfo.tooltip = parameter.tooltip;
                if (rootFieldName != null)
                {
                    paramInfo.sheetType = rootFieldName;
                    paramInfo.path      = paramInfo.name;
                    if (parameter.valueFilter == VFXValueFilter.Range)
                    {
                        float min = (float)System.Convert.ChangeType(parameter.min, typeof(float));
                        float max = (float)System.Convert.ChangeType(parameter.max, typeof(float));
                        paramInfo.min = min;
                        paramInfo.max = max;
                    }
                    else if (parameter.valueFilter == VFXValueFilter.Enum)
                    {
                        paramInfo.enumValues = parameter.enumValues.ToList();
                    }
                    paramInfo.defaultValue = new VFXSerializableObject(parameter.type, parameter.value);

                    paramInfo.descendantCount = 0;
                }
                else
                {
                    paramInfo.descendantCount = RecurseBuildParameterInfo(subList, parameter.type, parameter.exposedName, parameter.value);
                }


                infos.Add(paramInfo);
                infos.AddRange(subList);
                subList.Clear();
            }
        }
Exemplo n.º 6
0
 public void BuildParameterInfo()
 {
     m_ParameterInfo = VFXParameterInfo.BuildParameterInfo(this);
     VisualEffectEditor.RepaintAllEditors();
 }
        static void DisplayProperty(ref VFXParameterInfo parameter, GUIContent nameContent, SerializedProperty overridenProperty, SerializedProperty valueProperty, bool animated)
        {
            EditorGUILayout.BeginHorizontal();

            Color previousColor = GUI.color;

            if (animated)
            {
                GUI.color = AnimationMode.animatedPropertyColor;
            }

            overridenProperty.boolValue = EditorGUILayout.Toggle(overridenProperty.hasMultipleDifferentValues ? false : overridenProperty.boolValue, overridenProperty.hasMultipleDifferentValues ? Styles.toggleMixedStyle : Styles.toggleStyle, GUILayout.Width(overrideWidth));
            if (parameter.min != Mathf.NegativeInfinity && parameter.max != Mathf.Infinity)
            {
                if (valueProperty.propertyType == SerializedPropertyType.Float)
                {
                    EditorGUILayout.Slider(valueProperty, parameter.min, parameter.max, nameContent);
                }
                else
                {
                    EditorGUILayout.IntSlider(valueProperty, (int)parameter.min, (int)parameter.max, nameContent);
                }
            }
            else if (parameter.realType == typeof(Color).Name)
            {
                Vector4 vVal = valueProperty.vector4Value;
                Color   c    = new Color(vVal.x, vVal.y, vVal.z, vVal.w);
                c = EditorGUILayout.ColorField(nameContent, c, true, true, true);

                if (GUI.changed)
                {
                    valueProperty.vector4Value = new Vector4(c.r, c.g, c.b, c.a);
                }
            }
            else if (parameter.realType == typeof(Gradient).Name)
            {
                Gradient newGradient = EditorGUILayout.GradientField(nameContent, valueProperty.gradientValue, true);

                if (GUI.changed)
                {
                    valueProperty.gradientValue = newGradient;
                }
            }
            else if (valueProperty.propertyType == SerializedPropertyType.Vector4)
            {
                var oldVal = valueProperty.vector4Value;
                var newVal = EditorGUILayout.Vector4Field(nameContent, oldVal);
                if (oldVal.x != newVal.x || oldVal.y != newVal.y || oldVal.z != newVal.z || oldVal.w != newVal.w)
                {
                    valueProperty.vector4Value = newVal;
                }
            }
            else if (valueProperty.propertyType == SerializedPropertyType.ObjectReference)
            {
                Type objTyp = typeof(UnityObject);
                if (!string.IsNullOrEmpty(parameter.realType))
                {
                    if (parameter.realType.StartsWith("Texture") || parameter.realType.StartsWith("Cubemap"))
                    {
                        objTyp = typeof(Texture);
                    }
                    else if (parameter.realType == "Mesh")
                    {
                        objTyp = typeof(Mesh);
                    }
                }
                Rect r = EditorGUILayout.GetControlRect(true, EditorGUI.kSingleLineHeight, EditorStyles.objectField, null);
                EditorGUI.ObjectField(r, valueProperty, objTyp, nameContent);
            }
            else
            {
                EditorGUILayout.PropertyField(valueProperty, nameContent, true);
            }

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

            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 8
0
        static void DisplayProperty(ref VFXParameterInfo parameter, GUIContent nameContent, SerializedProperty overridenProperty, SerializedProperty valueProperty)
        {
            EditorGUILayout.BeginHorizontal();

            var height = 16f;

            if (EditorGUIUtility.currentViewWidth < 333f && GenerateMultipleField(ref parameter, valueProperty))
            {
                height *= 2.0f;
            }

            var rect = EditorGUILayout.GetControlRect(false, height);

            var toggleRect = rect;

            toggleRect.yMin            += 3.0f;
            toggleRect.width            = 18;
            overridenProperty.boolValue = EditorGUI.Toggle(toggleRect, overridenProperty.hasMultipleDifferentValues ? false : overridenProperty.boolValue, overridenProperty.hasMultipleDifferentValues ? Styles.toggleMixedStyle : Styles.toggleStyle);
            rect.xMin += overrideWidth;

            EditorGUI.BeginProperty(rect, nameContent, valueProperty);

            if (parameter.min != Mathf.NegativeInfinity && parameter.max != Mathf.Infinity)
            {
                if (valueProperty.propertyType == SerializedPropertyType.Float)
                {
                    EditorGUI.Slider(rect, valueProperty, parameter.min, parameter.max, nameContent);
                }
                else
                {
                    EditorGUI.IntSlider(rect, valueProperty, (int)parameter.min, (int)parameter.max, nameContent);
                }
            }
            else if (parameter.realType == typeof(Color).Name)
            {
                Vector4 vVal = valueProperty.vector4Value;
                Color   c    = new Color(vVal.x, vVal.y, vVal.z, vVal.w);
                c = EditorGUI.ColorField(rect, nameContent, c, true, true, true);

                if (GUI.changed)
                {
                    valueProperty.vector4Value = new Vector4(c.r, c.g, c.b, c.a);
                }
            }
            else if (parameter.realType == typeof(Gradient).Name)
            {
                Gradient newGradient = EditorGUI.GradientField(rect, nameContent, valueProperty.gradientValue, true);

                if (GUI.changed)
                {
                    valueProperty.gradientValue = newGradient;
                }
            }
            else if (valueProperty.propertyType == SerializedPropertyType.Vector4)
            {
                SerializedProperty copy = valueProperty.Copy();
                copy.Next(true);
                EditorGUI.MultiPropertyField(rect, new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") }, copy, nameContent);
            }
            else if (valueProperty.propertyType == SerializedPropertyType.ObjectReference)
            {
                Type objTyp = typeof(UnityObject);
                if (!string.IsNullOrEmpty(parameter.realType))
                {
                    if (parameter.realType.StartsWith("Texture") || parameter.realType.StartsWith("Cubemap"))
                    {
                        objTyp = typeof(Texture);
                    }
                    else if (parameter.realType == "Mesh")
                    {
                        objTyp = typeof(Mesh);
                    }
                }
                EditorGUI.ObjectField(rect, valueProperty, objTyp, nameContent);
            }
            else
            {
                EditorGUI.PropertyField(rect, valueProperty, nameContent, true);
            }

            EditorGUI.EndProperty();
            EditorGUILayout.EndHorizontal();
        }
        void DisplayProperty(ref VFXParameterInfo parameter, SerializedProperty overrideProperty, SerializedProperty property)
        {
            EditorGUILayout.BeginHorizontal();

            GUIContent nameContent = GetGUIContent(parameter.name, parameter.tooltip);

            EditorGUI.BeginChangeCheck();
            bool result = EditorGUILayout.Toggle(overrideProperty.hasMultipleDifferentValues ? false : overrideProperty.boolValue, overrideProperty.hasMultipleDifferentValues ? Styles.toggleMixedStyle : Styles.toggleStyle, GUILayout.Width(overrideWidth));

            if (EditorGUI.EndChangeCheck())
            {
                overrideProperty.boolValue = result;
            }

            SerializedProperty originalProperty = property;

            if (!overrideProperty.boolValue)
            {
                s_FakeObjectSerializedCache.Update();
                property = s_FakeObjectSerializedCache.FindProperty(originalProperty.propertyPath);
                if (property != null)
                {
                    SetObjectValue(property, parameter.defaultValue.Get());
                }
            }

            if (property != null)
            {
                EditorGUI.BeginChangeCheck();
                if (parameter.min != Mathf.NegativeInfinity && parameter.max != Mathf.Infinity)
                {
                    if (property.propertyType == SerializedPropertyType.Float)
                    {
                        EditorGUILayout.Slider(property, parameter.min, parameter.max, nameContent);
                    }
                    else
                    {
                        EditorGUILayout.IntSlider(property, (int)parameter.min, (int)parameter.max, nameContent);
                    }
                }
                else if (parameter.realType == typeof(Color).Name)
                {
                    Vector4 vVal = property.vector4Value;
                    Color   c    = new Color(vVal.x, vVal.y, vVal.z, vVal.w);
                    c = EditorGUILayout.ColorField(nameContent, c, true, true, true);

                    if (GUI.changed)
                    {
                        property.vector4Value = new Vector4(c.r, c.g, c.b, c.a);
                    }
                }
                else if (parameter.realType == typeof(Gradient).Name)
                {
                    Gradient newGradient = EditorGUILayout.GradientField(nameContent, property.gradientValue, true);

                    if (GUI.changed)
                    {
                        property.gradientValue = newGradient;
                    }
                }
                else if (property.propertyType == SerializedPropertyType.Vector4)
                {
                    var oldVal = property.vector4Value;
                    var newVal = EditorGUILayout.Vector4Field(nameContent, oldVal);
                    if (oldVal.x != newVal.x || oldVal.y != newVal.y || oldVal.z != newVal.z || oldVal.w != newVal.w)
                    {
                        property.vector4Value = newVal;
                    }
                }
                else if (property.propertyType == SerializedPropertyType.ObjectReference)
                {
                    Type objTyp = typeof(UnityObject);
                    if (!string.IsNullOrEmpty(parameter.realType))
                    {
                        if (parameter.realType.StartsWith("Texture") || parameter.realType.StartsWith("Cubemap"))
                        {
                            objTyp = typeof(Texture);
                        }
                        else if (parameter.realType == "Mesh")
                        {
                            objTyp = typeof(Mesh);
                        }
                    }
                    Rect r = EditorGUILayout.GetControlRect(true, EditorGUI.kSingleLineHeight, EditorStyles.objectField, null);
                    EditorGUI.ObjectField(r, property, objTyp, nameContent);
                }
                else
                {
                    EditorGUILayout.PropertyField(property, nameContent, true);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    if (overrideProperty.boolValue == false)
                    {
                        if (originalProperty.propertyType == property.propertyType)
                        {
                            SetObjectValue(originalProperty, GetObjectValue(property));
                        }
                        overrideProperty.boolValue = true;
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
            EditorGUILayout.EndHorizontal();
        }