Skip to content

Commit c98ef54

Browse files
committed
Merge branch 'dev'
2 parents c490392 + 1a7393a commit c98ef54

15 files changed

Lines changed: 366 additions & 82 deletions

Documents.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documents/imgs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
111 KB
Loading

Documents/imgs/img_sample_playablegraph_monitor.png.meta

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Scripts/GraphView/PlayableGraphView.cs

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using GBG.PlayableGraphMonitor.Editor.Node;
2+
using GBG.PlayableGraphMonitor.Editor.Utility;
23
using System.Collections.Generic;
4+
using UnityEditor;
35
using UnityEditor.Experimental.GraphView;
46
using UnityEngine;
57
using UnityEngine.Playables;
@@ -23,31 +25,29 @@ public PlayableGraphView()
2325
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
2426
}
2527

26-
public PlayableGraph GetPlayableGraph()
27-
{
28-
return _playableGraph;
29-
}
30-
3128
public void Update(PlayableGraph playableGraph)
3229
{
30+
var needFrameAll = !GraphTool.IsEqual(ref _playableGraph, ref playableGraph);
31+
32+
_playableGraph = playableGraph;
33+
3334
if (!_playableGraph.IsValid())
3435
{
3536
ClearView();
3637
}
3738

38-
if (IsEqual(ref _playableGraph, ref playableGraph))
39-
{
40-
DiffOutputNodes();
41-
}
42-
else
43-
{
44-
// playable graph changed
45-
_playableGraph = playableGraph;
46-
47-
PopulateView();
48-
}
39+
PopulateView();
4940

5041
CalculateLayout();
42+
43+
if (needFrameAll)
44+
{
45+
// wait for view initialize at least 2 frames
46+
EditorApplication.delayCall += () =>
47+
{
48+
EditorApplication.delayCall += () => { FrameAll(); };
49+
};
50+
}
5151
}
5252

5353

@@ -68,30 +68,6 @@ private void PopulateView()
6868
return;
6969
}
7070

71-
// create nodes
72-
for (int i = 0; i < _playableGraph.GetOutputCount(); i++)
73-
{
74-
var playableOutput = _playableGraph.GetOutput(i);
75-
var playableOutputNode = PlayableOutputNodeFactory.CreateNode(playableOutput);
76-
playableOutputNode.AddToContainer(this);
77-
78-
_rootOutputNodes.Add(playableOutputNode);
79-
}
80-
81-
for (int i = 0; i < _rootOutputNodes.Count; i++)
82-
{
83-
//_rootOutputNodes[i].CreateAndConnectInputNodes();
84-
_rootOutputNodes[i].Update();
85-
}
86-
}
87-
88-
private void DiffOutputNodes()
89-
{
90-
if (!_playableGraph.IsValid())
91-
{
92-
return;
93-
}
94-
9571
// mark all root nodes inactive
9672
for (int i = 0; i < _rootOutputNodes.Count; i++)
9773
{
@@ -158,24 +134,5 @@ private void CalculateLayout()
158134
origin.y += treeSize.y + NodeLayoutInfo.VerticalSpace;
159135
}
160136
}
161-
162-
163-
private static bool IsEqual(ref PlayableGraph a, ref PlayableGraph b)
164-
{
165-
if (!a.IsValid())
166-
{
167-
return !b.IsValid();
168-
}
169-
170-
if (!b.IsValid())
171-
{
172-
return false;
173-
}
174-
175-
var nameA = a.GetEditorName();
176-
var nameB = b.GetEditorName();
177-
178-
return nameA.Equals(nameB);
179-
}
180137
}
181138
}

Editor/Scripts/Node/GraphViewNode.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ public enum NodeFlag : uint
1616

1717
public readonly struct NodeInput
1818
{
19-
public UEdge Edge { get; }
19+
public readonly UEdge Edge;
2020

21-
public GraphViewNode Node { get; }
21+
public readonly GraphViewNode Node;
2222

23+
public readonly int PortIndex;
2324

24-
public NodeInput(UEdge edge, GraphViewNode node)
25+
26+
public NodeInput(UEdge edge, GraphViewNode node, int portIndex)
2527
{
2628
Edge = edge;
2729
Node = node;
30+
PortIndex = portIndex;
31+
}
32+
33+
public NodeInput Copy(NodeInput other, int portIndexOverride)
34+
{
35+
return new NodeInput(other.Edge, other.Node, portIndexOverride);
2836
}
2937
}
3038

Editor/Scripts/Node/PlayableNode.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System;
1+
using GBG.PlayableGraphMonitor.Editor.Utility;
2+
using System;
23
using UnityEditor.Experimental.GraphView;
3-
using UnityEngine;
44
using UnityEngine.Playables;
55

66
namespace GBG.PlayableGraphMonitor.Editor.Node
@@ -27,6 +27,7 @@ public override void Update()
2727

2828
if (!Playable.IsValid())
2929
{
30+
style.backgroundColor = GraphTool.GetNodeInvalidColor();
3031
return;
3132
}
3233

