mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-23 02:06:50 +08:00
More inclusive NodeEditorGUILayout
This commit is contained in:
parent
d68d926a2d
commit
ad7d9360e5
@ -8,34 +8,43 @@ namespace XNodeEditor {
|
|||||||
public static class NodeEditorGUILayout {
|
public static class NodeEditorGUILayout {
|
||||||
|
|
||||||
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
|
/// <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, params GUILayoutOption[] options) {
|
||||||
if (property == null) throw new NullReferenceException();
|
PropertyField(property, (GUIContent) null, includeChildren, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
|
||||||
|
public static void PropertyField(SerializedProperty property, GUIContent label, bool includeChildren = true, params GUILayoutOption[] options) {
|
||||||
|
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);
|
PropertyField(property, label, port, includeChildren);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Make a field for a serialized property. Manual node port override. </summary>
|
/// <summary> Make a field for a serialized property. Manual node port override. </summary>
|
||||||
public static void PropertyField(SerializedProperty property, NodePort port, bool includeChildren = true) {
|
public static void PropertyField(SerializedProperty property, NodePort port, bool includeChildren = true, params GUILayoutOption[] options) {
|
||||||
|
PropertyField(property, null, port, includeChildren, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Make a field for a serialized property. Manual node port override. </summary>
|
||||||
|
public static void PropertyField(SerializedProperty property, GUIContent label, NodePort port, bool includeChildren = true, params GUILayoutOption[] options) {
|
||||||
if (property == null) throw new NullReferenceException();
|
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, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
else {
|
else {
|
||||||
Rect rect = new Rect();
|
Rect rect = new Rect();
|
||||||
|
|
||||||
// If property is an input, display a regular property field and put a port handle on the left side
|
// If property is an input, display a regular property field and put a port handle on the left side
|
||||||
if (port.direction == NodePort.IO.Input) {
|
if (port.direction == NodePort.IO.Input) {
|
||||||
// Display a label if port is connected
|
// Display a label if port is connected
|
||||||
if (port.IsConnected) EditorGUILayout.LabelField(property.displayName);
|
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName));
|
||||||
// Display an editable property field if port is not connected
|
// Display an editable property field if port is not connected
|
||||||
else EditorGUILayout.PropertyField(property, includeChildren, GUILayout.MinWidth(30));
|
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position - new Vector2(16, 0);
|
rect.position = rect.position - new Vector2(16, 0);
|
||||||
// If property is an output, display a text label and put a port handle on the right side
|
// If property is an output, display a text label and put a port handle on the right side
|
||||||
} else if (port.direction == NodePort.IO.Output) {
|
} else if (port.direction == NodePort.IO.Output) {
|
||||||
EditorGUILayout.LabelField(property.displayName, NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position + new Vector2(rect.width, 0);
|
rect.position = rect.position + new Vector2(rect.width, 0);
|
||||||
}
|
}
|
||||||
@ -54,15 +63,15 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Make a simple port field. </summary>
|
/// <summary> Make a simple port field. </summary>
|
||||||
public static void PortField(NodePort port, params GUILayoutOption[] option) {
|
public static void PortField(NodePort port, params GUILayoutOption[] options) {
|
||||||
PortField(null, port, option);
|
PortField(null, port, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Make a simple port field. </summary>
|
/// <summary> Make a simple port field. </summary>
|
||||||
public static void PortField(GUIContent label, NodePort port, params GUILayoutOption[] option) {
|
public static void PortField(GUIContent label, NodePort port, params GUILayoutOption[] options) {
|
||||||
if (port == null) return;
|
if (port == null) return;
|
||||||
if (label == null) EditorGUILayout.LabelField(port.fieldName.PrettifyCamelCase(), option);
|
if (label == null) EditorGUILayout.LabelField(port.fieldName.PrettifyCamelCase(), options);
|
||||||
else EditorGUILayout.LabelField(label, option);
|
else EditorGUILayout.LabelField(label, options);
|
||||||
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