So I was creating a tool and I wanted to have a group of buttons behave like tabs.
GUIContent content = new GUIContent();
GUIStyle MiniLeft = EditorStyles.miniButtonLeft;
GUIStyle MiniMid = EditorStyles.miniButtonMid;
GUIStyle MiniRight = EditorStyles.miniButtonRight;
GUILayoutOption[] buttonWidth = new GUILayoutOption[]
{
GUILayout.MinWidth (50),
GUILayout.ExpandWidth (false),
};
public void OnGUI()
{
GUILayout.BeginHorizontal ();
content.text = "Enemies";
content.tooltip="Edit enemies that will spawn in this level";
MiniLeft.fontStyle = (TabState == 0)?FontStyle.Bold:FontStyle.Normal;
if (GUILayout.Button (content,MiniLeft, buttonWidth))
{
GUI.FocusControl("");
TabState = 0;
}
content.text = "Defenses";
content.tooltip="Edit what defenses you can build this level";
MiniMid.fontStyle = (TabState == 1)?FontStyle.Bold:FontStyle.Normal;
if (GUILayout.Button (content,MiniMid, buttonWidth))
{
GUI.FocusControl("");
TabState = 1;
}
content.text = "Spell";
content.tooltip="Edit what spells you can cast this level";
MiniRight.fontStyle = (TabState == 2)?FontStyle.Bold:FontStyle.Normal;
if (GUILayout.Button (content,MiniRight, buttonWidth))
{
GUI.FocusControl("");
TabState = 2;
}
GUILayout.EndHorizontal ();
TabState = Mathf.Clamp(TabState,0,2);
subWindows[TabState].OnGUI();
}
I assumed a line like GUIStyle MiniLeft = EditorStyles.miniButtonLeft;
would simply get me a copy of the style as a new instance (similar to Vector3.one;
), but the documention didn’t clarify this.
I’ve promptly switched my code to GUIStyle MiniLeft = new GUIStyle (EditorStyles.miniButtonLeft);
however it seems the damage as already been done, it directly altered the style settings. so every time when I render the window I get errors like this:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorStyles.get_miniButtonLeft () (at C:/buildslave/unity/build/Editor/Mono/GUI/EditorStyles.cs:69)
ChamberEditor..ctor ()
UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String)
UnityEditor.WindowLayout:LoadWindowLayout(String, Boolean)
I get roughly 6 to 10 copies of that error every time the OnGUI is called and the window blanks out. I assume its a file that needs to be deleted/reverted in the Project settings and let unity remake it but I’m unsure exactly which. I would really prefer not to delete the entire folder cause resetting other settings like collision layers becomes a chore.
I am using Unity Pro version 5.1.1f1
So the question is:
Is there a way to revert back to the default EditorStyles settings?