Information about the GUI skins on the Internet usually tells you to open a separate editor window and work there. However, I would like to use only some of the fonts, etc. in the basic editor component window.
GUISkin skin;
public override void OnInspectorGUI()
{
StyleInit(); //Edit the internal GUI styles of the GUI skin.
GUI.skin = skin;
base.OnInspectorGUI();
script.test = GUILayout.TextField(script.test);
}
void StyleInit()
{
skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
skin.font = font;
labelStyle = new GUIStyle(EditorStyles.label);
labelStyle.font = font;
labelStyle.fontSize = defaultFontSize;
skin.label = labelStyle;
popupStyle = new GUIStyle(EditorStyles.popup);
popupStyle.font = font;
popupStyle.fontSize = defaultFontSize;
popupStyle.fixedHeight = defaultFontSize;
textFieldStyle = new GUIStyle(EditorStyles.textField);
textFieldStyle.font = font;
textFieldStyle.fontSize = defaultFontSize;
textFieldStyle.fixedHeight = defaultFontSize + 5;
skin.textField = textFieldStyle;
buttonStyle = new GUIStyle(EditorStyles.miniButton);
buttonStyle.font = font;
buttonStyle.fontSize = defaultFontSize;
buttonStyle.fixedHeight = defaultFontSize + 10;
skin.button = buttonStyle;
checkStyle = new GUIStyle(EditorStyles.toggle);
checkStyle.font = font;
checkStyle.fontSize = defaultFontSize;
checkStyle.fixedHeight = defaultFontSize + 10;
skin.toggle = checkStyle;
boxStyle = new GUIStyle(GUI.skin.box);
boxStyle.font = font;
boxStyle.alignment = TextAnchor.UpperLeft;
boxStyle.fontSize = defaultFontSize;
skin.box = boxStyle;
submitStyle = new GUIStyle(EditorStyles.miniButton);
submitStyle.font = font;
submitStyle.fontSize = (int)(defaultFontSize * 1.5f);
submitStyle.fixedHeight = defaultFontSize * 2;
objectStyle = new GUIStyle(EditorStyles.objectField);
objectStyle.font = font;
objectStyle.fontSize = defaultFontSize;
objectStyle.fixedHeight = defaultFontSize + 5;
//boxStyle.fixedHeight = defaultFontSize + 10;
}
Here is the Edtior script for the component that wants to change the GUI skin. I created a GUI skin file in the Editor Default Resource folder as shown in this link, loaded it into EditorGUIUtility, and applied the GUI.skin attribute to my GUI skin before running the base function in OnInspectorGUI.
However, no matter what method you use, you can not control the style of the inspector that is drawn in Unity by default. (The above function called base’s OnInspectorGUI, but it did not call DrawDefaultInspector)
As you can see from the last TextField, when I manually set the TextField through the GUILayout call in the editor script, my intention was to come up without adding a separate GUIStyle. However, it is very troublesome to specify a field in the editor whenever you want to express more variables. Because of this, I want to follow the basic inspecting method of basic expression and change only some GUI style such as font.
Is this impossible? If you want to output TextFields and so on in modified fonts, is there only a way to make TextFields correspond to each other in the editor script?