-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace PeartreeGames.Topiary.Unity.Editor | ||
{ | ||
[CustomPropertyDrawer(typeof(TopiEnumReference))] | ||
public class TopiEnumReferenceDrawer : PropertyDrawer | ||
{ | ||
public override VisualElement CreatePropertyGUI(SerializedProperty property) | ||
{ | ||
var enumObjectProperty = property.FindPropertyRelative("enumObject"); | ||
var enumValueProperty = property.FindPropertyRelative("enumValue"); | ||
|
||
var enumObjField = new PropertyField(enumObjectProperty); | ||
var dropdownField = new PopupField<string>("Value", new List<string>(), 0); | ||
|
||
enumObjField.RegisterCallback<ChangeEvent<Object>>(evt => | ||
{ | ||
var enumObject = enumObjectProperty.objectReferenceValue as TopiEnumObject; | ||
if (enumObject == null) return; | ||
|
||
dropdownField.choices.Clear(); | ||
dropdownField.choices.AddRange(enumObject.Values); | ||
dropdownField.value = enumValueProperty.stringValue; | ||
}); | ||
|
||
dropdownField.RegisterCallback<ChangeEvent<string>>(evt => | ||
{ | ||
enumValueProperty.stringValue = evt.newValue; | ||
property.serializedObject.ApplyModifiedProperties(); | ||
|
||
if (enumValueProperty.serializedObject.targetObject is { } targetObject) | ||
{ | ||
EditorUtility.SetDirty(targetObject); | ||
} | ||
}); | ||
|
||
var elem = new VisualElement(); | ||
elem.Add(enumObjField); | ||
elem.Add(dropdownField); | ||
|
||
return elem; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.