Skip to content

Commit d334872

Browse files
committed
feat: Improve UI
1 parent 1c09f48 commit d334872

12 files changed

Lines changed: 71 additions & 70 deletions

Editor/Scripts/GraphView/PlayableGraphView.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public class PlayableGraphView : UGraphView
1818

1919
public PlayableGraphView()
2020
{
21+
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
2122
this.AddManipulator(new ContentDragger());
2223
//this.AddManipulator(new SelectionDragger());
2324
this.AddManipulator(new RectangleSelector());
24-
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
25-
26-
deleteSelection = OnDeleteSelectionEvent;
2725
}
2826

2927
public void Update(PlayableGraph playableGraph)
@@ -47,11 +45,9 @@ public void Update(PlayableGraph playableGraph)
4745
}
4846
}
4947

50-
5148
public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
5249
{
5350
// disable contextual menu
54-
//base.BuildContextualMenu(evt);
5551
}
5652

5753
private void ClearView()
@@ -135,13 +131,8 @@ private void CalculateLayout()
135131

136132
outputNode.CalculateLayout(origin);
137133

138-
origin.y += treeSize.y + GraphViewNode.VerticalSpace;
134+
origin.y += treeSize.y + GraphViewNode.VERTICAL_SPACE;
139135
}
140136
}
141-
142-
private void OnDeleteSelectionEvent(string operationName, AskUser askuser)
143-
{
144-
// disallow delete graph elements
145-
}
146137
}
147-
}
138+
}

Editor/Scripts/Node/GraphViewNode.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ public abstract class GraphViewNode : UNode
5757
protected GraphViewNode Parent { get; private set; }
5858

5959

60-
public virtual void Update() { }
60+
protected GraphViewNode()
61+
{
62+
capabilities &= ~Capabilities.Movable;
63+
capabilities &= ~Capabilities.Deletable;
64+
}
65+
66+
public virtual void Update()
67+
{
68+
}
6169

6270

6371
#region Description
@@ -129,9 +137,9 @@ protected Port InstantiatePort<TPort>(Direction direction)
129137

130138
#region Layout
131139

132-
public const int HorizontalSpace = 80;
140+
public const int HORIZONTAL_SPACE = 80;
133141

134-
public const int VerticalSpace = 80;
142+
public const int VERTICAL_SPACE = 80;
135143

136144
public static readonly Vector2 StandardNodeSize = new Vector2(400, 150);
137145

@@ -164,9 +172,10 @@ public Vector2 GetHierarchySize()
164172
subHierarchySize.x = Mathf.Max(subHierarchySize.x, childSize.x);
165173
subHierarchySize.y += childSize.y;
166174
}
167-
subHierarchySize.y += (InternalInputs.Count - 1) * VerticalSpace;
168175

169-
var hierarchySize = GetNodeSize() + new Vector2(HorizontalSpace, 0);
176+
subHierarchySize.y += (InternalInputs.Count - 1) * VERTICAL_SPACE;
177+
178+
var hierarchySize = GetNodeSize() + new Vector2(HORIZONTAL_SPACE, 0);
170179
hierarchySize.y = Mathf.Max(hierarchySize.y, subHierarchySize.y);
171180
_hierarchySize = hierarchySize;
172181

@@ -179,7 +188,7 @@ public void CalculateLayout(Vector2 origin)
179188
var nodePos = CalculateSubTreeRootNodePosition(subTreeSize, origin);
180189
SetPosition(new Rect(nodePos, Vector2.zero));
181190

