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

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

                    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
                                    }
                                });
                                cache[prevFold.Name].expanded = FoldManager.GetFold(prevFold.Id);
                            }
                            else
                            {
                                c.types.Add(objectFields[i].Name);
                            }
                        }
                        continue;
                    }

                    prevFold = fold;
                    fold.Id  = fold.Name + target.GetHashCode().ToString();

                    if (!cache.TryGetValue(fold.Name, out c))
                    {
                        cache.Add(fold.Name, new Cache {
                            atr = fold, types = new HashSet <string> {
                                objectFields[i].Name
                            }
                        });
                        cache[prevFold.Name].expanded = FoldManager.GetFold(fold.Id);
                    }
                    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)
                {
                    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();
            }

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

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