@@ -36,8 +37,13 @@ public override void Update()
3637
InternalInputs[i].Node.RemoveFlag(NodeFlag.Active);
3738
}
3839

40+
// diff child nodes
3941
for (int i = 0; i < Playable.GetInputCount(); i++)
4042
{
43+
// update self port color
44+
var inputWeight = Playable.GetInputWeight(i);
45+
InternalInputPorts[i].portColor = GraphTool.GetPortColor(inputWeight);
46+
4147
var inputPlayable = Playable.GetInput(i);
4248
if (!inputPlayable.IsValid())
4349
{
@@ -47,7 +53,9 @@ public override void Update()
4753
var childNodeIndex = FindChildPlayableNode(inputPlayable);
4854
if (childNodeIndex >= 0)
4955
{
50-
InternalInputs[i].Node.AddFlag(NodeFlag.Active);
56+
var input = InternalInputs[i];
57+
input.Node.AddFlag(NodeFlag.Active);
58+
InternalInputs[i] = input.Copy(input, i);
5159
continue;
5260
}
5361

@@ -60,12 +68,15 @@ public override void Update()
6068
var selfInputPort = InternalInputPorts[i];
6169
var edge = selfInputPort.ConnectTo(inputPlayableNodeOutputPort);
6270
Container.AddElement(edge);
63-
InternalInputs.Add(new NodeInput(edge, inputPlayableNode));
71+
InternalInputs.Add(new NodeInput(edge, inputPlayableNode, i));
6472
}
6573

74+
// update child nodes
6675
for (int i = InternalInputs.Count - 1; i >= 0; i--)
6776
{
6877
var input = InternalInputs[i];
78+
79+
// remove inactive child node
6980
if (!input.Node.CheckFlag(NodeFlag.Active))
7081
{
7182
Container.RemoveElement(input.Edge);
@@ -75,6 +86,11 @@ public override void Update()
7586
continue;
7687
}
7788

89+
// update child port color
90+
var inputWeight = Playable.GetInputWeight(input.PortIndex);
91+
input.Node.OutputPorts[0].portColor = GraphTool.GetPortColor(inputWeight);
92+
input.Edge.UpdateEdgeControl();
93+
7894
InternalInputs[i].Node.Update();
7995
}
8096
}
@@ -105,7 +121,7 @@ private void CreatePorts()
105121
{
106122
var inputPort = InstantiatePort<Playable>(Direction.Input);
107123
inputPort.portName = $"Input {i}";
108-
inputPort.portColor = Color.white;
124+
inputPort.portColor = GraphTool.GetPortColor(Playable.GetInputWeight(i));
109125
inputContainer.Add(inputPort);
110126
InternalInputPorts.Add(inputPort);
111127
}
@@ -114,7 +130,7 @@ private void CreatePorts()
114130
{
115131
var outputPort = InstantiatePort<Playable>(Direction.Output);
116132
outputPort.portName = $"Output {i}";
117-
outputPort.portColor = Color.white;
133+
outputPort.portColor = GraphTool.GetPortColor(1);
118134
outputContainer.Add(outputPort);
119135
InternalOutputPorts.Add(outputPort);
120136
}

Editor/Scripts/Node/PlayableNodeFactory.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
using UnityEngine.Animations;
1+
using GBG.PlayableGraphMonitor.Editor.Utility;
2+
using UnityEngine.Animations;
23
using UnityEngine.Playables;
34

45
namespace GBG.PlayableGraphMonitor.Editor.Node
56
{
67
public static class PlayableNodeFactory
78
{
9+
public const string PlayableHeader = "Playable";
10+
811
public static PlayableNode CreateNode(Playable playable)
912
{
1013
var playableType = playable.GetPlayableType();
1114
var playableTypeName = playableType.Name;
15+
var playableTypeSortName = playableTypeName
16+
.Remove(playableTypeName.Length - PlayableHeader.Length);
17+
var nodeTitle = $"{PlayableHeader}\n{playableTypeSortName}";
18+
19+
PlayableNode playableNode;
20+
21+
// todo create node by playable type
1222

1323
if (playableType == typeof(AnimationClipPlayable))
1424
{
15-
25+
//goto SET_NODE_TITLE;
1626
}
1727

1828
if (playableType == typeof(AnimationMixerPlayable))
@@ -28,11 +38,13 @@ public static PlayableNode CreateNode(Playable playable)
2838
// ...
2939

3040
// default node
31-
var playableNode = new PlayableNode(playable)
32-
{
33-
title = playableTypeName
34-
};
41+
playableNode = new PlayableNode(playable);
42+
43+
SET_NODE_TITLE:
44+
playableNode.title = nodeTitle;
45+
playableNode.SetNodeStyle(playable.GetPlayableNodeColor());
46+
3547
return playableNode;
3648
}
3749
}
38-
}
50+
}

0 commit comments

Comments
 (0)