Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();


            if (!initialized)
            {
                var uiTex_in    = Resources.Load <Texture2D>("IN foldout focus-6510");
                var uiTex_in_on = Resources.Load <Texture2D>("IN foldout focus on-5718");


                var c_on = Color.white;

                style = new GUIStyle(EditorStyles.foldout);

                style.overflow = new RectOffset(-10, 0, 3, 0);
                style.padding  = new RectOffset(25, 0, -3, 0);

                style.active.textColor    = c_on;
                style.active.background   = uiTex_in;
                style.onActive.textColor  = c_on;
                style.onActive.background = uiTex_in_on;

                style.focused.textColor    = c_on;
                style.focused.background   = uiTex_in;
                style.onFocused.textColor  = c_on;
                style.onFocused.background = uiTex_in_on;


                for (var i = 0; i < length; i++)
                {
                    var fold = Attribute.GetCustomAttribute(objectFields[i], typeof(FoldoutGroupAttribute)) as FoldoutGroupAttribute;

                    Cache c;
                    if (fold == null)
                    {
                        if (prevFold != null && prevFold.foldEverything)
                        {
                            if (!cache.TryGetValue(prevFold.name, out c))
                            {
                                cache.Add(prevFold.name, new Cache {
                                    atr = prevFold, types = new HashSet <string> {
                                        objectFields[i].Name
                                    }
                                });
                            }
                            else
                            {
                                c.types.Add(objectFields[i].Name);
                            }
                        }

                        continue;
                    }

                    prevFold = fold;
                    if (!cache.TryGetValue(fold.name, out c))
                    {
                        cache.Add(fold.name, new Cache {
                            atr = fold, types = new HashSet <string> {
                                objectFields[i].Name
                            }
                        });
                    }
                    else
                    {
                        c.types.Add(objectFields[i].Name);
                    }
                }


                var property = serializedObject.GetIterator();
                var next     = property.NextVisible(true);
                if (next)
                {
                    do
                    {
                        HandleProp(property);
                    } while (property.NextVisible(false));
                }
            }


            if (props.Count == 0)
            {
                DrawDefaultInspector();
                return;
            }

            initialized = true;

            using (new EditorGUI.DisabledScope("m_Script" == props[0].propertyPath))
            {
                EditorGUILayout.PropertyField(props[0], true);
            }

            EditorGUILayout.Space();

            foreach (var pair in cache)
            {
                var rect = EditorGUILayout.BeginVertical();

                EditorGUILayout.Space();

                EditorGUI.DrawRect(new Rect(rect.x - 1, rect.y - 1, rect.width + 1, rect.height + 1),
                                   colors.col0);

                EditorGUI.DrawRect(new Rect(rect.x - 1, rect.y - 1, rect.width + 1, rect.height + 1), colors.col1);


                pair.Value.expanded = EditorGUILayout.Foldout(pair.Value.expanded, pair.Value.atr.name, true,
                                                              style != null ? style : EditorStyles.foldout);


                EditorGUILayout.EndVertical();

                rect = EditorGUILayout.BeginVertical();

                EditorGUI.DrawRect(new Rect(rect.x - 1, rect.y - 1, rect.width + 1, rect.height + 1),
                                   colors.col2);

                if (pair.Value.expanded)
                {
                    EditorGUILayout.Space();
                    {
                        for (int i = 0; i < pair.Value.props.Count; i++)
                        {
                            EditorGUI.indentLevel = 1;

                            EditorGUILayout.PropertyField(pair.Value.props[i],
                                                          new GUIContent(pair.Value.props[i].name.FirstLetterToUpperCase()), true);
                            if (i == pair.Value.props.Count - 1)
                            {
                                EditorGUILayout.Space();
                            }
                        }
                    }
                }

                EditorGUI.indentLevel = 0;
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }


            for (var i = 1; i < props.Count; i++)
            {
                EditorGUILayout.PropertyField(props[i], true);
            }


            serializedObject.ApplyModifiedProperties();
            EditorGUILayout.Space();
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     props.Clear();
     types.Clear();
     atr = null;
 }