public override void OnInspectorGUI()
        {
            style          = GUIStyles.Get("foldout");
            style.overflow = new RectOffset(-10, 0, 3, 0);
            style.padding  = new RectOffset(25, 0, -3, 0);
            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
                                    }
                                });
                            }
                            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
                    {
                        index++;
                        HandleProp(property, index);
                    } while (property.NextVisible(false));
                }
            }


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

            initialized = true;

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

            EditorGUILayout.Space();
            for (int i = 1; i < orders.Count; i++)
            {
                var order = orders[i];

                if (order.prop != null)
                {
                    EditorGUILayout.PropertyField(order.prop, true);
                }
                else
                {
                    RenderCache(cache[order.cacheID]);
                }
            }
            serializedObject.ApplyModifiedProperties();
            EditorGUILayout.Space();
        }
 public void Dispose()
 {
     props.Clear();
     types.Clear();
     atr = null;
 }