Search Unity

Find a Editor Gui Label and set its color

Discussion in 'Immediate Mode GUI (IMGUI)' started by sliverkf, Jul 21, 2015.

  1. sliverkf

    sliverkf

    Joined:
    Mar 10, 2014
    Posts:
    6
    Hey,

    is it possible to find out via Editor Script what Label ( GUIobject ) is selected in the Hierarchy and modify its color / backgroundcolor ?
    I search for 2 days now... :/

    i can't finger it out how to modify existing Editor GUI element.

    Thx for any tips!
     
  2. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    What you can do is to give a tag to an GUI Element and than check if it's selected.

    Code (CSharp):
    1. if (GUI.GetNameOfFocusedControl() == "numberField"){
    2.       GUI.backgroundColor = Color.blue;
    3. }
    4.  
    5. GUI.SetNextControlName("numberField");
    6. number = EditorGUILayout.FloatField(number);
    7.  
    8. GUI.backgroundColor = Color.white;
    i don't know if there's another easier way because you have to name every control you want to check for.
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    martinmr likes this.
  4. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    Ah nice thanks, haven't this yet :)
     
  5. Mish

    Mish

    Joined:
    Apr 23, 2010
    Posts:
    96
    In the case of wanting to have a different color of the text label based on which script is attached to the object, how would you assign the color based on that condition?