Search Unity

Change editor font and font color

Discussion in 'Editor & General Support' started by Raptcha911, Feb 10, 2016.

  1. Raptcha911

    Raptcha911

    Joined:
    Sep 19, 2014
    Posts:
    24
    Hey, I'm making a plugin for untiy for which I need to change the editor font and the color of the font to match the plugin theme.
    How do I change the color & font of the text which are highlighted in this image?



    This is my code for each of them respectively -

    1 & 2-
    Code (CSharp):
    1.  batch.eventTransition.transitionType = (TransitionEvent.TransitionType)EditorGUILayout.EnumPopup("Transition Type", batch.eventTransition.transitionType);
    3-
    Code (CSharp):
    1.   GUI.Label(contentRect, new GUIContent(content.contentName, textureOnButton), newStyle);
    And the GUIStyle parameter called newStyle is setup like this -
    Code (CSharp):
    1.                         newStyle = new GUIStyle(EditorStyles.toolbarTextField);
    2.                         newStyle.fixedHeight = 30f;
    3.                         newStyle.alignment = TextAnchor.MiddleLeft;
    I have a font file in my resources folder. I just dont know how to apply it to the highlighted areas.

    Any help would be greatly appreciated !!.. Thanks in advance
     
  2. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    GUI.Color should be your friend I guess, but it's broken in 5.3.x.
     
  3. Raptcha911

    Raptcha911

    Joined:
    Sep 19, 2014
    Posts:
    24
    GUI.Color, GUI.ContentColor, GUI.backgroundColor doesnt work.. It only changes the color of thing like the enum dropdown box in the image.. And I'm using Unity 5.2.1p3..
     
  4. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Tried GUI.contentColor ? I'm pretty sure I achieved something like you want, but I've got to check my code at home later then.
     
  5. Raptcha911

    Raptcha911

    Joined:
    Sep 19, 2014
    Posts:
    24
    Yup I tried all three.. GUI.Color, GUI.ContentColor, GUI.backgroundColor.. none of them change the text color.. Changing those three colors to Color.yellow will give the below result..


    I want the text on the left to change color, not the content on the right.. I hope you got what I'm trying to achieve..
     
  6. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    The only solution I could come up with was to split the field into a label and a field.
    Some sample code -

    Code (csharp):
    1.  
    2. EditorGUILayout.BeginHorizontal();
    3. EditorGUILayout.LabelField(new GUIContent("Layer " + (i + 1)), SettingsLabel, GUILayout.Width(100));
    4. string layerName = EditorGUILayout.TextField(new GUIContent(""), Settings.layerNames[i], GUILayout.Width(Area.width - 100 - 20));
    5. EditorGUILayout.EndHorizontal();
    6.  
    I'm using the label with a custom style to change the font on the left, while using my field as usual, but without GUIContent. Then adjusting the width of each to fit.

    Hope this helps
    Dan