AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
RangePropAttribute.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.Reflection;
6 #if UNITY_EDITOR
7 using UnityEditor;
8 #endif
9 
10 namespace HoloToolkit.Unity
11 {
12  // Displays an int or float property as a range
13  [AttributeUsage(AttributeTargets.Property)]
15  {
16 
17  public enum TypeEnum
18  {
19  Float,
20  Int,
21  }
22 
23  public float MinFloat { get; private set; }
24  public float MaxFloat { get; private set; }
25  public int MinInt { get; private set; }
26  public int MaxInt { get; private set; }
27  public TypeEnum Type { get; private set; }
28 
29  public RangePropAttribute(float min, float max)
30  {
31  MinFloat = min;
32  MaxFloat = max;
33  Type = TypeEnum.Float;
34  }
35 
36  public RangePropAttribute(int min, int max)
37  {
38  MinInt = min;
39  MaxInt = max;
40  Type = TypeEnum.Int;
41  }
42 
43 #if UNITY_EDITOR
44  public override void DrawEditor(UnityEngine.Object target, FieldInfo field, SerializedProperty property)
45  {
46  // (safe since this is property-only attribute)
47  throw new NotImplementedException();
48  }
49 
50  public override void DrawEditor(UnityEngine.Object target, PropertyInfo prop)
51  {
52  if (prop.PropertyType == typeof(int))
53  {
54  int propIntValue = (int)prop.GetValue(target, null);
55  propIntValue = EditorGUILayout.IntSlider(SplitCamelCase(prop.Name), propIntValue, MinInt, MaxInt);
56  prop.SetValue(target, propIntValue, null);
57  }
58  else if (prop.PropertyType == typeof(float))
59  {
60  float propFloatValue = (float)prop.GetValue(target, null);
61  propFloatValue = EditorGUILayout.Slider(SplitCamelCase(prop.Name), propFloatValue, MinFloat, MaxFloat);
62  prop.SetValue(target, propFloatValue, null);
63  }
64  }
65 #endif
66 
67  }
68 }