Foldable Inspector
A utility for use in editors that group properties

Skills

Unity Editor C#

Software Used

Unity JetBrains Rider Photoshop

About

The purpose of this editor is to provide a class that helps organize inspector editors, not a field attribute. With this class you can create foldable sections quickly. An organized inspector is always required when working with classes with many serialized variables to the editor, such as a player, which has several and many variables that are desirably exposed to game designers. With these sections the search for the fields is much faster. and the inspector is well organized.


Images

Fold

Fold


Fold

Foldout


Usage Example

 1    usingUnityEngine;
 2   
 3    public classPlayer:MonoBehaviour
 4    {
 5       [SerializeField]privateColor_hairColor;
 6    }
 1    usingUnityEngine;
 2    usingUnityEditor;
 3   
 4    [CustomEditor(typeof(Player))]
 5    public classPlayerEditor:Editor
 6    {
 7       //-------------------------------------------------------------------------------------------------
 8       // Non-Serialized Fields
 9       //-------------------------------------------------------------------------------------------------
10       privateSerializedProperty_hairColorProperty;
11      
12       //-------------------------------------------------------------------------------------------------
13       // Properties
14       //-------------------------------------------------------------------------------------------------
15       private staticTexture2D_customIcon;
16       private staticTexture2DCustomIcon;
17       {
18         get
19         {
20           if(_customIcon == null)
21           {
22             _customIcon = Resources.Load<Texture2D>("ic-plus");
23           }
24           return_customIcon
25         }
26       }
27      
28       //-------------------------------------------------------------------------------------------------
29       // Unity Events
30       //-------------------------------------------------------------------------------------------------
31       private voidOnEnable()
32       {
33         _hairColorProperty=serializedObject.FindProperty("_hairColor");
34       }
35   
36       private override voidOnInspectorGUI()
37       {
38         FoldableInspector.DrawSection(_hairColorProperty.GetHashCode().ToString(),"SETTINGS", () =>
39         {
40           EditorGUILayout.PropertyField(_hairColorProperty);
41         }, CustomIcon);
42        
43         serializedObject.ApplyModifiedProperties();
44       }
45    }