Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. 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:
    16
    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
     
    nirvanajie, guillaumeR and Eldoir like this.
  10. Eldoir

    Eldoir

    Joined:
    Feb 27, 2015
    Posts:
    20
    Thanks peteyhayman, saved my day. :)
     
  11. tylearymf

    tylearymf

    Joined:
    Apr 18, 2018
    Posts:
    3
    666666666666666