Updated RelayNode;
Added ISlot interface; Added ProxySlot;
This commit is contained in:
@@ -9,16 +9,18 @@ namespace Misaki.GraphView
|
||||
[Serializable]
|
||||
public abstract class ExecutableNode : DataNode, ISlotContainer, IExecutable
|
||||
{
|
||||
[SerializeField]
|
||||
private List<Slot> _inputs = new();
|
||||
[SerializeField]
|
||||
private List<Slot> _outputs = new();
|
||||
|
||||
public ReadOnlyCollection<Slot> Inputs => _inputs.AsReadOnly();
|
||||
public ReadOnlyCollection<Slot> Outputs => _outputs.AsReadOnly();
|
||||
[SerializeReference]
|
||||
private List<ISlot> _inputs = new();
|
||||
[SerializeReference]
|
||||
private List<ISlot> _outputs = new();
|
||||
|
||||
private bool _isExecuted;
|
||||
|
||||
public ReadOnlyCollection<ISlot> Inputs => _inputs.AsReadOnly();
|
||||
public ReadOnlyCollection<ISlot> Outputs => _outputs.AsReadOnly();
|
||||
|
||||
public bool IsExecuted => _isExecuted;
|
||||
|
||||
public Action OnExecutionStarted;
|
||||
public Action OnExecutionCompleted;
|
||||
public Action OnExecutionFailed;
|
||||
@@ -26,8 +28,7 @@ namespace Misaki.GraphView
|
||||
|
||||
public override void Initialize(GraphObject graph)
|
||||
{
|
||||
graphObject = graph;
|
||||
|
||||
base.Initialize(graph);
|
||||
InitializeSlot();
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ namespace Misaki.GraphView
|
||||
direction = SlotDirection.Input,
|
||||
valueType = field.FieldType.FullName
|
||||
});
|
||||
AddSlot(inputSlot);
|
||||
_inputs.Add(inputSlot);
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -67,41 +68,13 @@ namespace Misaki.GraphView
|
||||
direction = SlotDirection.Output,
|
||||
valueType = field.FieldType.FullName
|
||||
});
|
||||
AddSlot(outputSlot);
|
||||
_outputs.Add(outputSlot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddSlot(Slot slot)
|
||||
{
|
||||
switch (slot.slotData.direction)
|
||||
{
|
||||
case SlotDirection.Input:
|
||||
_inputs.Add(slot);
|
||||
break;
|
||||
case SlotDirection.Output:
|
||||
_outputs.Add(slot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveSlot(Slot slot)
|
||||
{
|
||||
switch (slot.slotData.direction)
|
||||
{
|
||||
case SlotDirection.Input:
|
||||
_inputs.Remove(slot);
|
||||
break;
|
||||
case SlotDirection.Output:
|
||||
_outputs.Remove(slot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Slot GetSlot(int index, SlotDirection direction)
|
||||
public ISlot GetSlot(int index, SlotDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
@@ -163,11 +136,11 @@ namespace Misaki.GraphView
|
||||
OnExecuteFlagCleared?.Invoke();
|
||||
}
|
||||
|
||||
protected virtual void OnPullData(Slot input)
|
||||
protected virtual void OnPullData(ISlot input)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnPushData(Slot output)
|
||||
protected virtual void OnPushData(ISlot output)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView
|
||||
{
|
||||
[Serializable]
|
||||
public class RelayNode : DataNode, ISlotContainer, IExecutable
|
||||
{
|
||||
[SerializeField]
|
||||
private Slot _inputSlot;
|
||||
[SerializeField]
|
||||
private Slot _outputSlot;
|
||||
|
||||
private bool _isExecuted;
|
||||
|
||||
public bool IsExecuted => _isExecuted;
|
||||
|
||||
public string portValueType;
|
||||
|
||||
public override void Initialize(GraphObject graph)
|
||||
{
|
||||
graphObject = graph;
|
||||
base.Initialize(graph);
|
||||
|
||||
_inputSlot = new(this, new()
|
||||
_inputSlot = new Slot(this, new SlotData
|
||||
{
|
||||
slotName = "Input",
|
||||
nodeID = Id,
|
||||
@@ -25,7 +30,7 @@ namespace Misaki.GraphView
|
||||
valueType = typeof(object).FullName
|
||||
});
|
||||
|
||||
_outputSlot = new(this, new()
|
||||
_outputSlot = new Slot(this, new SlotData
|
||||
{
|
||||
slotName = "Output",
|
||||
nodeID = Id,
|
||||
@@ -37,15 +42,24 @@ namespace Misaki.GraphView
|
||||
portValueType = typeof(object).FullName;
|
||||
}
|
||||
|
||||
public void AddSlot(Slot slot)
|
||||
{
|
||||
}
|
||||
///// <summary>
|
||||
///// Bind the slot to the relay node.
|
||||
///// </summary>
|
||||
///// <param name="slot"> <see cref="ISlot"/> The slot want to bind to current relay node </param>
|
||||
//public void BindSlot(ISlot slot)
|
||||
//{
|
||||
// switch (slot.SlotData.direction)
|
||||
// {
|
||||
// case SlotDirection.Input:
|
||||
// _inputSlot.Bind(slot);
|
||||
// break;
|
||||
// case SlotDirection.Output:
|
||||
// _outputSlot.Bind(slot);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
public void RemoveSlot(Slot slot)
|
||||
{
|
||||
}
|
||||
|
||||
public Slot GetSlot(int index, SlotDirection direction)
|
||||
public ISlot GetSlot(int index, SlotDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
@@ -68,13 +82,8 @@ namespace Misaki.GraphView
|
||||
return;
|
||||
}
|
||||
|
||||
var connectedOutputNode = graphObject.GetNode(_inputSlot.LinkedSlotData[0].nodeID);
|
||||
if (connectedOutputNode is IExecutable executable)
|
||||
{
|
||||
executable.Execute();
|
||||
}
|
||||
|
||||
_outputSlot.ReceiveData(_inputSlot.value);
|
||||
_inputSlot.PullData(null);
|
||||
_outputSlot.ReceiveData(_inputSlot.Data);
|
||||
_outputSlot.PushData(null);
|
||||
|
||||
_isExecuted = true;
|
||||
|
||||
Reference in New Issue
Block a user