Tanoda
pb_EnumInspector.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
3using System.Collections.Generic;
4
5namespace GILES.Interface
6{
10 [pb_TypeInspector(typeof(System.Enum))]
11 public class pb_EnumInspector : pb_TypeInspector
12 {
13 object value;
14
15 public Text title;
16 public Dropdown dropdown;
17 string[] enumNames;
18 System.Array enumValues;
19
20 void OnGUIChanged()
21 {
22 SetValue(value);
23 }
24
25 public override void InitializeGUI()
26 {
27 title.text = GetName().SplitCamelCase();
28 if (dropdown)
29 dropdown.onValueChanged.AddListener(OnClick);
30
31 enumNames = System.Enum.GetNames(declaringType);
32 enumValues = System.Enum.GetValues(declaringType);
33 RefreshDropdown();
34 }
35
36 void OnClick(int index)
37 {
38 // cycle enum value
39 if (enumValues != null)
40 {
41 int len = enumValues.Length;
42 value = enumValues.GetValue(index);
43
44 OnGUIChanged();
45 }
46 }
47
48 protected override void OnUpdateGUI()
49 {
50 value = GetValue<object>();
51
52 RefreshDropdown();
53 }
54
55 void RefreshDropdown()
56 {
57 if (!dropdown) return;
58 dropdown.ClearOptions();
59 List<string> options = new List<string>();
60
61 for (int i = 0; i < enumValues.Length; i++)
62 {
63 options.Add(enumNames[i].ToString());
64 }
65 dropdown.AddOptions(options);
66 }
67
68
69 }
70}