I trying to get a list and then populate a drop down menu in the editor:
using UnityEngine;
using UnityEditor;
// attach this custom inspector to all MySpecialComponent components
[CustomEditor(typeof(ButtonPressCommand))]
public class ButtonPressCommandSelector : Editor
{
public int index = 0;
string options = HelperClass.GetCommandList();
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Rect r = EditorGUILayout.BeginHorizontal();
index = EditorGUILayout.Popup("Command Selector:",
index, options, EditorStyles.popup);
EditorGUILayout.EndHorizontal();
}
}
but I get a couple of errors:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorGUIUtility.TempContent (System.String texts)
UnityEditor.EditorGUI.Popup (Rect position, System.String label, Int32 selectedIndex, System.String displayedOptions, UnityEngine.GUIStyle style)
UnityEditor.EditorGUILayout.Popup (System.String label, Int32 selectedIndex, System.String displayedOptions, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption options)
ButtonPressCommandSelector.OnInspectorGUI () (at Assets/Editor/ButtonPressCommandSelector.cs:17)
UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor editors, Boolean eyeDropperDirty)
UnityEditor.DockArea:OnGUI()
Any guess why?