Ejemplo n.º 1
0
    public virtual void DoInspectorGUI()
    {
        var slotContainer = targets[0] as VFXModel;
        IEnumerable <FieldInfo> settingFields = slotContainer.GetSettings(false, VFXSettingAttribute.VisibleFlags.InInspector);

        for (int i = 1; i < targets.Length; ++i)
        {
            IEnumerable <FieldInfo> otherSettingFields = (targets[i] as VFXModel).GetSettings(false, VFXSettingAttribute.VisibleFlags.InInspector);

            settingFields = settingFields.Intersect(otherSettingFields);
        }

        foreach (var prop in settingFields.Select(t => new KeyValuePair <FieldInfo, SerializedProperty>(t, serializedObject.FindProperty(t.Name))).Where(t => t.Value != null))
        {
            var attrs = prop.Key.GetCustomAttributes(typeof(StringProviderAttribute), true);
            if (attrs.Length > 0)
            {
                var strings = StringPropertyRM.FindStringProvider(attrs)();

                int selected = prop.Value.hasMultipleDifferentValues ? -1 : System.Array.IndexOf(strings, prop.Value.stringValue);
                int result   = EditorGUILayout.Popup(ObjectNames.NicifyVariableName(prop.Value.name), selected, strings);
                if (result != selected)
                {
                    prop.Value.stringValue = strings[result];
                }
            }
            else
            {
                bool visibleChildren = EditorGUILayout.PropertyField(prop.Value);
                if (visibleChildren)
                {
                    SerializedProperty childProp = prop.Value.Copy();
                    while (childProp != null && childProp.NextVisible(visibleChildren) && childProp.propertyPath.StartsWith(prop.Value.propertyPath + "."))
                    {
                        visibleChildren = EditorGUILayout.PropertyField(childProp);
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    public virtual SerializedProperty DoInspectorGUI()
    {
        var slotContainer = targets[0] as VFXModel;
        List <VFXSetting> settingFields = slotContainer.GetSettings(false, VFXSettingAttribute.VisibleFlags.InInspector).ToList();

        for (int i = 1; i < targets.Length; ++i)
        {
            IEnumerable <VFXSetting> otherSettingFields = (targets[i] as VFXModel).GetSettings(false, VFXSettingAttribute.VisibleFlags.InInspector).ToArray();

            var excluded = new HashSet <NameNType>(settingFields.Select(t => new NameNType()
            {
                name = t.name, type = t.field.FieldType
            }).Except(otherSettingFields.Select(t => new NameNType()
            {
                name = t.name, type = t.field.FieldType
            })));
            settingFields.RemoveAll(t => excluded.Any(u => u.name == t.name));
        }

        SerializedProperty modifiedSetting = null;

        foreach (var prop in settingFields.Select(t => new KeyValuePair <VFXSetting, SerializedProperty>(t, FindProperty(t))).Where(t => t.Value != null))
        {
            var fieldInfo = prop.Key.field;
            EditorGUI.BeginChangeCheck();
            var attrs = fieldInfo.GetCustomAttributes(typeof(StringProviderAttribute), true);
            if (attrs.Length > 0)
            {
                var strings = StringPropertyRM.FindStringProvider(attrs)();

                int selected = prop.Value.hasMultipleDifferentValues ? -1 : System.Array.IndexOf(strings, prop.Value.stringValue);
                int result   = EditorGUILayout.Popup(ObjectNames.NicifyVariableName(prop.Value.name), selected, strings);
                if (result != selected)
                {
                    prop.Value.stringValue = strings[result];
                }
            }
            else if (fieldInfo.FieldType.IsEnum && fieldInfo.FieldType.GetCustomAttributes(typeof(FlagsAttribute), false).Length == 0)
            {
                GUIContent[] enumNames  = null;
                int[]        enumValues = null;

                Array      enums  = Enum.GetValues(fieldInfo.FieldType);
                List <int> values = new List <int>(enums.Length);
                for (int i = 0; i < enums.Length; ++i)
                {
                    values.Add((int)enums.GetValue(i));
                }

                foreach (var target in targets)
                {
                    VFXModel targetIte = target as VFXModel;

                    var filteredValues = targetIte.GetFilteredOutEnumerators(fieldInfo.Name);
                    if (filteredValues != null)
                    {
                        foreach (int val in filteredValues)
                        {
                            values.Remove(val);
                        }
                    }
                }
                enumNames  = values.Select(t => new GUIContent(Enum.GetName(fieldInfo.FieldType, t))).ToArray();
                enumValues = values.ToArray();

                HeaderAttribute attr = fieldInfo.GetCustomAttributes <HeaderAttribute>().FirstOrDefault();

                if (attr != null)
                {
                    GUILayout.Label(attr.header, EditorStyles.boldLabel);
                }

                EditorGUILayout.IntPopup(prop.Value, enumNames, enumValues);
            }
            else
            {
                bool visibleChildren = EditorGUILayout.PropertyField(prop.Value);
                if (visibleChildren)
                {
                    SerializedProperty childProp = prop.Value.Copy();
                    while (childProp != null && childProp.NextVisible(visibleChildren) && childProp.propertyPath.StartsWith(prop.Value.propertyPath + "."))
                    {
                        visibleChildren = EditorGUILayout.PropertyField(childProp);
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                modifiedSetting = prop.Value;
            }
        }

        return(modifiedSetting);
    }