mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-08 08:14:54 +08:00
More NodeEditorGUILayout options
This commit is contained in:
parent
4f65fcefc6
commit
dca06edd97
@ -7,10 +7,18 @@ namespace XNodeEditor {
|
|||||||
/// <summary> UNEC-specific version of <see cref="EditorGUILayout"/> </summary>
|
/// <summary> UNEC-specific version of <see cref="EditorGUILayout"/> </summary>
|
||||||
public static class NodeEditorGUILayout {
|
public static class NodeEditorGUILayout {
|
||||||
|
|
||||||
|
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
|
||||||
public static void PropertyField(SerializedProperty property, bool includeChildren = true) {
|
public static void PropertyField(SerializedProperty property, bool includeChildren = true) {
|
||||||
if (property == null) throw new NullReferenceException();
|
if (property == null) throw new NullReferenceException();
|
||||||
|
|
||||||
Node node = property.serializedObject.targetObject as Node;
|
Node node = property.serializedObject.targetObject as Node;
|
||||||
NodePort port = node.GetPort(property.name);
|
NodePort port = node.GetPort(property.name);
|
||||||
|
PropertyField(property, port, includeChildren);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Make a field for a serialized property. Manual node port override. </summary>
|
||||||
|
public static void PropertyField(SerializedProperty property, NodePort port, bool includeChildren = true) {
|
||||||
|
if (property == null) throw new NullReferenceException();
|
||||||
|
|
||||||
// If property is not a port, display a regular property field
|
// If property is not a port, display a regular property field
|
||||||
if (port == null) EditorGUILayout.PropertyField(property, includeChildren, GUILayout.MinWidth(30));
|
if (port == null) EditorGUILayout.PropertyField(property, includeChildren, GUILayout.MinWidth(30));
|
||||||
@ -44,9 +52,13 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void PortField(NodePort port) {
|
public static void PortField(NodePort port) {
|
||||||
if (port == null) return;
|
PortField(null, port);
|
||||||
EditorGUILayout.LabelField(port.fieldName.PrettifyCamelCase(), GUILayout.MinWidth(30));
|
}
|
||||||
|
|
||||||
|
public static void PortField(GUIContent label, NodePort port) {
|
||||||
|
if (port == null) return;
|
||||||
|
if (label == null) EditorGUILayout.LabelField(port.fieldName.PrettifyCamelCase(), GUILayout.MinWidth(30));
|
||||||
|
else EditorGUILayout.LabelField(label, GUILayout.MinWidth(30));
|
||||||
Rect rect = GUILayoutUtility.GetLastRect();
|
Rect rect = GUILayoutUtility.GetLastRect();
|
||||||
if (port.direction == NodePort.IO.Input) rect.position = rect.position - new Vector2(16, 0);
|
if (port.direction == NodePort.IO.Input) rect.position = rect.position - new Vector2(16, 0);
|
||||||
else if (port.direction == NodePort.IO.Output) rect.position = rect.position + new Vector2(rect.width, 0);
|
else if (port.direction == NodePort.IO.Output) rect.position = rect.position + new Vector2(rect.width, 0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user