Added RelayNodeView;

Chnaged GraphView to multiple files for better organization;
This commit is contained in:
Misaki
2024-11-05 22:46:42 +09:00
parent c853994bf5
commit 02ae77f17a
25 changed files with 863 additions and 620 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Misaki.GraphView
{
@@ -7,6 +8,7 @@ namespace Misaki.GraphView
/// <summary>
/// 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)
{
var slotCount = slot.LinkedSlotData.Count;
@@ -21,14 +23,112 @@ namespace Misaki.GraphView
}
}
}
/// <summary>
/// Get the value type of the slot data.
/// </summary>
/// <returns><see cref="Type"/> The type of the slot value </returns>
/// <param name="slotData">The slot data to get the value type from.</param>
/// <returns><see cref="Type"/> The type of the slot value.</returns>
public static Type GetValueType(this SlotData slotData)
{
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.
/// </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)
{
var property = slot.owner.GetType().GetField(slot.slotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
if (property == null)
{
return;
}
OnPullData(slot);
if (slot.LinkedSlotData.Count == 0)
{
return;
}
property.SetValue(slot.owner, slot.value);
}
/// <summary>
/// Push data to the slot and execute the provided action.
/// </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)
{
var property = slot.owner.GetType().GetField(slot.slotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
if (property == null)
{
return;
}
OnPushData(slot);
slot.value = property.GetValue(slot.owner);
foreach (var slotData in slot.LinkedSlotData)
{
var node = slot.owner.GraphObject.GetNode(slotData.nodeID);
if (node is not ISlotContainer slotContainer)
{
continue;
}
var otherSlot = slotContainer.GetSlot(slotData.slotIndex, slotData.direction);
if (slotData.GetValueType() == slot.slotData.GetValueType() || slot.slotData.GetValueType() == typeof(object))
{
otherSlot.ReceiveData(slot.value);
}
else if (slot.owner.GraphObject.ValueConverterManager != null && slot.owner.GraphObject.ValueConverterManager.TryConvert(slot.slotData.GetValueType(),
slotData.GetValueType(), slot.value, out var data))
{
otherSlot.ReceiveData(data);
}
else
{
slot.owner.GraphObject.Logger?.LogError(slot.owner, $"Failed to convert value from {otherSlot.slotData.valueType} to {slotData.valueType}");
}
}
}
/// <summary>
/// Pull data from a collection of slots and execute the provided action.
/// </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)
{
foreach (var slot in slots)
{
slot.PullData(OnPullData);
}
}
/// <summary>
/// Push data to a collection of slots and execute the provided action.
/// </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)
{
foreach (var slot in slots)
{
slot.PushData(OnPushData);
}
}
}
}