I'm implementing a simple level editor that functions in the scene view. For the most part it's working fine, but there seem to be some controls that, while they work correctly in OnInspectorGUI(), don't work correctly in OnSceneGUI().
The two controls I'm having trouble with are Popup() and ColorField(). It seems that with these controls, the selected value is not returned to the caller when the control is used in OnSceneGUI().
Here's the code I'm using to test this:
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor
{
int selected = 0;
Color color = Color.white;
void OnSceneGUI()
{
if (Event.current.type == EventType.Layout) {
HandleUtility.AddDefaultControl(
GUIUtility.GetControlID(FocusType.Passive));
}
Handles.BeginGUI();
selected = EditorGUILayout.Popup(
selected, new string[] { "0", "1", "2" });
color = EditorGUILayout.ColorField(color);
Handles.EndGUI();
}
}
The value returned is always the initial value (0 and Color.white, respectively), regardless of what's selected in the control.
Should these functions be expected to work in this context? Can anyone see any obvious problems with the example code above?