- Unity Documentation (EditorWindow)
- Unity Documentation (Editor Windows)
- EditorWindow Lifecycle
- List Builtin Resources/Styles
- Serialization in Unity Editor
Will stop GUI calling layout methods until next frame.
EditorGUIUtility.ExitGUI();
Serialization:
Every time you start/stop playmode, or you load/unload a scene, the editor serializes/deserialzes the editor(windows) itself. EditorWindow provides a flag (HideFlags) to avoid this behavior. Once you start splitting your code in different classes, you have to ensure all your code is serializable. You can either do that by adding [Serializable]
to your class, or derive from ScriptableObject. If you derive from ScriptableObject, ensure you set the hideFlags to HideFlags.DontSave
.
Example
using System;
using UnityEditor;
using UnityEngine;
namespace wooga.WDK.Editor
{
public class TestWindow : EditorWindow
{
public SubClass myInstance;
[MenuItem("Test Window")]
private static void ShowWindow()
{
GetWindow(typeof(TestWindow));
}
void Awake()
{
myInstance = new SubClass();
myInstance.instanceName = "TestName";
}
private void OnGUI()
{
GUILayout.Label(myInstance.instanceName);
}
}
[Serializable]
public class SubClass
{
public string instanceName;
}
}
In case you want to serialize private fields, make sure you add [SerializeField]
[Serializable]
public class SubClass
{
public string instanceName;
[SerializeField] private string instanceDescription;
}