Updated RelayNode;
Added ISlot interface; Added ProxySlot;
This commit is contained in:
@@ -9,13 +9,13 @@ namespace Misaki.GraphView
|
||||
/// Unlink all slots from this slot.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to unlink all connections from.</param>
|
||||
public static void UnlinkAll(this Slot slot)
|
||||
public static void UnlinkAll(this ISlot slot)
|
||||
{
|
||||
var slotCount = slot.LinkedSlotData.Count;
|
||||
var slotCount = slot.LinkedSlotDatas.Count;
|
||||
for (var i = 0; i < slotCount; i++)
|
||||
{
|
||||
var other = slot.LinkedSlotData[i];
|
||||
var otherNode = slot.owner.GraphObject.GetNode(other.nodeID);
|
||||
var other = slot.LinkedSlotDatas[i];
|
||||
var otherNode = slot.Owner.GraphObject.GetNode(other.nodeID);
|
||||
|
||||
if (otherNode is ISlotContainer slotContainer)
|
||||
{
|
||||
@@ -34,22 +34,39 @@ namespace Misaki.GraphView
|
||||
return Type.GetType(slotData.valueType);
|
||||
}
|
||||
|
||||
public static void ReceiveData(this Slot slot, object data)
|
||||
{
|
||||
slot.value = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pull data from the slot and execute the provided action.
|
||||
/// Pull data from the slot to property and execute the provided action.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to pull data from.</param>
|
||||
/// <param name="OnPullData">The action to execute when pulling data.</param>
|
||||
public static void PullData(this Slot slot, Action<Slot> OnPullData)
|
||||
public static void PullData(this ISlot slot, Action<ISlot> OnPullData)
|
||||
{
|
||||
if (slot.SlotData.direction == SlotDirection.Output)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var slotData in slot.LinkedSlotDatas)
|
||||
{
|
||||
var node = slot.Owner.GraphObject.GetNode(slotData.nodeID);
|
||||
if (node is not IExecutable executable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!executable.IsExecuted)
|
||||
{
|
||||
executable.Execute();
|
||||
}
|
||||
}
|
||||
|
||||
OnPullData?.Invoke(slot);
|
||||
|
||||
var property = slot.owner.GetType().GetField(slot.slotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
|
||||
property?.SetValue(slot.owner, slot.value);
|
||||
var property = slot.Owner.GetType().GetField(slot.SlotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
|
||||
if (slot.IsLinked && property != null)
|
||||
{
|
||||
property?.SetValue(slot.Owner, slot.Data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,38 +74,43 @@ namespace Misaki.GraphView
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to push data to.</param>
|
||||
/// <param name="OnPushData">The action to execute when pushing data.</param>
|
||||
public static void PushData(this Slot slot, Action<Slot> OnPushData)
|
||||
public static void PushData(this ISlot slot, Action<ISlot> OnPushData)
|
||||
{
|
||||
var property = slot.owner.GetType().GetField(slot.slotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
|
||||
if (slot.SlotData.direction == SlotDirection.Input)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var property = slot.Owner.GetType().GetField(slot.SlotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
|
||||
if (property != null)
|
||||
{
|
||||
slot.value = property.GetValue(slot.owner);
|
||||
slot.ReceiveData(property.GetValue(slot.Owner));
|
||||
}
|
||||
|
||||
OnPushData?.Invoke(slot);
|
||||
|
||||
foreach (var slotData in slot.LinkedSlotData)
|
||||
foreach (var connectedSlotData in slot.LinkedSlotDatas)
|
||||
{
|
||||
var node = slot.owner.GraphObject.GetNode(slotData.nodeID);
|
||||
var node = slot.Owner.GraphObject.GetNode(connectedSlotData.nodeID);
|
||||
if (node is not ISlotContainer slotContainer)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var otherSlot = slotContainer.GetSlot(slotData.slotIndex, slotData.direction);
|
||||
var connectedSlot = slotContainer.GetSlot(connectedSlotData.slotIndex, connectedSlotData.direction);
|
||||
|
||||
if (slotData.GetValueType() == slot.slotData.GetValueType() || slot.slotData.GetValueType() == typeof(object))
|
||||
if (connectedSlotData.GetValueType() == slot.SlotData.GetValueType() || slot.SlotData.GetValueType() == typeof(object) || connectedSlotData.GetValueType() == typeof(object))
|
||||
{
|
||||
otherSlot.ReceiveData(slot.value);
|
||||
connectedSlot.ReceiveData(slot.Data);
|
||||
}
|
||||
else if (slot.owner.GraphObject.ValueConverterManager != null && slot.owner.GraphObject.ValueConverterManager.TryConvert(slot.slotData.GetValueType(),
|
||||
slotData.GetValueType(), slot.value, out var data))
|
||||
else if (slot.Owner.GraphObject.ValueConverterManager != null && slot.Owner.GraphObject.ValueConverterManager.TryConvert(slot.SlotData.GetValueType(),
|
||||
connectedSlotData.GetValueType(), slot.Data, out var data))
|
||||
{
|
||||
otherSlot.ReceiveData(data);
|
||||
connectedSlot.ReceiveData(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.owner.GraphObject.Logger?.LogError(slot.owner, $"Failed to convert value from {otherSlot.slotData.valueType} to {slotData.valueType}");
|
||||
slot.Owner.GraphObject.Logger?.LogError(slot.Owner, $"Failed to convert value from {slot.SlotData.valueType} to {connectedSlotData.valueType}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,7 +120,7 @@ namespace Misaki.GraphView
|
||||
/// </summary>
|
||||
/// <param name="slots">The collection of slots to pull data from.</param>
|
||||
/// <param name="OnPullData">The action to execute when pulling data.</param>
|
||||
public static void PullData(this IEnumerable<Slot> slots, Action<Slot> OnPullData)
|
||||
public static void PullData(this IEnumerable<ISlot> slots, Action<ISlot> OnPullData)
|
||||
{
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
@@ -111,7 +133,7 @@ namespace Misaki.GraphView
|
||||
/// </summary>
|
||||
/// <param name="slots">The collection of slots to push data to.</param>
|
||||
/// <param name="OnPushData">The action to execute when pushing data.</param>
|
||||
public static void PushData(this IEnumerable<Slot> slots, Action<Slot> OnPushData)
|
||||
public static void PushData(this IEnumerable<ISlot> slots, Action<ISlot> OnPushData)
|
||||
{
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user