[Custom Inspector] How to keep a reference to a selecion in a drop down menu?
I created a drop down menu from an array I have in a prefab. This prefab is an AudioManager with three different arrays: one for all the sounds, one for all the musics and one for all the effects. A custom property drawer takes all the elements in an array (eg. musics array) and populates a drop down menu. Up to here everything okay: I can select a track from my menu and then the track will be played during the game. The problem comes if I add a new array element (a new track) before my selected track in the drop down menu. What happens is the menu loses the reference to the previously selected track and the new track is now selected (eg. "New Track" instead of "Forest").
How can I keep a reference to my selection?
That's the code I use to populate the drop down menu:
void DrawDropdownList(int listLenght, object list)
{
string[] listValues;
listValues = new string[listLenght];
for (int i = 0; i < listValues.Length; i++)
{
if (list.GetType() == typeof(Music[]) || list.GetType() == typeof(Sound[]))
{
Audio[] audioList = (Audio[])list;
listValues[i] = audioList[i].name;
}
}
selected.intValue = EditorGUI.Popup(enumRect, selected.intValue, listValues);
}
selected.intValue is a SerializedProperty of my object, so I guess it should keep always the same value...
Your answer
Follow this Question
Related Questions
selecting prefab from project window with Editor script 1 Answer
Spawning game objects in edit mode vanish after switching scenes 1 Answer
How to make a dropdown in Unity Editor with list from another Monobehaviour Script 0 Answers
Editor slider like "Quality Settings cascade split" 1 Answer
Editorscript: How to reference prefabs in editor not in awake or start 0 Answers