Documentation for the Unity C# Library
Loading...
Searching...
No Matches
EndpointAttributeDrawer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEditor;
5using UnityEngine;
6
7namespace PixoVR.Apex
8{
10 {
11 public List<string> enumDisplayList = new List<string>();
12 public List<PlatformServer> enumList = new List<PlatformServer>();
13
15 {
16 enumList = Enum.GetValues(typeof(PlatformServer)).Cast<PlatformServer>().ToList();
17
18 foreach(PlatformServer enumItem in enumList)
19 {
20 enumDisplayList.Add(enumItem.ToDisplayString());
21 }
22 }
23 }
24#if UNITY_EDITOR
25 [CustomPropertyDrawer(typeof(EndpointDisplayAttribute))]
26 public class EndpointDisplayDrawer : PropertyDrawer
27 {
28 [SerializeField]
29 int selectedIndex = -1;
30
31 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
32 {
33 EndpointDisplayAttribute displayAttribute = attribute as EndpointDisplayAttribute;
34
35 if (displayAttribute.enumDisplayList.Count > 0)
36 {
37 int newIndex = EditorGUI.Popup(position, property.name, selectedIndex, displayAttribute.enumDisplayList.ToArray());
38 if (newIndex < 0)
39 {
40 newIndex = property.enumValueIndex;
41 }
42
43 if (newIndex != selectedIndex)
44 {
45 selectedIndex = newIndex;
46 property.enumValueIndex = selectedIndex;
47 UnityEngine.Object dirtyObject = property.serializedObject.targetObject;
48
49 if (dirtyObject != null)
50 {
51 Debug.Log("Selected Index: " + selectedIndex);
52 EditorUtility.SetDirty(dirtyObject);
53 }
54 }
55 }
56 else
57 {
58 Debug.Log("Reset");
59 EditorGUI.PropertyField(position, property, label);
60 }
61 }
62 }
63#endif
64}