Search Unity

the label click event of foldout

Discussion in 'Immediate Mode GUI (IMGUI)' started by wisly, Jan 23, 2010.

  1. wisly

    wisly

    Joined:
    Jan 18, 2010
    Posts:
    12
    Now I see the function EditorGUILayout.Foldout() with which I can create a structure like a tree.
    this function returns a value of bool type.
    Then how can I catch the event when mouse is clicking on its label(the value of foldout is not changed maybe) so that I can get which one of foldout labels is clicked?

    Thanks.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    There isn't a way to get clicks in the label of a foldout, unfortunately.
     
  3. wisly

    wisly

    Joined:
    Jan 18, 2010
    Posts:
    12
    see next floor
     

    Attached Files:

  4. wisly

    wisly

    Joined:
    Jan 18, 2010
    Posts:
    12

    Thanks for reply,andeeee.

    But there should be a way to implement the function that the unity3d has already implemented in its hierarchy window as the image shown.

    can you tell me a method to do it ?
    or this maybe a function defect for unity3d need to be improved ?
     

    Attached Files:

  5. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Well, in the main scene GUI, you can check the mouse against the rectangle of a control to implement your own behaviour. However, I don't think that will work with the inspector because it could scroll and render the mouse position useless.

    You could request this as a feature with the Report Bug app if you think it would be a good addition to Unity,
     
  6. wisly

    wisly

    Joined:
    Jan 18, 2010
    Posts:
    12

    OK,I mean it.
    Thank you,andeeee.
     
  7. Dragon1995

    Dragon1995

    Joined:
    Mar 2, 2016
    Posts:
    2
    confused too.but stead way! use EditorGUIUtility.PingObject
    if (GUILayout.Button("Ping"))
    {
    EditorGUIUtility.PingObject(t.gameObject);
    Selection.activeGameObject = t.gameObject;
    }
     
  8. Kamilche_

    Kamilche_

    Joined:
    Jan 11, 2015
    Posts:
    75
    You can set the rect of the foldout. Set it narrow, like 15 pixels... then create a button to the right of it with a wider width, like 200 pixels. Catch the mouseclick on that button instead of the foldout.
     
  9. chantey

    chantey

    Joined:
    Mar 5, 2017
    Posts:
    49
    I cant speak for 2010 but in 2017 we can do it like this:

    state = EditorGUILayout.Foldout (state, title, true, EditorStyles.foldout);

    The true is for toggle on label click
     
  10. Eldoir

    Eldoir

    Joined:
    Feb 27, 2015
    Posts:
    60
    Thanks peteyhayman, saved my day. :)