Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

the label click event of foldout

Discussion in 'Extensions & OnGUI' 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:
    74
    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. peteyhayman

    peteyhayman

    Joined:
    Mar 5, 2017
    Posts:
    17
    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:
    23
    Thanks peteyhayman, saved my day. :)
     
  11. tylearymf

    tylearymf

    Joined:
    Apr 18, 2018
    Posts:
    4
    666666666666666