Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [System.Serializable]
- public struct MicrophoneDevice
- {
- public int id;
- public string device;
- }
- #if UNITY_EDITOR
- [CustomPropertyDrawer(typeof(MicrophoneDevice))]
- public class MicrophoneDeviceDrawer : PropertyDrawer
- {
- public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
- {
- var micDevProp = property.FindPropertyRelative("device");
- var micIdProp = property.FindPropertyRelative("id");
- int selectedIndex = 0;
- for (int i = 0; i < Microphone.devices.Length; i++)
- {
- if (micDevProp.stringValue == Microphone.devices[i])
- {
- selectedIndex = i;
- break;
- }
- }
- EditorGUI.BeginChangeCheck();
- selectedIndex = EditorGUI.Popup(position, selectedIndex, Microphone.devices);
- if (EditorGUI.EndChangeCheck())
- {
- micDevProp.stringValue = Microphone.devices[selectedIndex];
- micIdProp.intValue = selectedIndex;
- }
- property.serializedObject.ApplyModifiedProperties();
- }
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
- {
- return EditorGUIUtility.singleLineHeight;
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement