mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-11 09:38:45 +08:00
Added NodeEnumDrawer.EnumPopup so you can use it from your own node editor scripts
This commit is contained in:
parent
788b8d8a0b
commit
c995bdf0bc
@ -12,6 +12,12 @@ namespace XNodeEditor {
|
|||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||||
EditorGUI.BeginProperty(position, label, property);
|
EditorGUI.BeginProperty(position, label, property);
|
||||||
|
|
||||||
|
EnumPopup(position, property, label);
|
||||||
|
|
||||||
|
EditorGUI.EndProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EnumPopup(Rect position, SerializedProperty property, GUIContent label) {
|
||||||
// Throw error on wrong type
|
// Throw error on wrong type
|
||||||
if (property.propertyType != SerializedPropertyType.Enum) {
|
if (property.propertyType != SerializedPropertyType.Enum) {
|
||||||
throw new ArgumentException("Parameter selected must be of type System.Enum");
|
throw new ArgumentException("Parameter selected must be of type System.Enum");
|
||||||
@ -39,10 +45,9 @@ namespace XNodeEditor {
|
|||||||
NodeEditorWindow.current.onLateGUI += () => ShowContextMenuAtMouse(property);
|
NodeEditorWindow.current.onLateGUI += () => ShowContextMenuAtMouse(property);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
EditorGUI.EndProperty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowContextMenuAtMouse(SerializedProperty property) {
|
private static void ShowContextMenuAtMouse(SerializedProperty property) {
|
||||||
// Initialize menu
|
// Initialize menu
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
|
|
||||||
@ -57,7 +62,7 @@ namespace XNodeEditor {
|
|||||||
menu.DropDown(r);
|
menu.DropDown(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetEnum(SerializedProperty property, int index) {
|
private static void SetEnum(SerializedProperty property, int index) {
|
||||||
property.enumValueIndex = index;
|
property.enumValueIndex = index;
|
||||||
property.serializedObject.ApplyModifiedProperties();
|
property.serializedObject.ApplyModifiedProperties();
|
||||||
property.serializedObject.Update();
|
property.serializedObject.Update();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user