Updated RelayNode;

Added ISlot interface;
Added ProxySlot;
This commit is contained in:
Misaki
2024-11-08 20:56:19 +09:00
parent e15570459c
commit 994297a3f2
22 changed files with 426 additions and 268 deletions

View File

@@ -10,10 +10,10 @@ namespace Misaki.GraphView.Editor
[CustomEditor(typeof(GraphObject))]
public class GraphObjectEditor : UnityEditor.Editor
{
private readonly Dictionary<string, List<SerializedProperty>> _inspectorPropertyMap = new ();
private readonly Dictionary<string, List<SerializedProperty>> _inspectorPropertyMap = new();
private GraphObject _graphObject;
private void OnEnable()
{
_graphObject = target as GraphObject;
@@ -41,7 +41,7 @@ namespace Misaki.GraphView.Editor
{
continue;
}
var fields = property.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
var i = _graphObject.ExposedProperties.IndexOf(property);
foreach (var field in fields)
@@ -51,12 +51,12 @@ namespace Misaki.GraphView.Editor
{
continue;
}
if (!_inspectorPropertyMap.ContainsKey(property.propertyName))
{
_inspectorPropertyMap[property.propertyName] = new ();
_inspectorPropertyMap[property.propertyName] = new();
}
_inspectorPropertyMap[property.propertyName].Add(serializedProperty);
}
}
@@ -64,12 +64,17 @@ namespace Misaki.GraphView.Editor
protected virtual VisualElement CreateInspectorProperty()
{
if (_inspectorPropertyMap.Count <= 0)
{
return null;
}
var graphPropertyFoldout = new Foldout()
{
text = "Graph Properties",
value = true
};
foreach (var property in _inspectorPropertyMap)
{
var label = new Label(property.Key)
@@ -81,7 +86,7 @@ namespace Misaki.GraphView.Editor
marginBottom = 2,
}
};
var propertyContainer = new VisualElement()
{
style =
@@ -96,7 +101,7 @@ namespace Misaki.GraphView.Editor
inputField.Bind(serializedObject);
propertyContainer.Add(inputField);
}
graphPropertyFoldout.Add(label);
graphPropertyFoldout.Add(propertyContainer);
}

View File

@@ -65,7 +65,7 @@ namespace Misaki.GraphView.Editor
if (inputs != null)
{
var inputSlots = (IList<Slot>)inputs.GetValue(_dataNode);
var inputSlots = (IList<ISlot>)inputs.GetValue(_dataNode);
if (inputSlots == null || inputSlots.Count == 0)
{
@@ -84,7 +84,7 @@ namespace Misaki.GraphView.Editor
if (outputs != null)
{
var outputSlots = (IList<Slot>)outputs.GetValue(_dataNode);
var outputSlots = (IList<ISlot>)outputs.GetValue(_dataNode);
if (outputSlots == null || outputSlots.Count == 0)
{
outputContainer.style.display = DisplayStyle.None;
@@ -163,12 +163,12 @@ namespace Misaki.GraphView.Editor
RemoveFromClassList("node-execution-failed");
}
private void CreateInputPort(Slot slot)
private void CreateInputPort(ISlot slot)
{
var valueType = Type.GetType(slot.slotData.valueType);
var valueType = Type.GetType(slot.SlotData.valueType);
var inputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, valueType);
inputPort.portName = ObjectNames.NicifyVariableName(slot.slotData.slotName);
inputPort.portName = ObjectNames.NicifyVariableName(slot.SlotData.slotName);
inputPort.portType = valueType;
inputPort.userData = slot;
if (_portColorManager != null && _portColorManager.TryGetColor(valueType, out var portColor))
@@ -180,12 +180,12 @@ namespace Misaki.GraphView.Editor
_inputPorts.Add(inputPort);
}
private void CreateOutputPort(Slot slot)
private void CreateOutputPort(ISlot slot)
{
var valueType = Type.GetType(slot.slotData.valueType);
var valueType = Type.GetType(slot.SlotData.valueType);
var outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, valueType);
outputPort.portName = ObjectNames.NicifyVariableName(slot.slotData.slotName);
outputPort.portName = ObjectNames.NicifyVariableName(slot.SlotData.slotName);
outputPort.portType = valueType;
outputPort.userData = slot;
if (_portColorManager != null && _portColorManager.TryGetColor(valueType, out var portColor))
@@ -243,9 +243,10 @@ namespace Misaki.GraphView.Editor
}
var i = graphObject.Nodes.IndexOf(_dataNode);
var nodeProperty = _serializedObject.FindProperty("_nodes")?.GetArrayElementAtIndex(i);
foreach (var field in fields)
{
var serializedProperty = _serializedObject.FindProperty("_nodes")?.GetArrayElementAtIndex(i)?.FindPropertyRelative(field.Name);
var serializedProperty = nodeProperty?.FindPropertyRelative(field.Name);
if (serializedProperty == null)
{
@@ -261,9 +262,9 @@ namespace Misaki.GraphView.Editor
if (field.GetCustomAttribute<NodeInputAttribute>() is not null)
{
if (_dataNode.Inputs.FirstOrDefault(x => x.slotData.slotName == field.Name) is { } inputSlot)
if (_dataNode.Inputs.FirstOrDefault(x => x.SlotData.slotName == field.Name) is { } inputSlot)
{
if (inputSlot.LinkedSlotData.Count > 0)
if (inputSlot.LinkedSlotDatas.Count > 0)
{
root.Add(CreateFieldForConnectedSlot(inputSlot, propertyName));
continue;
@@ -280,7 +281,7 @@ namespace Misaki.GraphView.Editor
return root;
}
protected VisualElement CreateFieldForConnectedSlot(Slot slot, string propertyName)
protected VisualElement CreateFieldForConnectedSlot(ISlot slot, string propertyName)
{
var root = new VisualElement()
{
@@ -305,7 +306,7 @@ namespace Misaki.GraphView.Editor
};
label.AddToClassList("unity-base-field__label");
var value = new Label($"Connected to {ObjectNames.NicifyVariableName(slot.LinkedSlotData[0].slotName)}");
var value = new Label($"Connected to {ObjectNames.NicifyVariableName(slot.LinkedSlotDatas[0].slotName)}");
value.AddToClassList("unity-base-field__input");
root.Add(label);

View File

@@ -39,7 +39,7 @@ namespace Misaki.GraphView.Editor
return nodeView;
}
private static Port CreateOutputPort(ExposedProperty property, Slot slot, IPortColorManager portColorManager)
private static Port CreateOutputPort(ExposedProperty property, ISlot slot, IPortColorManager portColorManager)
{
if (property == null)
{

View File

@@ -53,14 +53,18 @@ namespace Misaki.GraphView.Editor
var input = edge.input;
var output = edge.output;
if (input.userData is Slot inputSlot && output.userData is Slot outputSlot)
if (input.userData is ISlot inputSlot && output.userData is ISlot outputSlot)
{
inputSlot.Unlink(outputSlot);
input.Disconnect(edge);
output.Disconnect(edge);
//_dataNode.BindSlot(inputSlot);
//_dataNode.BindSlot(outputSlot);
inputSlot.Link(_dataNode.GetSlot(0, SlotDirection.Output), out inputConnection);
outputSlot.Link(_dataNode.GetSlot(0, SlotDirection.Input), out outputConnection);
inputSlot.Unlink(outputSlot);
_dataNode.GetSlot(0, SlotDirection.Input).Link(outputSlot, out outputConnection);
inputEdge = output.ConnectTo(_inputPort);
outputEdge = _outputPort.ConnectTo(input);