Files
com.misaki.graph-view/Runtime/Models/Nodes/RelayNode.cs
Misaki d3c5968a80 Changed Slot in RelayNode to ProxySlot;
Changed PullData and PushData from SlotExtension to ISlot;

Added BackTraceExecutableNode;

Removed IExecutable from RelayNode;
2024-11-10 12:28:12 +09:00

98 lines
2.6 KiB
C#

using System;
using UnityEngine;
namespace Misaki.GraphView
{
[Serializable]
public class RelayNode : DataNode, ISlotContainer
{
[SerializeField]
private ProxySlot _inputSlot;
[SerializeField]
private ProxySlot _outputSlot;
public string portValueType;
public override void Initialize(GraphObject graph)
{
base.Initialize(graph);
_inputSlot = new(this, new SlotData
{
slotName = "Input",
nodeID = Id,
slotIndex = 0,
direction = SlotDirection.Input,
valueType = typeof(object).FullName
});
_outputSlot = new(this, new SlotData
{
slotName = "Output",
nodeID = Id,
slotIndex = 0,
direction = SlotDirection.Output,
valueType = typeof(object).FullName
});
portValueType = typeof(object).FullName;
}
/// <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;
}
}
/// <summary>
/// Unbind the slot from the relay node.
/// </summary>
/// <param name="direction"> The direction of the slot </param>
public void UnbindSlot(SlotDirection direction)
{
switch (direction)
{
case SlotDirection.Input:
_inputSlot.Unbind();
break;
case SlotDirection.Output:
_outputSlot.Unbind();
break;
}
}
public ISlot GetSlot(int index, SlotDirection direction)
{
return direction switch
{
SlotDirection.Input => _inputSlot,
SlotDirection.Output => _outputSlot,
_ => null
};
}
public void UnlinkAllSlots()
{
_inputSlot.UnlinkAll();
_outputSlot.UnlinkAll();
}
public override void Dispose()
{
base.Dispose();
_inputSlot.Unbind();
_outputSlot.Unbind();
}
}
}