Search Unity

Building a custom inspector, a bit of confusion

Discussion in 'Scripting' started by Mike_Cona, May 11, 2010.

  1. Mike_Cona

    Mike_Cona

    Joined:
    Apr 25, 2010
    Posts:
    4
    So I've managed to create a couple of gadgets in my custom inspector for a particular component type. I'm a bit confused on how to interact with those gadgets. For example, I've managed to create a foldout but have been unable to make it's state (folded-in / folded-out) change. In this situation am I supposed to use some eventing to detect when it has been clicked and then change it's state manually? Etc. It seems that unless I say something like ((myComponentType)target).myVar = EditorGUILayout.FloatField( "MyValue", ((myComponentType)target).myVar ) the value won't update or maybe I'm confused?

    Is this the same thing I need to do with the foldouts?

    In general the documentation for custom gui work is just very lacking, and wondered if anyone could do a general breakdown for something who's a bit stupid in this arena :). Thanks in advance!
     
  2. Mike_Cona

    Mike_Cona

    Joined:
    Apr 25, 2010
    Posts:
    4
    I also forgot, I havn't been able to figure out how to put child objects inside of a foldout, this one is also very frustrating and should be clearly documented.
     
  3. Mike_Cona

    Mike_Cona

    Joined:
    Apr 25, 2010
    Posts:
    4
    *bump* could use any help or links to resources that might help :).
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    A number of GUI functions work by returning a state value which is then passed into the function again on the next OnGUI call. EditorGUI.Foldout is one such function:-
    Code (csharp):
    1. var folded: boolean;
    2.    ...
    3.  
    4. function OnGUI() {
    5.     folded = EditorGUI.Foldout(foldoutRect, folded, "Click me");
    6. }
    (This also applies to EditorGUILayout.Foldout.)

    You need to draw the contents of the foldout yourself. You can use the padding value in the GUIStyle object to create indentation for the items in the foldout.
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm finding that EditorGUILayout.Foldout works but when I switch it to EditorGUI.Foldout and include a Rect(0,0,400,20) as the first parameter, the foldout will not operate when you click on it - it stays stuck in whatever mode it was in when it was previously operated as an EditorGUILayout.Foldout.

    Is this a bug?
     
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Anyone? I can't for the life of me get this to work. I am having to resort to using EditorGUILayout for most of the gui and creating some space which is populated by a few EditorGUI calls for showing a texture. The EditorGUI.foldout just won't function.