-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnumSettableEditor.cs
89 lines (77 loc) · 2.85 KB
/
EnumSettableEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace dkstlzu.Utility
{
[CustomEditor(typeof(EnumSettableMonoBehaviour), true)]
public class EnumSettableEditor : Editor
{
SerializedProperty EnumName;
SerializedProperty EnumValue;
SerializedProperty EnumNameCorrect;
private EnumSettableMonoBehaviour GetTarget()
{
return target as EnumSettableMonoBehaviour;
}
protected virtual void OnEnable()
{
EnumName = serializedObject.FindProperty(nameof(EnumSettableMonoBehaviour.EnumName));
EnumValue = serializedObject.FindProperty(nameof(EnumSettableMonoBehaviour._EnumValue));
EnumNameCorrect = serializedObject.FindProperty(nameof(EnumSettableMonoBehaviour.EnumNameCorrect));
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EnumSettableMonoBehaviour ESM = GetTarget();
if (!EnumNameCorrect.boolValue)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(EnumName, new GUIContent("Enum Name"));
if (GUILayout.Button("Submit", GUILayout.Width(50)))
{
Type type = EnumHelper.GetEnumType(EnumName.stringValue);
if (type != null)
{
EnumNameCorrect.boolValue = true;
}
}
EditorGUILayout.EndHorizontal();
} else
{
if (!EditorApplication.isPlaying)
{
if (GUILayout.Button($"{EnumName.stringValue} : Reset enum type"))
EnumReset();
OnNotPlayingInspectorGUI();
} else
{
OnPlayingInspectorGUI();
}
OnOverridingInspectorGUI();
}
base.OnInspectorGUI();
serializedObject.ApplyModifiedProperties();
}
protected void EnumPopup()
{
if (EnumNameCorrect.boolValue)
{
EnumValue.stringValue = EditorGUILayout.EnumPopup("Enum Value", GetTarget().EnumValue).ToString();
} else
{
EditorGUILayout.LabelField("Can not get PoolEnum.");
}
}
protected void EnumReset()
{
EnumNameCorrect.boolValue = false;
EnumName.stringValue = string.Empty;
EnumValue.stringValue = string.Empty;
}
protected virtual void OnPlayingInspectorGUI() {}
protected virtual void OnNotPlayingInspectorGUI() {}
protected virtual void OnOverridingInspectorGUI() {}
}
}