To explain the question a little better, I’m creating a custom editor window and it has a few tabs using a toolbar. I use a switch statement to delegate between which GUI is drawn on the screen. In an effort to prevent making a monolithic function for drawing all the elements in the window, I’ve attempted to delegate the gui creation to methods, however they don’t seem to be drawing the GUI at all, despite Debug.Log()'s working perfectly fine when the methods are called.
Example code of what I’m doing:
//..
using UnityEditor;
using UnityEngine;
public class ExampleWindowWithTabs : EditorWindow
{
string[] tabOptions = {"Tab 1", "Tab 2"};
int currentTab = 0;
void OnGUI()
{
int tab = GUILayout.Toolbar(currentTab, tabOptions);
this.DelegateTabs(tab);
}
void DelegateTabs(int tab)
{
if(tab != this.currentTab)
{
switch(tab)
{
case 0:
this.DisplayTabOne();
break;
case 1:
this.DisplayTabTwo();
break;
default:
break;
}
this.currentTab = tab;
}
}
void DisplayTabOne()
{
Debug.Log("Tab 1 selected");
// This doesn't work
GUILayout.Label("Tab 1 selected");
}
void DisplayTabTwo()
{
Debug.Log("Tab 2 selected");
// Neither does this.
GUILayout.Label("Tab 2 selected");
}
}
However, if i lumped all this code into the OnGUI() method instead of splitting it into separate methods, it works.
This is mildly frustrating because the editor window I’m creating will be very difficult to maintain if it all just sits in a single method. Is there any way to get this to work like I have it shown above, or am I just going to have to tough it out? Thanks for any feedback!