- Home /
 
               Question by 
               Kwillson2 · May 30, 2017 at 03:44 PM · 
                inspectoreditorguilayoutserializedpropertyserializableserializefield  
              
 
              Custom Inspector for an array of a serialized class
Hello, I would like to have a custom inspector for a list of a serialized class. I would also like it to where based on a bool property of the class toggles other properties to show. So here is kind of what I would like in code.
 [System.Serializable]
 public class PlacementObject
 {
     [Tooltip("The Object that will be placed in the world")]
     public GameObject objectToPlace;
 
     [Tooltip("The parent that the object to place will be under")]
     public GameObject parentOfObjectToPlace;
 
     [Tooltip("Do you want to set a min and max surface size?")]
     public bool limitToMinMax = false;
 
     [Tooltip("The min size of the surface to be bounded")]
     public Vector3 minSize = new Vector3(.2f, .2f, .2f);
 
     [Tooltip("The max size of the surface to be bounded")]
     public Vector3 maxSize = new Vector3(1f, 1f, 1f);
 
     [Tooltip("Do you want to snap the object to a surface?")]
     public bool snapToSurface = false;
 
     [Tooltip("Snap to horizontal surfaces?")]
     public bool snapToHorizontalSurfaces = true;
 
     [Tooltip("Snap to vertical surfaces?")]
     public bool snapToVerticalSurfaces = false;
 
     public string[] surfaceTypes = new string[] { "Horizontal", "Vertical"};
     public enum surfaceTypesEnum { HORIZONTAL = 0, VERTICAL};
     public int surfaceTypeIndex = 0;
 }
 
 public class SpatialPlacementController : MonoBehaviour
 {
 
     [SerializeField]
     public List<PlacementObject> placementObjects;
 
 
 #if UNITY_EDITOR
 
         [CustomEditor(typeof(SpatialPlacementController))]
         [CanEditMultipleObjects]
 
         public class SceneInfoGUI : Editor
         {
             Vector2 scroll;
             override public void OnInspectorGUI()
             {
                 var myScript = target as SpatialPlacementController;
 
                 serializedObject.Update();
                 EditorGUILayout.PropertyField(serializedObject.FindProperty("placementObjects"), true);
                 serializedObject.ApplyModifiedProperties();
 
 
             // SUDO SCRIPT
             myScript.limitToMinMax = GUILayout.Toggle(myScript.limitToMinMax, new GUIContent("Limit to Min/Max", "Do you want to limit the objet to min and max surface sizes"));
             if (limitToMinMax)
             {
                    myScript.minSize = EditorGUILayout("Min Size of surface", myScript.minSize);
                   myScript.maxSize = EditorGUILayout("Max Size of surface", myScript.maxSize);
             }
 
 
             myScript.snapToSurface = GUILayout.Toggle(myScript.snapToSurface, new GUIContent("Snap to surfaces", "Do you want to snap the object to surfaces?"));
             if (snapToSurface)
             {
                 myScript.surfaceTypeIndex = GUILayout.SelectionGrid(myScript.surfaceTypeIndex, myScript.surfaceTypes, 1, EditorStyles.radioButton);
             }
 
         }
         
 #endif
 
         void Start()
         {
             // DO STUFF
         }
 
         void Update()
         {
             // DO STUFF
         }
 
         // FUNCTIONS
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                