Hey there…
I´ve created a greater EditorWindow, which should be the AllInOne Editor for 4-5 Scripts of my Scene Setup Object.
So now, every of these 4-5 Scripts will get such an Inspector override attached:
[CustomEditor(typeof(Sys_Vocab))]
public class Sys_VocabEditor : Editor
{
public override void OnInspectorGUI()
{
if(GUILayout.Button("Open Vocab Editor")){
File.WriteAllText("crml.dat", (2).ToString());
EditorWindow.GetWindowWithRect(typeof(Editor_Scene_Setup), new Rect(0, 0, 800, Screen.height));
GUIUtility.ExitGUI();
}
}
}
This should open the EditorWindow, and show the Script depending Stuff by asking what ID “private int EditorFenster;” is set to.
EditorFenster is set by reading out “crml.dat”, which is filled with only the ID integer by the Inspector overrides.
The Problem:
If i open the EditorWindow via my Topmenü Setting (GameObject > Create Other > Scene_Setup), everything runs fine!
When clicking the Button in the Inspector, i get this:

Any idea what could be wrong here, and how to solve that Error Stuff?
TESTPROJECT TO REPRODUCE THE PROBLEM: link text
Vurawid
2
The error has to do with trying to show the Vocabs section right away in the EditorWindow. It is a simple enough fix. Setup the code to run through OnGUI 2 or 3 times in Editor_Scene_Setup with EditorFenster=0 prior to reading from the crml.dat file. I tested it out and the errors went away in the test project by doing this.
Updated now that I have time to share more details… here are changes I made. Also improved upon the original solution I did.
-
Removed this section of code from OnGUI: if (File.Exists("crml.dat")) { ... }
-
Added the following properties to the Editor_Scene_Setup class…
private bool m_IsInitialized = false;
private Nullable m_StartingEditorFenster = null;
public void SetStartEditorFenster(int editorFenster)
{
m_IsInitialized = false;
m_StartingEditorFenster = editorFenster;
}
-
Added the following at the end of OnGUI…
if (m_IsInitialized == true)
{
if (m_StartingEditorFenster.HasValue)
{
EditorFenster = m_StartingEditorFenster.Value;
m_StartingEditorFenster = null;
}
}
m_IsInitialized = true;
-
Changed the code in Sys_VocabEditor. Note something similar needs to be done for Sys_LanguageEditor…
public override void OnInspectorGUI()
{
if(GUILayout.Button(“Open Vocab Editor”)){
Editor_Scene_Setup thisWindow = (Editor_Scene_Setup)EditorWindow.GetWindowWithRect(typeof(Editor_Scene_Setup), new Rect(0, 0, 800, Screen.height));
thisWindow.SetStartEditorFenster (2);
GUIUtility.ExitGUI();
}
}
OKAY
Found a Solution for the ArgumentException Error.
I needed to place the File Reader as last step in OnGUI, so OnGUI runs first with EditorFenster as 0, and sets itself via File readout to the new value.