Skip to content

Commit c5a7b40

Browse files
committed
feat: draw nodes
1 parent 6a9ea80 commit c5a7b40

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

Editor/Scripts/GraphView/PlayableNode.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public PlayableNode(PlayableGraphView owner, int depth, Playable playable)
1616
CreatePorts();
1717
RefreshExpandedState();
1818
RefreshPorts();
19+
20+
CreateAndConnectInputNodes();
1921
}
2022

2123

@@ -42,5 +44,31 @@ private void CreatePorts()
4244
InternalOutputPorts.Add(outputPort);
4345
}
4446
}
47+
48+
private void CreateAndConnectInputNodes()
49+
{
50+
if (!Playable.IsValid())
51+
{
52+
return;
53+
}
54+
55+
var inputPlayableDepth = Depth + 1;
56+
for (int i = 0; i < Playable.GetInputCount(); i++)
57+
{
58+
var inputPlayable = Playable.GetInput(i);
59+
var inputPlayableTypeName = inputPlayable.GetPlayableType().Name;
60+
var inputPlayableNode = new PlayableNode(Owner, inputPlayableDepth, inputPlayable)
61+
{
62+
title = inputPlayableTypeName
63+
};
64+
inputPlayableNode.SetPosition(new Rect(-400 * inputPlayableDepth, 200, 0, 0));
65+
Owner.AddElement(inputPlayableNode);
66+
67+
var inputPlayableOutputPortIndex = 0;
68+
var inputPlayableOutputPort = InternalInputPorts[inputPlayableOutputPortIndex];
69+
var edge = inputPlayableOutputPort.ConnectTo(inputPlayableNode.OutputPorts[0]);
70+
Owner.AddElement(edge);
71+
}
72+
}
4573
}
4674
}

Editor/Scripts/GraphView/PlayableOutputNode.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public PlayableOutputNode(PlayableGraphView owner, int depth, PlayableOutput pla
1919
RefreshExpandedState();
2020
RefreshPorts();
2121

22-
CreateAndConnectInputs();
22+
CreateAndConnectInputNodes();
2323
}
2424

2525

@@ -36,7 +36,7 @@ private void CreatePorts()
3636
InternalInputPorts.Add(inputPort);
3737
}
3838

39-
private void CreateAndConnectInputs()
39+
private void CreateAndConnectInputNodes()
4040
{
4141
if (!PlayableOutput.IsOutputValid())
4242
{
@@ -53,7 +53,9 @@ private void CreateAndConnectInputs()
5353
inputPlayableNode.SetPosition(new Rect(-400 * inputPlayableDepth, 200, 0, 0));
5454
Owner.AddElement(inputPlayableNode);
5555

56-
var edge = InternalInputPorts[0].ConnectTo(inputPlayableNode.OutputPorts[0]);
56+
var inputPlayableOutputPortIndex = PlayableOutput.GetSourceOutputPort();
57+
var inputPlayableOutputPort = InternalInputPorts[inputPlayableOutputPortIndex];
58+
var edge = inputPlayableOutputPort.ConnectTo(inputPlayableNode.OutputPorts[0]);
5759
Owner.AddElement(edge);
5860
}
5961
}

0 commit comments

Comments
 (0)