AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
EnumFlagsAttribute.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using System.Collections.Generic;
6 using System.Reflection;
7 #if UNITY_EDITOR
8 using UnityEditor;
9 #endif
10 
11 namespace HoloToolkit.Unity
12 {
13  // Displays an enum value as a dropdown mask
14  [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
16  {
17 #if UNITY_EDITOR
18  public override void DrawEditor(UnityEngine.Object target, FieldInfo field, SerializedProperty property)
19  {
20  int enumValue = Convert.ToInt32(field.GetValue(target));
21  List<string> displayOptions = new List<string>();
22  foreach (object value in Enum.GetValues(field.FieldType))
23  {
24  displayOptions.Add(value.ToString());
25  }
26  enumValue = EditorGUILayout.MaskField(SplitCamelCase(field.Name), enumValue, displayOptions.ToArray());
27  }
28 
29  public override void DrawEditor(UnityEngine.Object target, PropertyInfo prop)
30  {
31  int enumValue = Convert.ToInt32(prop.GetValue(target, null));
32  List<string> displayOptions = new List<string>();
33  foreach (object value in Enum.GetValues(prop.PropertyType))
34  {
35  displayOptions.Add(value.ToString());
36  }
37  enumValue = EditorGUILayout.MaskField(SplitCamelCase(prop.Name), enumValue, displayOptions.ToArray());
38  }
39 #endif
40  }
41 }