Skip to content

Commit a6f70dd

Browse files
committed
feat: update version code & update docs & sorting code
1 parent af85df7 commit a6f70dd

16 files changed

Lines changed: 295 additions & 227 deletions

Editor/Scripts/GraphView/PlayableGraphView.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public void Update(PlayableGraph playableGraph)
3636
ClearView();
3737
}
3838

39-
PopulateView();
39+
UpdateView();
4040

4141
CalculateLayout();
4242

4343
if (needFrameAll)
4444
{
45-
// wait for view initialize at least 2 frames
45+
// wait at least 2 frames for view initialization
4646
EditorApplication.delayCall += () =>
4747
{
4848
EditorApplication.delayCall += () => { FrameAll(); };
@@ -61,7 +61,7 @@ private void ClearView()
6161
_rootOutputNodes.Clear();
6262
}
6363

64-
private void PopulateView()
64+
private void UpdateView()
6565
{
6666
if (!_playableGraph.IsValid())
6767
{
@@ -93,6 +93,7 @@ private void PopulateView()
9393
_rootOutputNodes.Add(playableOutputNode);
9494
}
9595

96+
// check and update nodes
9697
for (int i = _rootOutputNodes.Count - 1; i >= 0; i--)
9798
{
9899
var rootOutputNode = _rootOutputNodes[i];
@@ -131,7 +132,7 @@ private void CalculateLayout()
131132

132133
outputNode.CalculateLayout(origin);
133134

134-
origin.y += treeSize.y + NodeLayoutInfo.VerticalSpace;
135+
origin.y += treeSize.y + GraphViewNode.VerticalSpace;
135136
}
136137
}
137138
}

Editor/Scripts/Node/GraphViewNode.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum NodeFlag : uint
1212
{
1313
None = 0,
1414
Active = 1 << 0,
15-
Dirty = 1 << 1,
15+
//Dirty = 1 << 1,
1616
}
1717

1818
public readonly struct NodeInput
@@ -49,15 +49,14 @@ public abstract class GraphViewNode : UNode
4949

5050
protected UGraphView Container { get; set; }
5151

52-
public IReadOnlyList<NodeInput> Inputs => InternalInputs;
53-
5452
protected List<NodeInput> InternalInputs { get; } = new List<NodeInput>();
5553

56-
protected GraphViewNode Parent { get; private set; }
54+
//protected GraphViewNode Parent { get; private set; }
5755

5856

5957
public virtual void Update() { }
6058

59+
6160
#region Description
6261

6362
private StringBuilder _descBuilder;
@@ -79,19 +78,18 @@ public string GetStateDescription()
7978

8079
protected abstract void AppendStateDescriptions(StringBuilder descBuilder);
8180

82-
8381
#endregion
8482

8583

8684
#region Hierarchy
8785

88-
public virtual void AddToContainer(UGraphView container)
86+
public void AddToContainer(UGraphView container)
8987
{
9088
Container = container;
9189
Container.AddElement(this);
9290
}
9391

94-
public virtual void RemoveFromContainer()
92+
public void RemoveFromContainer()
9593
{
9694
// self
9795
Container.RemoveElement(this);
@@ -120,12 +118,18 @@ protected Port InstantiatePort<TPort>(Direction direction)
120118

121119
#region Layout
122120

121+
public const int HorizontalSpace = 80;
122+
123+
public const int VerticalSpace = 80;
124+
125+
public static readonly Vector2 StandardNodeSize = new Vector2(400, 150);
126+
123127
private Vector2? _hierarchySize;
124128

125129

126130
public Vector2 GetNodeSize()
127131
{
128-
return NodeLayoutInfo.StandardNodeSize;
132+
return StandardNodeSize;
129133
//return worldBound.size;
130134
}
131135

@@ -136,22 +140,22 @@ public Vector2 GetHierarchySize()
136140
return _hierarchySize.Value;
137141
}
138142

139-
if (Inputs.Count == 0)
143+
if (InternalInputs.Count == 0)
140144
{
141145
_hierarchySize = GetNodeSize();
142146
return _hierarchySize.Value;
143147
}
144148

145149
var subHierarchySize = Vector2.zero;
146-
for (int i = 0; i < Inputs.Count; i++)
150+
for (int i = 0; i < InternalInputs.Count; i++)
147151
{
148-
var childSize = Inputs[i].Node.GetHierarchySize();
152+
var childSize = InternalInputs[i].Node.GetHierarchySize();
149153
subHierarchySize.x = Mathf.Max(subHierarchySize.x, childSize.x);
150154
subHierarchySize.y += childSize.y;
151155
}
152-
subHierarchySize.y += (Inputs.Count - 1) * NodeLayoutInfo.VerticalSpace;
156+
subHierarchySize.y += (InternalInputs.Count - 1) * VerticalSpace;
153157

154-
var hierarchySize = GetNodeSize() + new Vector2(NodeLayoutInfo.HorizontalSpace, 0);
158+
var hierarchySize = GetNodeSize() + new Vector2(HorizontalSpace, 0);
155159
hierarchySize.y = Mathf.Max(hierarchySize.y, subHierarchySize.y);
156160
_hierarchySize = hierarchySize;
157161

@@ -164,10 +168,10 @@ public void CalculateLayout(Vector2 origin)
164168
var nodePos = CalculateSubTreeRootNodePosition(subTreeSize, origin);
165169
SetPosition(new Rect(nodePos, Vector2.zero));
166170

