Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Inspector: Custom Controls Custom Editor for Items in a List

Discussion in 'Immediate Mode GUI (IMGUI)' started by failex, Jul 23, 2013.

  1. failex

    failex

    Joined:
    Jul 23, 2013
    Posts:
    2
    Problem 1

    I would like to have a control that is basically a grid of check boxes. I wouldn't mind literally using a grid of check boxes, but when doing so with this snippet
    Code (csharp):
    1.  
    2. public override void OnInspectorGUI()
    3. {
    4.     base.OnInspectorGUI();
    5.  
    6.     int rows = 3;
    7.     int cols = 2;
    8.    
    9.     GUILayout.BeginVertical();
    10.     for (int r = 0; r < rows; r++)
    11.     {
    12.         GUILayout.BeginHorizontal();
    13.         for (int c = 0; c < cols; c++)
    14.         {
    15.             GUILayout.Toggle(false, "");
    16.         }
    17.            
    18.         GUILayout.EndHorizontal();
    19.     }
    20.    
    21.     GUILayout.EndVertical();
    22. }
    23.  
    unity displays the following:
    $CheckBoxes.png

    This isn't much of a grid.

    Is there any method for authoring custom controls? I've searched the internet for a few hours but to no avail.


    Problem 2

    I would like to use the control mentioned in Problem 1 to display items in a List. I've tried making a class that derives off of Editor (and has the CustomEditor(MyType)) attribute, but this only seems to work for MonoBehaviours.
     
  2. yumupdate

    yumupdate

    Joined:
    Nov 20, 2012
    Posts:
    30
    I can only help with your first problem since I'm a bit new to all this as well. Have you tried setting the GUILayoutOptions in your GUILayout.Toggle?

    Code (csharp):
    1. GUILayout.Toggle(false, GUILayout.Width(10.0f));
    Something like that should work.
     
  3. failex

    failex

    Joined:
    Jul 23, 2013
    Posts:
    2
    Very cool, thanks.