I want to do a dropdown menu that works similar to the tag system but for my sound names. However, whenever I have my custom properties in a container and I change one of them, every other property also changes.
This is my property drawer code:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(SoundName))]
public class SoundNamePropertyDrawer : PropertyDrawer
{
SoundNamesContainer _soundNamesContainer;
SerializedProperty _nameProperty;
SerializedProperty _indexProperty;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if(_nameProperty == null)
{
_nameProperty = property.FindPropertyRelative("Name");
_indexProperty = property.FindPropertyRelative("index");
}
if(_soundNamesContainer == null)
_soundNamesContainer = Resources.Load("SoundNames") as SoundNamesContainer;
EditorGUI.BeginProperty(position, label, property);
_indexProperty.intValue = EditorGUI.Popup(position, _indexProperty.intValue, _soundNamesContainer.Names);
_nameProperty.stringValue = _soundNamesContainer.Names[_indexProperty.intValue];
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight;
}
}