I’m trying to take a value (or set of values, changes, etc.) from one EditorWindow and reflect those changes back to the editor and subsequently the object the editor is representing.
I feel like I’m missing something very fundamental and basic–and maybe its documented some place and I was just unable to find it. I’ve thumbed through the answers and glanced through some code but I didn’t find what I was looking for. There doesn’t seem to be any information that explicitly addresses this.
I suspect that I have to do one of the following:
- Have a reference to the object be passed along between Editor and EditorWindow
- Implement return callback (though I haven’t seen this model used anywhere that I could tell).
- …or rely on an event driven model to send arguments between one window and another.
If anyone could help me out in understanding the basic principal behind communication between editors, editor windows, and the objects that they represent that would be much appreciated.
Specifically, what I have is this: a behavior which has inspector elements allowing me to open a preview window for a specific type of custom asset, where upon clicking “OK” the window will dismiss itself and whatever values were set or changed in the preview window will be applied to the behavior whose editor enabled the launch of the window in the first place.
public class MyBehaviorEditor : Editor {
...
public override void OnInspectorGUI() {
...
EditorGUILayout.BeginHorizontal();
EditorGUILayout.Space();
if (GUILayout.Button("Load", GUILayout.Width(50))) {
MyBehaviorLoaderWindow window = (MyBehaviorLoaderWindow)
EditorWindow.GetWindow(typeof(MyBehaviorLoaderWindow));
}
EditorGUILayout.EndHorizontal();
}
}
and…
public class MyBehaviorLoaderWindow : EditorWindow {
...
public override void OnInspectorGUI() {
...
if (GUILayout.Button("OK", GUILayout.Width(50))) {
// What to put here to return a value back to MyBehaviorEditor, if anything?
}
}
}