First commit
This commit is contained in:
101
Runtime/Models/Slots/Slot.cs
Normal file
101
Runtime/Models/Slots/Slot.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView
|
||||
{
|
||||
[Serializable]
|
||||
public struct SlotData : IEquatable<SlotData>
|
||||
{
|
||||
public string slotName;
|
||||
public string nodeID;
|
||||
public int slotIndex;
|
||||
public SlotDirection direction;
|
||||
public string valueType;
|
||||
|
||||
public bool Equals(SlotData other)
|
||||
{
|
||||
return slotName == other.slotName && nodeID == other.nodeID && slotIndex == other.slotIndex && direction == other.direction && valueType == other.valueType;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is SlotData other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(slotName, nodeID, slotIndex, direction, valueType);
|
||||
}
|
||||
|
||||
public static bool operator ==(SlotData left, SlotData right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(SlotData left, SlotData right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Slot
|
||||
{
|
||||
[SerializeField]
|
||||
private List<SlotData> _linkedSlotData = new();
|
||||
|
||||
public ReadOnlyCollection<SlotData> LinkedSlotData => _linkedSlotData.AsReadOnly();
|
||||
|
||||
[SerializeReference]
|
||||
public BaseNode owner;
|
||||
public SlotData slotData;
|
||||
|
||||
public object value;
|
||||
|
||||
public Slot(BaseNode owner, SlotData slotData)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.slotData = slotData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the current slot with another slot.
|
||||
/// </summary>
|
||||
/// <param name="other"> The slot need to be linked </param>
|
||||
public void Link(Slot other)
|
||||
{
|
||||
if (other.slotData.direction == slotData.direction)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_linkedSlotData.Contains(other.slotData))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_linkedSlotData.Add(other.slotData);
|
||||
other._linkedSlotData.Add(slotData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlink the current slot with another slot.
|
||||
/// </summary>
|
||||
/// <param name="other"> The slot need to be unlinked </param>
|
||||
public void Unlink(Slot other)
|
||||
{
|
||||
_linkedSlotData.Remove(other.slotData);
|
||||
other._linkedSlotData.Remove(slotData);
|
||||
}
|
||||
|
||||
public void ReceiveData(object data)
|
||||
{
|
||||
value = data;
|
||||
// We move this to PullData method in BaseNode
|
||||
//owner.GetType().GetField(slotData.slotName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(owner, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Models/Slots/Slot.cs.meta
Normal file
2
Runtime/Models/Slots/Slot.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a905458a4a2f3848b7f29f182fad7f9
|
||||
47
Runtime/Models/Slots/SlotConnection.cs
Normal file
47
Runtime/Models/Slots/SlotConnection.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.GraphView
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a connection between two connection ports.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct SlotConnection : IEquatable<SlotConnection>
|
||||
{
|
||||
[SerializeField]
|
||||
private SlotData _inputSlotData;
|
||||
|
||||
[SerializeField]
|
||||
private SlotData _outputSlotData;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SlotConnection" /> struct.
|
||||
/// </summary>
|
||||
/// <param name="inputSlotData">The input connection port.</param>
|
||||
/// <param name="outputSlotData">The output connection port.</param>
|
||||
public SlotConnection(SlotData inputSlotData, SlotData outputSlotData)
|
||||
{
|
||||
_inputSlotData = inputSlotData;
|
||||
_outputSlotData = outputSlotData;
|
||||
}
|
||||
|
||||
public SlotData InputSlotData => _inputSlotData;
|
||||
public SlotData OutputSlotData => _outputSlotData;
|
||||
|
||||
public bool Equals(SlotConnection other)
|
||||
{
|
||||
return _inputSlotData.Equals(other._inputSlotData) && _outputSlotData.Equals(other._outputSlotData);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is SlotConnection other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(InputSlotData, OutputSlotData);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Runtime/Models/Slots/SlotConnection.cs.meta
Normal file
3
Runtime/Models/Slots/SlotConnection.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfede99dc664420b8b64a5ad265db47b
|
||||
timeCreated: 1730127456
|
||||
Reference in New Issue
Block a user