Skip to content

Commit d0a147c

Browse files
committed
feat: improve node layout
1 parent daa1363 commit d0a147c

6 files changed

Lines changed: 18 additions & 40 deletions

File tree

Editor/Scripts/GraphView/PlayableGraphView.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public PlayableGraph GetPlayableGraph()
3030
return _playableGraph;
3131
}
3232

33-
public void SetPlayableGraph(PlayableGraph playableGraph, bool forceRepaint)
33+
public void SetPlayableGraph(PlayableGraph playableGraph)
3434
{
35-
if (!forceRepaint && IsEqual(ref _playableGraph, ref playableGraph))
35+
if (IsEqual(ref _playableGraph, ref playableGraph))
3636
{
3737
return;
3838
}
@@ -91,10 +91,10 @@ private void PopulateView()
9191
for (int i = 0; i < _playableOutputNodes.Count; i++)
9292
{
9393
var outputNode = _playableOutputNodes[i];
94-
var hierarchySize = outputNode.GetHierarchySize();
95-
outputNode.CalculateLayout(hierarchySize, origin);
94+
var treeSize = outputNode.GetHierarchySize();
95+
outputNode.CalculateLayout(treeSize, origin);
9696

97-
origin.y += hierarchySize.y + NodeLayoutInfo.VerticalSpace;
97+
origin.y += treeSize.y + NodeLayoutInfo.VerticalSpace;
9898
}
9999
}
100100

Editor/Scripts/Node/GraphViewNode.cs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,32 @@ public Vector2 GetHierarchySize()
4747
return _hierarchySize.Value;
4848
}
4949

50-
5150
if (Children.Count == 0)
5251
{
5352
_hierarchySize = GetNodeSize();
5453
return _hierarchySize.Value;
5554
}
5655

57-
if (Children.Count == 1)
58-
{
59-
var selfSize = GetNodeSize();
60-
var childHierarchySize = Children[0].GetHierarchySize();
61-
_hierarchySize = new Vector2
62-
{
63-
x = selfSize.x + childHierarchySize.x + NodeLayoutInfo.HorizontalSpace,
64-
y = selfSize.y + childHierarchySize.y + NodeLayoutInfo.VerticalSpace
65-
};
66-
67-
return _hierarchySize.Value;
68-
}
69-
70-
var hierarchySize = GetNodeSize() + new Vector2(NodeLayoutInfo.HorizontalSpace, 0);
56+
var subHierarchySize = Vector2.zero;
7157
for (int i = 0; i < Children.Count; i++)
7258
{
7359
var childSize = Children[i].GetHierarchySize();
74-
hierarchySize.x += childSize.x;
75-
hierarchySize.y = Mathf.Max(hierarchySize.y, childSize.y);
60+
subHierarchySize.x = Mathf.Max(subHierarchySize.x, childSize.x);
61+
subHierarchySize.y += childSize.y;
7662
}
63+
subHierarchySize.y += (Children.Count - 1) * NodeLayoutInfo.VerticalSpace;
7764

78-
hierarchySize.y += (Children.Count - 1) * NodeLayoutInfo.VerticalSpace;
65+
var hierarchySize = GetNodeSize() + new Vector2(NodeLayoutInfo.HorizontalSpace, 0);
66+
hierarchySize.y = Mathf.Max(hierarchySize.y, subHierarchySize.y);
7967
_hierarchySize = hierarchySize;
8068

8169
return _hierarchySize.Value;
8270
}
8371

8472
public void CalculateLayout(Vector2 treeSize, Vector2 origin)
8573
{
86-
var hierarchySize = GetHierarchySize();
87-
var nodePos = CalculateSubTreeRootPosition(treeSize, hierarchySize, origin);
74+
var subTreeSize = GetHierarchySize();
75+
var nodePos = CalculateSubTreeRootPosition(treeSize, subTreeSize, origin);
8876
SetPosition(new Rect(nodePos, Vector2.zero));
8977

9078
origin.x -= GetNodeSize().x - NodeLayoutInfo.HorizontalSpace;
@@ -94,7 +82,7 @@ public void CalculateLayout(Vector2 treeSize, Vector2 origin)
9482
var childHierarchySize = childNode.GetHierarchySize();
9583
childNode.CalculateLayout(treeSize, origin);
9684

97-
origin.y += childHierarchySize.y + NodeLayoutInfo.VerticalSpace;
85+
origin.y += childHierarchySize.y;
9886
}
9987
}
10088

Editor/Scripts/Node/NodeLayoutInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public struct NodeLayoutInfo
88

99
public const int VerticalSpace = 80;
1010

11-
public static readonly Vector2 StandardNodeSize = new Vector2(300, 150);
11+
public static readonly Vector2 StandardNodeSize = new Vector2(400, 150);
1212

1313
public int TreeWidth;
1414

Editor/Scripts/Node/PlayableNode.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public override void CreateAndConnectInputNodes()
3434
{
3535
title = inputPlayableTypeName
3636
};
37-
//inputPlayableNode.SetPosition(new Rect(-400 * inputPlayableDepth, 200, 0, 0));
3837
inputPlayableNode.AddToContainer(Container);
3938
Children.Add(inputPlayableNode);
4039

Editor/Scripts/Node/PlayableOutputNode.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ public override void CreateAndConnectInputNodes()
3535
{
3636
title = sourcePlayableTypeName
3737
};
38-
//sourcePlayableNode.SetPosition(new Rect(-400 * sourcePlayableNodeDepth, 200, 0, 0));
3938
sourcePlayableNode.AddToContainer(Container);
4039
Children.Add(sourcePlayableNode);
4140

42-
var sourcePlayableOutputPortIndex = PlayableOutput.GetSourceOutputPort();
43-
var sourcePlayableOutputPort = sourcePlayableNode.OutputPorts[sourcePlayableOutputPortIndex];
41+
var sourcePlayableOutputPort = sourcePlayableNode.OutputPorts[0];
4442
var selfSourcePort = InternalInputPorts[0];
4543
var edge = selfSourcePort.ConnectTo(sourcePlayableOutputPort);
4644
Container.AddElement(edge);

Editor/Scripts/Window/PlayableGraphMonitorWindow.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ public static PlayableGraphMonitorWindow Open()
2323

2424
private PopupField<PlayableGraph> _graphPopupField;
2525

26-
private PlayableGraph _selectedGraph;
27-
2826
private PlayableGraphView _graphView;
2927

30-
private bool _needRepaintGraph;
31-
3228

3329
private void OnEnable()
3430
{
@@ -70,8 +66,7 @@ private void OnDisable()
7066

7167
private void Update()
7268
{
73-
_graphView.SetPlayableGraph(_graphPopupField.value, _needRepaintGraph);
74-
_needRepaintGraph = false;
69+
_graphView.SetPlayableGraph(_graphPopupField.value);
7570
}
7671

7772
private string GraphPopupFieldFormatter(PlayableGraph graph)
@@ -90,15 +85,13 @@ private void OnGraphCreated(PlayableGraph graph)
9085
{
9186
_graphs.Add(graph);
9287
_graphPopupField.MarkDirtyRepaint();
93-
_needRepaintGraph = true;
9488
}
9589
}
9690

9791
private void OnDestroyingGraph(PlayableGraph graph)
9892
{
9993
_graphs.Remove(graph);
10094
_graphPopupField.MarkDirtyRepaint();
101-
_needRepaintGraph = true;
10295
}
10396
}
104-
}
97+
}

0 commit comments

Comments
 (0)