mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Merge branch 'master' of https://github.com/Siccity/xNode.git into development
This commit is contained in:
commit
639680b4f2
@ -46,11 +46,11 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual int GetWidth() {
|
public virtual int GetWidth() {
|
||||||
return 200;
|
return 208;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Color GetTint() {
|
public virtual Color GetTint() {
|
||||||
Type type = GetType();
|
Type type = target.GetType();
|
||||||
if (NodeEditorWindow.nodeTint.ContainsKey(type)) return NodeEditorWindow.nodeTint[type];
|
if (NodeEditorWindow.nodeTint.ContainsKey(type)) return NodeEditorWindow.nodeTint[type];
|
||||||
else return Color.white;
|
else return Color.white;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using XNode;
|
using XNode;
|
||||||
@ -36,15 +37,54 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
// 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
|
// Get data from [Input] attribute
|
||||||
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName));
|
Node.ShowBackingValue showBacking = Node.ShowBackingValue.Unconnected;
|
||||||
// Display an editable property field if port is not connected
|
Node.InputAttribute inputAttribute;
|
||||||
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out inputAttribute)) showBacking = inputAttribute.backingValue;
|
||||||
|
|
||||||
|
switch (showBacking) {
|
||||||
|
case Node.ShowBackingValue.Unconnected:
|
||||||
|
// Display a label if port is connected
|
||||||
|
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName));
|
||||||
|
// Display an editable property field if port is not connected
|
||||||
|
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
|
break;
|
||||||
|
case Node.ShowBackingValue.Never:
|
||||||
|
// Display a label
|
||||||
|
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName));
|
||||||
|
break;
|
||||||
|
case Node.ShowBackingValue.Always:
|
||||||
|
// Display an editable property field
|
||||||
|
EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
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(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
// Get data from [Output] attribute
|
||||||
|
Node.ShowBackingValue showBacking = Node.ShowBackingValue.Unconnected;
|
||||||
|
Node.OutputAttribute outputAttribute;
|
||||||
|
if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out outputAttribute)) showBacking = outputAttribute.backingValue;
|
||||||
|
|
||||||
|
switch (showBacking) {
|
||||||
|
case Node.ShowBackingValue.Unconnected:
|
||||||
|
// Display a label if port is connected
|
||||||
|
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
||||||
|
// Display an editable property field if port is not connected
|
||||||
|
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
|
break;
|
||||||
|
case Node.ShowBackingValue.Never:
|
||||||
|
// Display a label
|
||||||
|
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
||||||
|
break;
|
||||||
|
case Node.ShowBackingValue.Always:
|
||||||
|
// Display an editable property field
|
||||||
|
EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position + new Vector2(rect.width, 0);
|
rect.position = rect.position + new Vector2(rect.width, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,11 @@ namespace XNodeEditor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool GetAttrib<T>(Type classType, string fieldName, out T attribOut) where T : Attribute {
|
||||||
|
object[] attribs = classType.GetField(fieldName).GetCustomAttributes(typeof(T), false);
|
||||||
|
return GetAttrib(attribs, out attribOut);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool HasAttrib<T>(object[] attribs) where T : Attribute {
|
public static bool HasAttrib<T>(object[] attribs) where T : Attribute {
|
||||||
for (int i = 0; i < attribs.Length; i++) {
|
for (int i = 0; i < attribs.Length; i++) {
|
||||||
if (attribs[i].GetType() == typeof(T)) {
|
if (attribs[i].GetType() == typeof(T)) {
|
||||||
|
|||||||
@ -160,8 +160,11 @@ namespace XNode {
|
|||||||
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutput(string)"/> </summary>
|
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutput(string)"/> </summary>
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||||
public class OutputAttribute : Attribute {
|
public class OutputAttribute : Attribute {
|
||||||
|
public ShowBackingValue backingValue;
|
||||||
|
|
||||||
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutput(string)"/> </summary>
|
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutput(string)"/> </summary>
|
||||||
public OutputAttribute() { }
|
/// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
|
||||||
|
public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never) { this.backingValue = backingValue; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user