| 1 | /************************************************************************************ |
| 2 | Filename : OVRNamedArrayPropertyDrawer.cs |
| 3 | Content : Adds a custom named array drawer to the Unity editor |
| 4 | Created : May 17th, 2018 |
| 5 | Copyright : Copyright Facebook Technologies, LLC and its affiliates. |
| 6 | All rights reserved. |
| 7 | |
| 8 | Licensed under the Oculus Audio SDK License Version 3.3 (the "License"); |
| 9 | you may not use the Oculus Audio SDK except in compliance with the License, |
| 10 | which is provided at the time of installation or download, or which |
| 11 | otherwise accompanies this software in either electronic or hard copy form. |
| 12 | |
| 13 | You may obtain a copy of the License at |
| 14 | |
| 15 | https://developer.oculus.com/licenses/audio-3.3/ |
| 16 | |
| 17 | Unless required by applicable law or agreed to in writing, the Oculus Audio SDK |
| 18 | distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | See the License for the specific language governing permissions and |
| 21 | limitations under the License. |
| 22 | ************************************************************************************/ |
| 23 | using UnityEngine; |
| 24 | using UnityEditor; |
| 25 | |
| 26 | // Adds a custom named array drawer to the Unity editor |
| 27 | [CustomPropertyDrawer( typeof(OVRNamedArrayAttribute) )] |
| 28 | public class OVRNamedArrayPropertyDrawer : PropertyDrawer { |
| 29 | public override void OnGUI( Rect rect, SerializedProperty property, GUIContent label ) { |
| 30 | try { |
| 31 | int pos = int.Parse(property.propertyPath.Split('[', ']')[1]); |
| 32 | EditorGUI.PropertyField( rect, property, |
| 33 | new GUIContent( ( (OVRNamedArrayAttribute)attribute ).names[pos] ) ); |
| 34 | } catch { |
| 35 | EditorGUI.PropertyField( rect, property, label ); |
| 36 | } |
| 37 | } |
| 38 | } |