167-
origin.x -= GetNodeSize().x - NodeLayoutInfo.HorizontalSpace;
168-
for (int i = 0; i < Inputs.Count; i++)
171+
origin.x -= GetNodeSize().x - HorizontalSpace;
172+
for (int i = 0; i < InternalInputs.Count; i++)
169173
{
170-
var childNode = Inputs[i];
174+
var childNode = InternalInputs[i];
171175
var childHierarchySize = childNode.Node.GetHierarchySize();
172176
childNode.Node.CalculateLayout(origin);
173177

Editor/Scripts/Node/NodeLayoutInfo.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

Editor/Scripts/Node/PlayableNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override void Update()
7272
InternalInputs.Add(new NodeInput(edge, inputPlayableNode, i));
7373
}
7474

75-
// update child nodes
75+
// check and update children
7676
for (int i = InternalInputs.Count - 1; i >= 0; i--)
7777
{
7878
var input = InternalInputs[i];

Editor/Scripts/Node/PlayableOutputNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public override void Update()
5858
}
5959
}
6060

61+
// check and update children
6162
for (int i = InternalInputs.Count - 1; i >= 0; i--)
6263
{
6364
var input = InternalInputs[i];

Editor/Scripts/Utility/GraphTool.cs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public static string DurationToString(this Playable playable, string format = "F
3838
return durationStr;
3939
}
4040

41-
4241
public static void SetNodeStyle(this GraphViewNode node, Color nodeColor,
4342
float titleFontSize = 15, Color? titleColor = null)
4443
{
@@ -51,10 +50,22 @@ public static void SetNodeStyle(this GraphViewNode node, Color nodeColor,
5150
}
5251

5352

53+
#region Port Color
54+
5455
// Ensure edge is always visible.
5556
public const float ColorAlphaFactor = 1f / 9;
5657

5758

59+
public static Color GetPortColor(float weight)
60+
{
61+
var alpha = (weight + ColorAlphaFactor) / (1 + ColorAlphaFactor);
62+
return new Color(1, 1, 1, alpha);
63+
}
64+
65+
#endregion
66+
67+
68+
5869
public static Color GetButtonBackgroundColor(bool isChecked)
5970
{
6071
if (isChecked)
@@ -77,24 +88,22 @@ public static Color GetNodeInspectorBackgroundColor()
7788
new Color32(175, 175, 175, 255); // light
7889
}
7990

91+
92+
#region Node Color
93+
8094
public static Color GetNodeInspectorTextColor()
8195
{
8296
return EditorGUIUtility.isProSkin ?
8397
new Color32(255, 255, 255, 255) : // dark
8498
new Color32(0, 0, 0, 255); // light
8599
}
86100

87-
public static Color GetPortColor(float weight)
88-
{
89-
var alpha = (weight + ColorAlphaFactor) / (1 + ColorAlphaFactor);
90-
return new Color(1, 1, 1, alpha);
91-
}
92-
93101
public static Color GetNodeInvalidColor()
94102
{
95103
return Color.red;
96104
}
97105

106+
// (0, ?, 255, 255) for PlayableOutput nodes
98107
public static Color GetPlayableOutputNodeColor(this ref PlayableOutput playableOutput)
99108
{
100109
if (playableOutput.IsPlayableOutputOfType<AnimationPlayableOutput>())
@@ -111,40 +120,37 @@ public static Color GetPlayableOutputNodeColor(this ref PlayableOutput playableO
111120
return GetRandomColorForType(playableOutput.GetPlayableOutputType());
112121
}
113122

123+
// (0, 255, ?, 255) for Playable nodes
114124
public static Color GetPlayableNodeColor(this ref Playable playable)
115125
{
116126
if (playable.IsPlayableOfType<AnimationClipPlayable>())
117127
{
118-
return new Color32(0, 255, 102, 255);
128+
return new Color32(0, 255, 51, 255);
119129
}
120130

121131
if (playable.IsPlayableOfType<AnimationMixerPlayable>())
122132
{
123-
return new Color32(0, 255, 153, 255);
133+
return new Color32(0, 255, 102, 255);
124134
}
125135

126136
if (playable.IsPlayableOfType<AnimationLayerMixerPlayable>())
127137
{
128-
return new Color32(0, 255, 204, 255);
138+
return new Color32(0, 255, 153, 255);
129139
}
130140

131-
return GetRandomColorForType(playable.GetPlayableType());
132-
}
133-
134-
public static Color GetRandomColorForType(this Type type)
135-
{
136-
if (_colorCache.TryGetValue(type, out var color))
141+
if (playable.IsPlayableOfType<AnimationScriptPlayable>())
137142
{
138-
return color;
143+
return new Color32(0, 255, 204, 255);
139144
}
140145

141-
color = ColorPool[URandom.Range(0, ColorPool.Count)];
142-
_colorCache[type] = color;
143-
144-
return color;
146+
return GetRandomColorForType(playable.GetPlayableType());
145147
}
146148

149+
#endregion
150+
147151

152+
// reserve (0, ?, 255, 255) for PlayableOutput nodes
153+
// reserve (0, 255, ?, 255) for Playable nodes
148154
public static readonly IReadOnlyList<Color32> ColorPool = new Color32[]
149155
{
150156
new Color32(255,0,255,255), new Color32(255,0,153,255),
@@ -159,6 +165,19 @@ public static Color GetRandomColorForType(this Type type)
159165
private static readonly Dictionary<Type, Color32> _colorCache = new Dictionary<Type, Color32>();
160166

161167

168+
public static Color GetRandomColorForType(this Type type)
169+
{
170+
if (_colorCache.TryGetValue(type, out var color))
171+
{
172+
return color;
173+
}
174+
175+
color = ColorPool[URandom.Range(0, ColorPool.Count)];
176+
_colorCache[type] = color;
177+
178+
return color;
179+
}
180+
162181
public static void ClearGlobalCache()
163182
{
164183
_colorCache.Clear();

0 commit comments

Comments
 (0)