Added the functionality to add RelayNode directly to edge between two Prot;
This commit is contained in:
22
Editor/Contracts/IDataNodeView.cs
Normal file
22
Editor/Contracts/IDataNodeView.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace Misaki.GraphView.Editor
|
||||||
|
{
|
||||||
|
public interface IDataNodeView<T> : IDataNodeView
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The data node that the view represents.
|
||||||
|
/// </summary>
|
||||||
|
public T DataNode
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IDataNodeView
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the data node that the view represents.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DataNode GetDataNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Editor/Contracts/IDataNodeView.cs.meta
Normal file
2
Editor/Contracts/IDataNodeView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 81b43125cc7c5e74f8752420b31030c7
|
||||||
@@ -70,7 +70,7 @@ namespace Misaki.GraphView.Editor
|
|||||||
exposedProperty.propertyName = newValue;
|
exposedProperty.propertyName = newValue;
|
||||||
_owner.Query<PropertyInputNodeView>().ForEach(n =>
|
_owner.Query<PropertyInputNodeView>().ForEach(n =>
|
||||||
{
|
{
|
||||||
if (n.Data.Property.Equals(exposedProperty))
|
if (n.DataNode.Property.Equals(exposedProperty))
|
||||||
{
|
{
|
||||||
n.title = newValue;
|
n.title = newValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,15 +33,15 @@ namespace Misaki.GraphView.Editor
|
|||||||
Add(gridBackground);
|
Add(gridBackground);
|
||||||
gridBackground.SendToBack();
|
gridBackground.SendToBack();
|
||||||
|
|
||||||
var minimapConfig = _graphViewConfig.miniMapConfig;
|
var miniMapConfig = _graphViewConfig.miniMapConfig;
|
||||||
if (minimapConfig is { enable: true })
|
if (miniMapConfig is { enable: true })
|
||||||
{
|
{
|
||||||
var minimap = new MiniMap()
|
var miniMap = new MiniMap()
|
||||||
{
|
{
|
||||||
anchored = true
|
anchored = true
|
||||||
};
|
};
|
||||||
minimap.SetPosition(minimapConfig.position);
|
miniMap.SetPosition(miniMapConfig.position);
|
||||||
Add(minimap);
|
Add(miniMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
_blackboardView = new GraphBlackboardView(_graphObject, this, _graphViewConfig.serializedObject, _graphViewConfig.exposedPropertyTypeManager);
|
_blackboardView = new GraphBlackboardView(_graphObject, this, _graphViewConfig.serializedObject, _graphViewConfig.exposedPropertyTypeManager);
|
||||||
@@ -135,9 +135,9 @@ namespace Misaki.GraphView.Editor
|
|||||||
private void OnDragPerform(DragPerformEvent evt)
|
private void OnDragPerform(DragPerformEvent evt)
|
||||||
{
|
{
|
||||||
var data = DragAndDrop.GetGenericData("DragSelection");
|
var data = DragAndDrop.GetGenericData("DragSelection");
|
||||||
if (data is List<ISelectable> selectables)
|
if (data is List<ISelectable> selectable)
|
||||||
{
|
{
|
||||||
var propertyViews = selectables.OfType<BlackboardPropertyView>().ToArray();
|
var propertyViews = selectable.OfType<BlackboardPropertyView>().ToArray();
|
||||||
if (propertyViews.Length <= 0)
|
if (propertyViews.Length <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Misaki.GraphView.Editor
|
|||||||
}, DropdownMenuAction.AlwaysEnabled);
|
}, DropdownMenuAction.AlwaysEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.target is Edge)
|
if (evt.target is Edge edge)
|
||||||
{
|
{
|
||||||
evt.menu.AppendAction("Create Relay Node", e =>
|
evt.menu.AppendAction("Create Relay Node", e =>
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ namespace Misaki.GraphView.Editor
|
|||||||
position = new Rect(mousePosition, Vector2.zero)
|
position = new Rect(mousePosition, Vector2.zero)
|
||||||
};
|
};
|
||||||
|
|
||||||
AddRelayNode(relayNode);
|
AddRelayNode(relayNode, edge);
|
||||||
}, DropdownMenuAction.AlwaysEnabled);
|
}, DropdownMenuAction.AlwaysEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,16 +46,19 @@ namespace Misaki.GraphView.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (graphViewChange.movedElements != null)
|
if (graphViewChange.movedElements != null)
|
||||||
// {
|
{
|
||||||
// var movedElements = graphViewChange.movedElements;
|
var movedElements = graphViewChange.movedElements;
|
||||||
// Undo.RecordObject(_graphObject, $"Move {movedElements.FirstOrDefault()?.GetType().Name}");
|
Undo.RecordObject(_graphObject, $"Move {movedElements.FirstOrDefault()?.GetType().Name}");
|
||||||
//
|
|
||||||
// foreach (var element in graphViewChange.movedElements)
|
foreach (var element in movedElements)
|
||||||
// {
|
{
|
||||||
// element.SetPosition(element.GetPosition());
|
if (element is IDataNodeView dataNodeView)
|
||||||
// }
|
{
|
||||||
// }
|
dataNodeView.GetDataNode().position = element.GetPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (graphViewChange.edgesToCreate != null)
|
if (graphViewChange.edgesToCreate != null)
|
||||||
{
|
{
|
||||||
@@ -63,15 +66,16 @@ namespace Misaki.GraphView.Editor
|
|||||||
Undo.RecordObject(_graphObject, $"Connect {createdEdges.FirstOrDefault()?.GetType().Name}");
|
Undo.RecordObject(_graphObject, $"Connect {createdEdges.FirstOrDefault()?.GetType().Name}");
|
||||||
|
|
||||||
foreach (var edge in createdEdges)
|
foreach (var edge in createdEdges)
|
||||||
|
{
|
||||||
if (edge.input.userData is Slot inputSlot && edge.output.userData is Slot outputSlot)
|
if (edge.input.userData is Slot inputSlot && edge.output.userData is Slot outputSlot)
|
||||||
{
|
{
|
||||||
var connection = new SlotConnection(inputSlot.slotData, outputSlot.slotData);
|
outputSlot.Link(inputSlot, out var connection);
|
||||||
_slotConnections.Add(edge, connection);
|
_slotConnections.Add(edge, connection);
|
||||||
|
|
||||||
outputSlot.Link(inputSlot);
|
|
||||||
AddConnection(connection);
|
AddConnection(connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_graphObject.SetGraphTransform(viewTransform);
|
_graphObject.SetGraphTransform(viewTransform);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ namespace Misaki.GraphView.Editor
|
|||||||
type ??= typeof(ExecutableNodeView);
|
type ??= typeof(ExecutableNodeView);
|
||||||
return Activator.CreateInstance(type, executableNode, _graphViewConfig.serializedObject, _graphViewConfig.portColorManager, _graphObject.Logger) as ExecutableNodeView;
|
return Activator.CreateInstance(type, executableNode, _graphViewConfig.serializedObject, _graphViewConfig.portColorManager, _graphObject.Logger) as ExecutableNodeView;
|
||||||
}
|
}
|
||||||
|
else if (node is RelayNode relayNode)
|
||||||
|
{
|
||||||
|
return new RelayNodeView(relayNode, _graphViewConfig.portColorManager);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -123,10 +127,14 @@ namespace Misaki.GraphView.Editor
|
|||||||
EditorUtility.SetDirty(_graphObject);
|
EditorUtility.SetDirty(_graphObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveConnection(SlotConnection connection)
|
private void RemoveConnection(SlotConnection connection, bool notify = true)
|
||||||
|
{
|
||||||
|
if (notify)
|
||||||
{
|
{
|
||||||
Undo.RecordObject(_graphObject, $"Remove {connection.GetType().Name}");
|
Undo.RecordObject(_graphObject, $"Remove {connection.GetType().Name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoveConnectionView(connection);
|
||||||
_graphObject.RemoveConnection(connection);
|
_graphObject.RemoveConnection(connection);
|
||||||
|
|
||||||
EditorUtility.SetDirty(_graphObject);
|
EditorUtility.SetDirty(_graphObject);
|
||||||
@@ -148,29 +156,55 @@ namespace Misaki.GraphView.Editor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputPort = inputPortContainer.GetPort(inputSlotData.slotIndex, Direction.Input);
|
var portA = inputPortContainer.GetPort(inputSlotData.slotIndex, (Direction)inputSlotData.direction);
|
||||||
var outputPort = outputPortContainer.GetPort(outputSlotData.slotIndex, Direction.Output);
|
var portB = outputPortContainer.GetPort(outputSlotData.slotIndex, (Direction)outputSlotData.direction);
|
||||||
|
|
||||||
var edge = inputPort.ConnectTo(outputPort);
|
var edge = portA.ConnectTo(portB);
|
||||||
AddElement(edge);
|
AddElement(edge);
|
||||||
_slotConnections.Add(edge, connection);
|
_slotConnections.Add(edge, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRelayNode(RelayNode relayNode)
|
private void RemoveConnectionView(SlotConnection connection)
|
||||||
|
{
|
||||||
|
var edge = _slotConnections.FirstOrDefault(x => x.Value == connection).Key;
|
||||||
|
if (edge != null)
|
||||||
|
{
|
||||||
|
RemoveElement(edge);
|
||||||
|
_slotConnections.Remove(edge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddRelayNode(RelayNode relayNode, Edge edge)
|
||||||
{
|
{
|
||||||
Undo.RecordObject(_graphObject, $"Add {relayNode.GetType().Name}");
|
Undo.RecordObject(_graphObject, $"Add {relayNode.GetType().Name}");
|
||||||
|
|
||||||
_graphObject.AddNode(relayNode);
|
_graphObject.AddNode(relayNode);
|
||||||
AddRelayNodeView(relayNode);
|
AddRelayNodeView(relayNode, edge);
|
||||||
|
|
||||||
|
var connection = _slotConnections[edge];
|
||||||
|
RemoveConnection(connection, false);
|
||||||
|
|
||||||
EditorUtility.SetDirty(_graphObject);
|
EditorUtility.SetDirty(_graphObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddRelayNodeView(RelayNode relayNode)
|
private void AddRelayNodeView(RelayNode relayNode, Edge edge)
|
||||||
{
|
{
|
||||||
var relayNodeView = new RelayNodeView(relayNode, _graphViewConfig.portColorManager);
|
var relayNodeView = new RelayNodeView(relayNode, _graphViewConfig.portColorManager);
|
||||||
relayNodeView.SetPosition(relayNode.position);
|
relayNodeView.SetPosition(relayNode.position);
|
||||||
|
|
||||||
|
relayNodeView.Connect(edge,
|
||||||
|
out var inputConnection, out var outputConnection,
|
||||||
|
out var inputEdge, out var outputEdge);
|
||||||
|
|
||||||
|
_graphObject.AddConnection(inputConnection);
|
||||||
|
_graphObject.AddConnection(outputConnection);
|
||||||
|
|
||||||
|
_slotConnections.Add(inputEdge, inputConnection);
|
||||||
|
_slotConnections.Add(outputEdge, outputConnection);
|
||||||
|
|
||||||
AddElement(relayNodeView);
|
AddElement(relayNodeView);
|
||||||
|
AddElement(inputEdge);
|
||||||
|
AddElement(outputEdge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ using UnityEngine.UIElements;
|
|||||||
|
|
||||||
namespace Misaki.GraphView.Editor
|
namespace Misaki.GraphView.Editor
|
||||||
{
|
{
|
||||||
public class ExecutableNodeView : Node, IInspectable, IPortContainer
|
public class ExecutableNodeView : Node, IInspectable, IPortContainer, IDataNodeView<ExecutableNode>
|
||||||
{
|
{
|
||||||
private readonly ExecutableNode _dataNode;
|
private readonly ExecutableNode _dataNode;
|
||||||
private readonly Type _nodeType;
|
private readonly Type _nodeType;
|
||||||
@@ -24,6 +24,9 @@ namespace Misaki.GraphView.Editor
|
|||||||
|
|
||||||
private readonly VisualElement _logContainer = new();
|
private readonly VisualElement _logContainer = new();
|
||||||
|
|
||||||
|
public ExecutableNode DataNode => _dataNode;
|
||||||
|
public DataNode GetDataNode() => _dataNode;
|
||||||
|
|
||||||
public Action<IInspectable> OnItemSelected
|
public Action<IInspectable> OnItemSelected
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@@ -194,12 +197,6 @@ namespace Misaki.GraphView.Editor
|
|||||||
_outputPorts.Add(outputPort);
|
_outputPorts.Add(outputPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetPosition(Rect newPos)
|
|
||||||
{
|
|
||||||
base.SetPosition(newPos);
|
|
||||||
_dataNode.position = newPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnSelected()
|
public override void OnSelected()
|
||||||
{
|
{
|
||||||
base.OnSelected();
|
base.OnSelected();
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
using UnityEditor.Experimental.GraphView;
|
using UnityEditor.Experimental.GraphView;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace Misaki.GraphView.Editor
|
namespace Misaki.GraphView.Editor
|
||||||
{
|
{
|
||||||
public class PropertyInputNodeView : TokenNode, IPortContainer
|
public class PropertyInputNodeView : TokenNode, IPortContainer, IDataNodeView<PropertyInput>
|
||||||
{
|
{
|
||||||
private readonly Port _outputPort;
|
private readonly Port _outputPort;
|
||||||
|
|
||||||
private readonly PropertyInput _data;
|
private readonly PropertyInput _dataNode;
|
||||||
//private readonly ExposedPropertyEditor _editor;
|
//private readonly ExposedPropertyEditor _editor;
|
||||||
|
|
||||||
public PropertyInput Data => _data;
|
public PropertyInput DataNode => _dataNode;
|
||||||
|
public DataNode GetDataNode() => _dataNode;
|
||||||
|
|
||||||
public PropertyInputNodeView(PropertyInput data, Port output) : base(null, output)
|
public PropertyInputNodeView(PropertyInput data, Port output) : base(null, output)
|
||||||
{
|
{
|
||||||
_data = data;
|
_dataNode = data;
|
||||||
_outputPort = output;
|
_outputPort = output;
|
||||||
|
|
||||||
name = data.Property.propertyName;
|
name = data.Property.propertyName;
|
||||||
@@ -60,13 +60,7 @@ namespace Misaki.GraphView.Editor
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string InspectorName => _data.Property.propertyName;
|
public string InspectorName => _dataNode.Property.propertyName;
|
||||||
|
|
||||||
public override void SetPosition(Rect newPos)
|
|
||||||
{
|
|
||||||
base.SetPosition(newPos);
|
|
||||||
_data.position = newPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Port GetPort(int index, Direction direction)
|
public Port GetPort(int index, Direction direction)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEditor.Experimental.GraphView;
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace Misaki.GraphView.Editor
|
namespace Misaki.GraphView.Editor
|
||||||
{
|
{
|
||||||
public class RelayNodeView : Node, IPortContainer
|
public class RelayNodeView : Node, IPortContainer, IDataNodeView<RelayNode>
|
||||||
{
|
{
|
||||||
private RelayNode _dataNode;
|
private RelayNode _dataNode;
|
||||||
private IPortColorManager _portColorManager;
|
private IPortColorManager _portColorManager;
|
||||||
@@ -11,21 +12,56 @@ namespace Misaki.GraphView.Editor
|
|||||||
private readonly Port _inputPort;
|
private readonly Port _inputPort;
|
||||||
private readonly Port _outputPort;
|
private readonly Port _outputPort;
|
||||||
|
|
||||||
|
public RelayNode DataNode => _dataNode;
|
||||||
|
public DataNode GetDataNode() => _dataNode;
|
||||||
|
|
||||||
public RelayNodeView(RelayNode dataNode, IPortColorManager portColorManager)
|
public RelayNodeView(RelayNode dataNode, IPortColorManager portColorManager)
|
||||||
{
|
{
|
||||||
_dataNode = dataNode;
|
_dataNode = dataNode;
|
||||||
_portColorManager = portColorManager;
|
_portColorManager = portColorManager;
|
||||||
|
userData = dataNode;
|
||||||
|
|
||||||
_inputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(object));
|
_inputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(object));
|
||||||
_outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(object));
|
_outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(object));
|
||||||
|
|
||||||
_inputPort.portName = string.Empty;
|
this.Q<VisualElement>("title").style.height = 0;
|
||||||
_outputPort.portName = string.Empty;
|
var divider = this.Q<VisualElement>("divider");
|
||||||
|
divider.style.height = 0;
|
||||||
|
divider.style.borderBottomWidth = 0;
|
||||||
|
|
||||||
SetPortsTypeAndColor(typeof(object));
|
_inputPort.style.height = 16;
|
||||||
|
_outputPort.style.height = 16;
|
||||||
|
|
||||||
inputContainer.Add(_inputPort);
|
inputContainer.Add(_inputPort);
|
||||||
outputContainer.Add(_outputPort);
|
outputContainer.Add(_outputPort);
|
||||||
|
|
||||||
|
var portType = Type.GetType(_dataNode.portValueType) ?? typeof(object);
|
||||||
|
SetPortsTypeAndColor(portType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Connect(Edge edge, out SlotConnection inputConnection, out SlotConnection outputConnection, out Edge inputEdge, out Edge outputEdge)
|
||||||
|
{
|
||||||
|
inputConnection = default;
|
||||||
|
outputConnection = default;
|
||||||
|
inputEdge = null;
|
||||||
|
outputEdge = null;
|
||||||
|
|
||||||
|
var input = edge.input;
|
||||||
|
var output = edge.output;
|
||||||
|
if (input.userData is Slot inputSlot && output.userData is Slot outputSlot)
|
||||||
|
{
|
||||||
|
input.Disconnect(edge);
|
||||||
|
output.Disconnect(edge);
|
||||||
|
|
||||||
|
inputSlot.Link(_dataNode.GetSlot(0, SlotDirection.Output), out inputConnection);
|
||||||
|
outputSlot.Link(_dataNode.GetSlot(0, SlotDirection.Input), out outputConnection);
|
||||||
|
inputSlot.Unlink(outputSlot);
|
||||||
|
|
||||||
|
inputEdge = output.ConnectTo(_inputPort);
|
||||||
|
outputEdge = _outputPort.ConnectTo(input);
|
||||||
|
|
||||||
|
SetPortsTypeAndColor(input.portType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetPortsTypeAndColor(Type portType)
|
private void SetPortsTypeAndColor(Type portType)
|
||||||
@@ -33,6 +69,9 @@ namespace Misaki.GraphView.Editor
|
|||||||
_inputPort.portType = portType;
|
_inputPort.portType = portType;
|
||||||
_outputPort.portType = portType;
|
_outputPort.portType = portType;
|
||||||
|
|
||||||
|
_inputPort.portName = string.Empty;
|
||||||
|
_outputPort.portName = string.Empty;
|
||||||
|
|
||||||
if (_portColorManager != null)
|
if (_portColorManager != null)
|
||||||
{
|
{
|
||||||
if (_portColorManager.TryGetColor(portType, out var portColor))
|
if (_portColorManager.TryGetColor(portType, out var portColor))
|
||||||
@@ -41,6 +80,8 @@ namespace Misaki.GraphView.Editor
|
|||||||
_outputPort.portColor = portColor;
|
_outputPort.portColor = portColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_dataNode.portValueType = portType.FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Port GetPort(int index, Direction direction)
|
public Port GetPort(int index, Direction direction)
|
||||||
|
|||||||
@@ -41,33 +41,34 @@ namespace Misaki.GraphView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddNode(DataNode executableNode)
|
public void AddNode(DataNode node)
|
||||||
{
|
{
|
||||||
_nodes.Add(executableNode);
|
_nodes.Add(node);
|
||||||
TryAddNodeToMap(executableNode);
|
TryAddNodeToMap(node);
|
||||||
executableNode.Initialize(this);
|
node.Initialize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveNode(DataNode node)
|
public void RemoveNode(DataNode node)
|
||||||
{
|
{
|
||||||
_nodes.Remove(node);
|
_nodes.Remove(node);
|
||||||
RemoveNodeFromMap(node);
|
RemoveNodeFromMap(node);
|
||||||
node.Dispose();
|
|
||||||
|
|
||||||
if (node is ISlotContainer slotContainer)
|
if (node is ISlotContainer slotContainer)
|
||||||
{
|
{
|
||||||
slotContainer.UnlinkAllSlots();
|
slotContainer.UnlinkAllSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryAddNodeToMap(DataNode executable)
|
public bool TryAddNodeToMap(DataNode node)
|
||||||
{
|
{
|
||||||
return _nodeMap.TryAdd(executable.Id, executable);
|
return _nodeMap.TryAdd(node.Id, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveNodeFromMap(DataNode executableNode)
|
public void RemoveNodeFromMap(DataNode node)
|
||||||
{
|
{
|
||||||
_nodeMap.Remove(executableNode.Id);
|
_nodeMap.Remove(node.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataNode GetNode(string id)
|
public DataNode GetNode(string id)
|
||||||
@@ -75,9 +76,9 @@ namespace Misaki.GraphView
|
|||||||
return _nodeMap.GetValueOrDefault(id);
|
return _nodeMap.GetValueOrDefault(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetNode(string id, out DataNode executable)
|
public bool TryGetNode(string id, out DataNode node)
|
||||||
{
|
{
|
||||||
return _nodeMap.TryGetValue(id, out executable);
|
return _nodeMap.TryGetValue(id, out node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddStickyNote(StickyNoteData stickyNote)
|
public void AddStickyNote(StickyNoteData stickyNote)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Misaki.GraphView
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unload the node, this method is called when the node is removed from the graph.
|
/// Dispose the node, this method is called when the node is removed from the graph.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace Misaki.GraphView
|
|||||||
|
|
||||||
private bool _isExecuted;
|
private bool _isExecuted;
|
||||||
|
|
||||||
|
public string portValueType;
|
||||||
|
|
||||||
public override void Initialize(GraphObject graph)
|
public override void Initialize(GraphObject graph)
|
||||||
{
|
{
|
||||||
graphObject = graph;
|
graphObject = graph;
|
||||||
@@ -31,6 +33,8 @@ namespace Misaki.GraphView
|
|||||||
direction = SlotDirection.Output,
|
direction = SlotDirection.Output,
|
||||||
valueType = typeof(object).FullName
|
valueType = typeof(object).FullName
|
||||||
});
|
});
|
||||||
|
|
||||||
|
portValueType = typeof(object).FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSlot(Slot slot)
|
public void AddSlot(Slot slot)
|
||||||
|
|||||||
@@ -64,20 +64,24 @@ namespace Misaki.GraphView
|
|||||||
/// Link the current slot with another slot.
|
/// Link the current slot with another slot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other"> The slot need to be linked </param>
|
/// <param name="other"> The slot need to be linked </param>
|
||||||
public void Link(Slot other)
|
public bool Link(Slot other, out SlotConnection connection)
|
||||||
{
|
{
|
||||||
|
connection = default;
|
||||||
if (other.slotData.direction == slotData.direction)
|
if (other.slotData.direction == slotData.direction)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_linkedSlotData.Contains(other.slotData))
|
if (_linkedSlotData.Contains(other.slotData))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_linkedSlotData.Add(other.slotData);
|
_linkedSlotData.Add(other.slotData);
|
||||||
other._linkedSlotData.Add(slotData);
|
other._linkedSlotData.Add(slotData);
|
||||||
|
connection = new(slotData, other.slotData);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -43,5 +43,15 @@ namespace Misaki.GraphView
|
|||||||
{
|
{
|
||||||
return HashCode.Combine(InputSlotData, OutputSlotData);
|
return HashCode.Combine(InputSlotData, OutputSlotData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(SlotConnection left, SlotConnection right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(SlotConnection left, SlotConnection right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,9 +13,9 @@ MonoBehaviour:
|
|||||||
m_Name: GraphAsset
|
m_Name: GraphAsset
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_nodes:
|
_nodes:
|
||||||
- rid: 299037570321612880
|
|
||||||
- rid: 299037570321612881
|
- rid: 299037570321612881
|
||||||
- rid: 299037570321612882
|
- rid: 299037570321612882
|
||||||
|
- rid: 299037621810888806
|
||||||
_stickyNotes:
|
_stickyNotes:
|
||||||
- _id: 940a3025-e571-4b33-8d7c-c86761a95017
|
- _id: 940a3025-e571-4b33-8d7c-c86761a95017
|
||||||
title: Title
|
title: Title
|
||||||
@@ -36,26 +36,26 @@ MonoBehaviour:
|
|||||||
direction: 0
|
direction: 0
|
||||||
valueType: System.Single
|
valueType: System.Single
|
||||||
_outputSlotData:
|
_outputSlotData:
|
||||||
slotName: _result
|
slotName: Output
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
nodeID: c9e7e09c-b463-42ad-b855-9081abb68942
|
||||||
slotIndex: 0
|
slotIndex: 0
|
||||||
direction: 1
|
direction: 1
|
||||||
valueType: System.Single
|
valueType: System.Object
|
||||||
- _inputSlotData:
|
- _inputSlotData:
|
||||||
slotName: a
|
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
|
||||||
slotIndex: 0
|
|
||||||
direction: 0
|
|
||||||
valueType: System.Single
|
|
||||||
_outputSlotData:
|
|
||||||
slotName: value
|
slotName: value
|
||||||
nodeID: 5ee073fb-e411-4061-867a-9ce3afd9a188
|
nodeID: 5ee073fb-e411-4061-867a-9ce3afd9a188
|
||||||
slotIndex: 0
|
slotIndex: 0
|
||||||
direction: 1
|
direction: 1
|
||||||
valueType: System.Object
|
valueType: System.Object
|
||||||
|
_outputSlotData:
|
||||||
|
slotName: Input
|
||||||
|
nodeID: c9e7e09c-b463-42ad-b855-9081abb68942
|
||||||
|
slotIndex: 0
|
||||||
|
direction: 0
|
||||||
|
valueType: System.Object
|
||||||
_exposedProperties:
|
_exposedProperties:
|
||||||
- rid: 299037523270959195
|
- rid: 299037523270959195
|
||||||
graphPosition: {x: 131.33333, y: -8, z: 0}
|
graphPosition: {x: 224, y: 84.666664, z: 0}
|
||||||
graphScale: {x: 1, y: 1, z: 1}
|
graphScale: {x: 1, y: 1, z: 1}
|
||||||
references:
|
references:
|
||||||
version: 2
|
version: 2
|
||||||
@@ -68,58 +68,6 @@ MonoBehaviour:
|
|||||||
propertyType: Misaki.GraphView.Sample.FloatProperty
|
propertyType: Misaki.GraphView.Sample.FloatProperty
|
||||||
showInInspector: 1
|
showInInspector: 1
|
||||||
value: 1
|
value: 1
|
||||||
- rid: 299037570321612880
|
|
||||||
type: {class: Add, ns: Misaki.GraphView.Sample, asm: GraphView.Sample}
|
|
||||||
data:
|
|
||||||
graphObject: {fileID: 11400000}
|
|
||||||
id: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
|
||||||
position:
|
|
||||||
serializedVersion: 2
|
|
||||||
x: 534
|
|
||||||
y: 418
|
|
||||||
width: 116.66669
|
|
||||||
height: 102.66666
|
|
||||||
_inputs:
|
|
||||||
- _linkedSlotData:
|
|
||||||
- slotName: value
|
|
||||||
nodeID: 5ee073fb-e411-4061-867a-9ce3afd9a188
|
|
||||||
slotIndex: 0
|
|
||||||
direction: 1
|
|
||||||
valueType: System.Object
|
|
||||||
owner:
|
|
||||||
rid: 299037570321612880
|
|
||||||
slotData:
|
|
||||||
slotName: a
|
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
|
||||||
slotIndex: 0
|
|
||||||
direction: 0
|
|
||||||
valueType: System.Single
|
|
||||||
- _linkedSlotData: []
|
|
||||||
owner:
|
|
||||||
rid: 299037570321612880
|
|
||||||
slotData:
|
|
||||||
slotName: b
|
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
|
||||||
slotIndex: 1
|
|
||||||
direction: 0
|
|
||||||
valueType: System.Single
|
|
||||||
_outputs:
|
|
||||||
- _linkedSlotData:
|
|
||||||
- slotName: _input
|
|
||||||
nodeID: 1d18af80-6a54-4cdc-b49c-b53e74f56404
|
|
||||||
slotIndex: 0
|
|
||||||
direction: 0
|
|
||||||
valueType: System.Single
|
|
||||||
owner:
|
|
||||||
rid: 299037570321612880
|
|
||||||
slotData:
|
|
||||||
slotName: _result
|
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
|
||||||
slotIndex: 0
|
|
||||||
direction: 1
|
|
||||||
valueType: System.Single
|
|
||||||
a: 1
|
|
||||||
b: 1
|
|
||||||
- rid: 299037570321612881
|
- rid: 299037570321612881
|
||||||
type: {class: Output, ns: Misaki.GraphView.Sample, asm: GraphView.Sample}
|
type: {class: Output, ns: Misaki.GraphView.Sample, asm: GraphView.Sample}
|
||||||
data:
|
data:
|
||||||
@@ -127,17 +75,27 @@ MonoBehaviour:
|
|||||||
id: 1d18af80-6a54-4cdc-b49c-b53e74f56404
|
id: 1d18af80-6a54-4cdc-b49c-b53e74f56404
|
||||||
position:
|
position:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 760
|
x: 709.7862
|
||||||
y: 418
|
y: 417.86685
|
||||||
width: 124.66669
|
width: 124.66669
|
||||||
height: 78.66666
|
height: 78.66666
|
||||||
_inputs:
|
_inputs:
|
||||||
- _linkedSlotData:
|
- _linkedSlotData:
|
||||||
- slotName: _result
|
- slotName: _result
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
nodeID: fea7bcdd-0c2a-464f-a21a-126383bafb2e
|
||||||
slotIndex: 0
|
slotIndex: 0
|
||||||
direction: 1
|
direction: 1
|
||||||
valueType: System.Single
|
valueType: System.Single
|
||||||
|
- slotName: Output
|
||||||
|
nodeID: 104c0451-a164-449e-9d90-d629cdc33150
|
||||||
|
slotIndex: 0
|
||||||
|
direction: 1
|
||||||
|
valueType: System.Object
|
||||||
|
- slotName: Output
|
||||||
|
nodeID: c9e7e09c-b463-42ad-b855-9081abb68942
|
||||||
|
slotIndex: 0
|
||||||
|
direction: 1
|
||||||
|
valueType: System.Object
|
||||||
owner:
|
owner:
|
||||||
rid: 299037570321612881
|
rid: 299037570321612881
|
||||||
slotData:
|
slotData:
|
||||||
@@ -154,18 +112,28 @@ MonoBehaviour:
|
|||||||
id: 5ee073fb-e411-4061-867a-9ce3afd9a188
|
id: 5ee073fb-e411-4061-867a-9ce3afd9a188
|
||||||
position:
|
position:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 357.66666
|
x: 264
|
||||||
y: 484.6665
|
y: 460
|
||||||
width: 98.66666
|
width: 98.66666
|
||||||
height: 36
|
height: 35.99997
|
||||||
_inputs: []
|
_inputs: []
|
||||||
_outputs:
|
_outputs:
|
||||||
- _linkedSlotData:
|
- _linkedSlotData:
|
||||||
- slotName: a
|
- slotName: a
|
||||||
nodeID: 31f46c9e-45f1-418a-bb4b-cc843ea9242a
|
nodeID: fea7bcdd-0c2a-464f-a21a-126383bafb2e
|
||||||
slotIndex: 0
|
slotIndex: 0
|
||||||
direction: 0
|
direction: 0
|
||||||
valueType: System.Single
|
valueType: System.Single
|
||||||
|
- slotName: Input
|
||||||
|
nodeID: 104c0451-a164-449e-9d90-d629cdc33150
|
||||||
|
slotIndex: 0
|
||||||
|
direction: 0
|
||||||
|
valueType: System.Object
|
||||||
|
- slotName: Input
|
||||||
|
nodeID: c9e7e09c-b463-42ad-b855-9081abb68942
|
||||||
|
slotIndex: 0
|
||||||
|
direction: 0
|
||||||
|
valueType: System.Object
|
||||||
owner:
|
owner:
|
||||||
rid: 299037570321612882
|
rid: 299037570321612882
|
||||||
slotData:
|
slotData:
|
||||||
@@ -176,3 +144,15 @@ MonoBehaviour:
|
|||||||
valueType: System.Object
|
valueType: System.Object
|
||||||
_property:
|
_property:
|
||||||
rid: 299037523270959195
|
rid: 299037523270959195
|
||||||
|
- rid: 299037621810888806
|
||||||
|
type: {class: RelayNode, ns: Misaki.GraphView, asm: GraphView}
|
||||||
|
data:
|
||||||
|
graphObject: {fileID: 11400000}
|
||||||
|
id: c9e7e09c-b463-42ad-b855-9081abb68942
|
||||||
|
position:
|
||||||
|
serializedVersion: 2
|
||||||
|
x: 500.66666
|
||||||
|
y: 462.66666
|
||||||
|
width: 74.66669
|
||||||
|
height: 33.333313
|
||||||
|
portValueType: System.Single
|
||||||
|
|||||||
Reference in New Issue
Block a user