182-
origin.x -= GetNodeSize().x - HorizontalSpace;
191+
origin.x -= GetNodeSize().x - HORIZONTAL_SPACE;
183192
for (int i = 0; i < InternalInputs.Count; i++)
184193
{
185194
var childNode = InternalInputs[i];
@@ -202,7 +211,7 @@ public static Vector2 CalculateSubTreeRootNodePosition(Vector2 subTreeSize, Vect
202211

203212
#region Flags
204213

205-
private uint _flags = 0;
214+
private uint _flags;
206215

207216

208217
public bool CheckFlag(NodeFlag flag)

Editor/Scripts/Node/PlayableNode.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public override void Update()
7575
var selfInputPort = InternalInputPorts[i];
7676
var edge = selfInputPort.ConnectTo(inputPlayableNodeOutputPort);
7777
Container.AddElement(edge);
78+
edge.capabilities &= ~Capabilities.Movable;
79+
edge.capabilities &= ~Capabilities.Deletable;
80+
edge.capabilities &= ~Capabilities.Selectable;
7881
InternalInputs.Add(new NodeInput(edge, inputPlayableNode, i));
7982

8083
AddFlag(NodeFlag.HierarchyDirty);

Editor/Scripts/Node/PlayableNodeFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ namespace GBG.PlayableGraphMonitor.Editor.Node
66
{
77
public static class PlayableNodeFactory
88
{
9-
public const string PlayableHeader = "Playable";
9+
public const string PLAYABLE_HEADER = "Playable";
1010

1111
public static PlayableNode CreateNode(Playable playable)
1212
{
1313
var playableType = playable.GetPlayableType();
1414
var playableTypeName = playableType.Name;
1515
var playableTypeSortName = playableTypeName
16-
.Remove(playableTypeName.Length - PlayableHeader.Length);
17-
var nodeTitle = $"{PlayableHeader}\n{playableTypeSortName}";
16+
.Remove(playableTypeName.Length - PLAYABLE_HEADER.Length);
17+
var nodeTitle = $"{PLAYABLE_HEADER}\n{playableTypeSortName}";
1818

1919
// create node by playable type
2020
PlayableNode playableNode;

Editor/Scripts/Node/PlayableOutputNode.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public override void Update()
5353
var sourcePlayableOutputPort = sourcePlayableNode.OutputPorts[0];
5454
var selfSourcePort = InternalInputPorts[0];
5555
var edge = selfSourcePort.ConnectTo(sourcePlayableOutputPort);
56+
edge.capabilities &= ~Capabilities.Movable;
57+
edge.capabilities &= ~Capabilities.Deletable;
58+
edge.capabilities &= ~Capabilities.Selectable;
5659
Container.AddElement(edge);
5760
InternalInputs.Add(new NodeInput(edge, sourcePlayableNode, 0));
5861

@@ -115,7 +118,7 @@ private void CreatePorts()
115118
protected override void AppendStateDescriptions(StringBuilder descBuilder)
116119
{
117120
descBuilder.Append("Type: ").AppendLine(PlayableOutput.GetPlayableOutputType().Name)
118-
.Append("IsValid: ").AppendLine(PlayableOutput.IsOutputValid().ToString());
121+
.Append("IsValid: ").AppendLine(PlayableOutput.IsOutputValid().ToString());
119122
if (PlayableOutput.IsOutputValid())
120123
{
121124
descBuilder.Append("Name: ").AppendLine(PlayableOutput.GetEditorName())
@@ -128,4 +131,4 @@ protected override void AppendStateDescriptions(StringBuilder descBuilder)
128131

129132
#endregion
130133
}
131-
}
134+
}

Editor/Scripts/Node/PlayableOutputNodeFactory.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
using GBG.PlayableGraphMonitor.Editor.Utility;
22
using UnityEditor.Playables;
3-
using UnityEngine.Animations;
43
using UnityEngine.Playables;
54

65
namespace GBG.PlayableGraphMonitor.Editor.Node
76
{
87
public static class PlayableOutputNodeFactory
98
{
10-
public const string PlayableOutputHeader = "PlayableOutput";
9+
public const string PLAYABLE_OUTPUT_HEADER = "PlayableOutput";
1110

1211
public static PlayableOutputNode CreateNode(PlayableOutput playableOutput)
1312
{
1413
var playableOutputType = playableOutput.GetPlayableOutputType();
1514
var playableOutputTypeName = playableOutputType.Name;
1615
var playableOutputTypeSortName = playableOutputTypeName
17-
.Remove(playableOutputTypeName.Length - PlayableOutputHeader.Length);
16+
.Remove(playableOutputTypeName.Length - PLAYABLE_OUTPUT_HEADER.Length);
1817
var playableOutputEditorName = playableOutput.GetEditorName();
19-
var nodeTitle = $"{PlayableOutputHeader}\n" +
18+
var nodeTitle = $"{PLAYABLE_OUTPUT_HEADER}\n" +
2019
$"{playableOutputTypeSortName} ({playableOutputEditorName})";
2120

2221
// default node

Editor/Scripts/Utility/GraphTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public static void SetNodeStyle(this GraphViewNode node, Color nodeColor,
5353
#region Port Color
5454

5555
// Ensure edge is always visible.
56-
public const float ColorAlphaFactor = 1f / 9;
56+
public const float COLOR_ALPHA_FACTOR = 1f / 9;
5757

5858

5959
public static Color GetPortColor(float weight)
6060
{
61-
var alpha = (weight + ColorAlphaFactor) / (1 + ColorAlphaFactor);
61+
var alpha = (weight + COLOR_ALPHA_FACTOR) / (1 + COLOR_ALPHA_FACTOR);
6262
return new Color(1, 1, 1, alpha);
6363
}
6464

Editor/Scripts/Window/PlayableGraphMonitorWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace GBG.PlayableGraphMonitor.Editor
99
{
1010
public partial class PlayableGraphMonitorWindow : EditorWindow
1111
{
12+
// ReSharper disable once Unity.IncorrectMethodSignature
1213
[MenuItem("Window/Analysis/PlayableGraph Monitor")]
1314
public static PlayableGraphMonitorWindow Open()
1415
{

Editor/Scripts/Window/PlayableGraphMonitorWindow_GraphView.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ private void CreateGraphView(VisualElement container)
1313
_graphView = new PlayableGraphView
1414
{
1515
style =
16-
{
17-
flexGrow = new StyleFloat(1)
18-
}
16+
{
17+
flexGrow = new StyleFloat(1)
18+
}
1919
};
2020

2121
container.Add(_graphView);
2222
}
2323
}
24-
}
24+
}

Editor/Scripts/Window/PlayableGraphMonitorWindow_NodeInspector.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GBG.PlayableGraphMonitor.Editor
66
{
77
public partial class PlayableGraphMonitorWindow
88
{
9-
private const float _nodeInspectorWidth = 250f;
9+
private const float _NODE_INSPECTOR_WIDTH = 250f;
1010

1111
private VisualElement _nodeInspectorPanel;
1212

@@ -19,15 +19,15 @@ private void CreateNodeInspector(VisualElement container)
1919
{
2020
name = "node-inspector",
2121
style =
22-
{
23-
width = new Length(_nodeInspectorWidth, LengthUnit.Pixel),
24-
height = new Length(100, LengthUnit.Percent),
25-
backgroundColor = GraphTool.GetNodeInspectorBackgroundColor(),
26-
paddingLeft = 4,
27-
paddingRight = 4,
28-
paddingTop = 4,
29-
paddingBottom = 4
30-
}
22+
{
23+
width = new Length(_NODE_INSPECTOR_WIDTH, LengthUnit.Pixel),
24+
height = new Length(100, LengthUnit.Percent),
25+
backgroundColor = GraphTool.GetNodeInspectorBackgroundColor(),
26+
paddingLeft = 4,
27+
paddingRight = 4,
28+
paddingTop = 4,
29+
paddingBottom = 4
30+
}
3131
};
3232

3333
var scrollView = new ScrollView
@@ -38,9 +38,9 @@ private void CreateNodeInspector(VisualElement container)
3838
{
3939
name = "node-desc-label",
4040
style =
41-
{
42-
color = GraphTool.GetNodeInspectorTextColor()
43-
}
41+
{
42+
color = GraphTool.GetNodeInspectorTextColor()
43+
}
4444
};
4545
scrollView.Add(_nodeDescriptionLabel);
4646
_nodeInspectorPanel.Add(scrollView);
@@ -50,7 +50,7 @@ private void CreateNodeInspector(VisualElement container)
5050

5151
private void DrawGraphNodeInspector()
5252
{
53-
if (!(bool)_showInspectorButton.userData)
53+
if (!_inspectorToggle.value)
5454
{
5555
return;
5656
}
@@ -65,4 +65,4 @@ private void DrawGraphNodeInspector()
6565
_nodeDescriptionLabel.text = "Select one node to show details.";
6666
}
6767
}
68-
}
68+
}

0 commit comments

Comments
 (0)