Updated RelayNode;
Added ISlot interface; Added ProxySlot;
This commit is contained in:
@@ -109,16 +109,16 @@ namespace Misaki.GraphView
|
||||
_connections.Remove(connection);
|
||||
}
|
||||
|
||||
public void RemoveAllConnectionsForSlot(Slot slot)
|
||||
public void RemoveAllConnectionsForSlot(ISlot slot)
|
||||
{
|
||||
_connections.RemoveAll(connection =>
|
||||
connection.InputSlotData == slot.slotData || connection.OutputSlotData == slot.slotData);
|
||||
connection.InputSlotData == slot.SlotData || connection.OutputSlotData == slot.SlotData);
|
||||
}
|
||||
|
||||
public SlotConnection TryGetConnection(Slot input, Slot output)
|
||||
public SlotConnection TryGetConnection(ISlot input, ISlot output)
|
||||
{
|
||||
return _connections.FirstOrDefault(connection =>
|
||||
connection.InputSlotData == input.slotData && connection.OutputSlotData == output.slotData);
|
||||
connection.InputSlotData == input.SlotData && connection.OutputSlotData == output.SlotData);
|
||||
}
|
||||
|
||||
public void AddExposedProperty(ExposedProperty property)
|
||||
|
||||
@@ -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;
|
||||
|
||||
44
Runtime/Models/Slots/ProxySlot.cs
Normal file
44
Runtime/Models/Slots/ProxySlot.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView
|
||||
{
|
||||
[Serializable]
|
||||
public class ProxySlot : ISlot
|
||||
{
|
||||
[SerializeReference]
|
||||
private ISlot _slot;
|
||||
|
||||
public SlotData SlotData => _slot == null ? default : _slot.SlotData;
|
||||
public List<SlotData> LinkedSlotDatas => _slot?.LinkedSlotDatas;
|
||||
public bool IsLinked => LinkedSlotDatas?.Count > 0;
|
||||
public DataNode Owner => _slot?.Owner;
|
||||
public object Data => _slot?.Data;
|
||||
|
||||
public void Bind(ISlot slot)
|
||||
{
|
||||
_slot = slot;
|
||||
}
|
||||
|
||||
public bool Link(ISlot other, out SlotConnection connection)
|
||||
{
|
||||
if (_slot == null)
|
||||
{
|
||||
connection = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
return _slot.Link(other, out connection);
|
||||
}
|
||||
public void Unlink(ISlot other)
|
||||
{
|
||||
_slot?.Unlink(other);
|
||||
}
|
||||
|
||||
public void ReceiveData(object data)
|
||||
{
|
||||
_slot?.ReceiveData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Models/Slots/ProxySlot.cs.meta
Normal file
2
Runtime/Models/Slots/ProxySlot.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a594be83195d37541be4619f6ca1c440
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView
|
||||
@@ -41,57 +40,61 @@ namespace Misaki.GraphView
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Slot
|
||||
public class Slot : ISlot
|
||||
{
|
||||
[SerializeField]
|
||||
private SlotData _slotData;
|
||||
[SerializeField]
|
||||
private List<SlotData> _linkedSlotData = new();
|
||||
|
||||
public ReadOnlyCollection<SlotData> LinkedSlotData => _linkedSlotData.AsReadOnly();
|
||||
|
||||
[SerializeReference]
|
||||
public DataNode owner;
|
||||
public SlotData slotData;
|
||||
private DataNode _owner;
|
||||
|
||||
public object value;
|
||||
private object _data;
|
||||
|
||||
public SlotData SlotData => _slotData;
|
||||
public List<SlotData> LinkedSlotDatas => _linkedSlotData;
|
||||
public bool IsLinked => _linkedSlotData.Count > 0;
|
||||
public DataNode Owner => _owner;
|
||||
public object Data => _data;
|
||||
|
||||
public Slot(DataNode owner, SlotData slotData)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.slotData = slotData;
|
||||
_owner = owner;
|
||||
_slotData = slotData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the current slot with another slot.
|
||||
/// </summary>
|
||||
/// <param name="other"> The slot need to be linked </param>
|
||||
public bool Link(Slot other, out SlotConnection connection)
|
||||
/// <inheritdoc/>
|
||||
public bool Link(ISlot other, out SlotConnection connection)
|
||||
{
|
||||
connection = default;
|
||||
if (other.slotData.direction == slotData.direction)
|
||||
if (other.SlotData.direction == _slotData.direction)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_linkedSlotData.Contains(other.slotData))
|
||||
if (_linkedSlotData.Contains(other.SlotData))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_linkedSlotData.Add(other.slotData);
|
||||
other._linkedSlotData.Add(slotData);
|
||||
connection = new(slotData, other.slotData);
|
||||
_linkedSlotData.Add(other.SlotData);
|
||||
other.LinkedSlotDatas.Add(_slotData);
|
||||
connection = new(_slotData, other.SlotData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlink the current slot with another slot.
|
||||
/// </summary>
|
||||
/// <param name="other"> The slot need to be unlinked </param>
|
||||
public void Unlink(Slot other)
|
||||
/// <inheritdoc/>
|
||||
public void Unlink(ISlot other)
|
||||
{
|
||||
_linkedSlotData.Remove(other.slotData);
|
||||
other._linkedSlotData.Remove(slotData);
|
||||
_linkedSlotData.Remove(other.SlotData);
|
||||
other.LinkedSlotDatas.Remove(_slotData);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void ReceiveData(object data)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user