Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Editor/CCKProcessTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ void OnGUI()
ProcessObjectFactory.displaySelectionOnly = GUI.Toggle(new Rect(position.size.x - 150, 60, 150, 30),
ProcessObjectFactory.displaySelectionOnly, "Display Selection Only");

var prevEnabled = KeyFilter.enabled;
KeyFilter.enabled = GUI.Toggle(new Rect(position.size.x - 150, 90, 150, 30),
KeyFilter.enabled, "Filter by Key");

if (KeyFilter.enabled)
{
var prevIndex = KeyFilter.selectedKeyIndex;
KeyFilter.selectedKeyIndex = EditorGUI.Popup(
new Rect(position.size.x - 150, 120, 150, 20),
KeyFilter.selectedKeyIndex,
KeyFilter.keyDisplayNames);

if (prevIndex != KeyFilter.selectedKeyIndex)
KeyFilter.BuildFilterSets();
}

if (prevEnabled != KeyFilter.enabled)
KeyFilter.BuildFilterSets();

View.Control();
}

Expand Down
2 changes: 1 addition & 1 deletion Editor/Connect/ConnectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static List<Connect> Create(List<Node> nodes)
return connects;
}

static string TrimAxis(string key)
public static string TrimAxis(string key)
{
if (key.EndsWith(".x") || key.EndsWith(".y") || key.EndsWith(".z"))
{
Expand Down
4 changes: 4 additions & 0 deletions Editor/DisplayUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ public static void Update()
var nodes = NodeFactory.Create(objects);
var connects = ConnectFactory.Create(nodes);

KeyFilter.CollectKeyNames(nodes);

ProcessObjectsAligner.Align(objects);
ConnectAligner.Align(connects);

KeyFilter.BuildFilterSets();
}
}
}
4 changes: 2 additions & 2 deletions Editor/Draw/ArrowDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void DrawNormalArrow()
{
foreach (var a in arrows)
{
if (!a.highlight)
if (!a.highlight && KeyFilter.IsArrowVisible(a))
DrawArrow(a.from, a.to, Color.gray);
}
}
Expand All @@ -24,7 +24,7 @@ public static void DrawHighlightAllow()
{
foreach (var a in arrows)
{
if (a.highlight)
if (a.highlight && KeyFilter.IsArrowVisible(a))
DrawArrow(a.from, a.to, Color.yellow);
}
}
Expand Down
1 change: 1 addition & 0 deletions Editor/Draw/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace CCKProcessTracer.Editor
public sealed class Button
{
readonly IButton parent;
public IButton Owner => parent;
public Rect rect;
public string text;
public Color textColor = new Color(0.933f, 0.933f, 0.933f, 1.000f);
Expand Down
5 changes: 4 additions & 1 deletion Editor/Draw/ButtonDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ public static void Draw()
{
foreach (var button in buttons)
{
if (!KeyFilter.IsButtonVisible(button.Owner))
continue;

var scaledRect = new Rect();
var pos = View.ProcessViewPosition(new Vector2(button.rect.x, button.rect.y));
scaledRect.x = pos.x;
scaledRect.y = pos.y;
scaledRect.width = button.rect.width * View.scale;
scaledRect.height = button.rect.height * View.scale;

var style = new GUIStyle("button");
style.normal.textColor = button.textColor;
if (GUI.Button(scaledRect, button.text, style))
Expand Down
2 changes: 1 addition & 1 deletion Editor/Draw/ObjectFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CCKProcessTracer.Editor
public sealed class ObjectFrame : IButton
{
readonly GameObject gameObject;
readonly ProcessObject processObject;
public readonly ProcessObject processObject;

public Rect rect;

Expand Down
3 changes: 3 additions & 0 deletions Editor/Draw/ObjectFrameDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public static void Draw()
{
foreach (var f in objectFrames)
{
if (!KeyFilter.IsFrameVisible(f.processObject))
continue;

Handles.color = Color.gray;

Vector3 upLeft = View.ProcessViewPosition(new Vector2(f.rect.xMin, f.rect.yMin));
Expand Down
108 changes: 108 additions & 0 deletions Editor/KeyFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System.Collections.Generic;

namespace CCKProcessTracer.Editor
{
public static class KeyFilter
{
public static bool enabled;
public static int selectedKeyIndex;
public static string[] keyDisplayNames = { "All" };

static readonly HashSet<Arrow> visibleArrows = new HashSet<Arrow>();
static readonly HashSet<IButton> visibleButtonOwners = new HashSet<IButton>();
static readonly HashSet<ProcessObject> visibleProcessObjects = new HashSet<ProcessObject>();

public static bool IsActive => enabled && selectedKeyIndex > 0;

public static string SelectedKeyName =>
IsActive ? keyDisplayNames[selectedKeyIndex] : null;

public static void CollectKeyNames(List<Node> nodes)
{
var keySet = new SortedSet<string>();
foreach (var node in nodes)
{
foreach (var key in node.useKeys)
{
if (!string.IsNullOrEmpty(key.keyName))
keySet.Add(ConnectFactory.TrimAxis(key.keyName));
}
if (!string.IsNullOrEmpty(node.receiveKeyName))
keySet.Add(ConnectFactory.TrimAxis(node.receiveKeyName));
}

var names = new List<string> { "All" };
names.AddRange(keySet);
keyDisplayNames = names.ToArray();

if (selectedKeyIndex >= keyDisplayNames.Length)
selectedKeyIndex = 0;
}

public static void BuildFilterSets()
{
visibleArrows.Clear();
visibleButtonOwners.Clear();
visibleProcessObjects.Clear();

if (!IsActive) return;

var targetKey = SelectedKeyName;

foreach (var connect in ConnectFactory.connects)
{
if (ConnectFactory.TrimAxis(connect.from.keyName) == targetKey)
{
if (connect.arrow != null)
visibleArrows.Add(connect.arrow);

visibleButtonOwners.Add(connect.from);
visibleButtonOwners.Add(connect.from.node);
visibleProcessObjects.Add(connect.from.processObject);

visibleButtonOwners.Add(connect.to);
visibleProcessObjects.Add(connect.to.processObject);
}
}

foreach (var node in NodeFactory.nodes)
{
foreach (var key in node.useKeys)
{
if (ConnectFactory.TrimAxis(key.keyName) == targetKey)
{
visibleButtonOwners.Add(key);
visibleButtonOwners.Add(node);
visibleProcessObjects.Add(node.processObject);
}
}
if (!string.IsNullOrEmpty(node.receiveKeyName) &&
ConnectFactory.TrimAxis(node.receiveKeyName) == targetKey)
{
visibleButtonOwners.Add(node);
visibleProcessObjects.Add(node.processObject);
}
}
}

public static bool IsArrowVisible(Arrow arrow)
{
if (!IsActive) return true;
return visibleArrows.Contains(arrow);
}

public static bool IsButtonVisible(IButton owner)
{
if (!IsActive) return true;
if (owner is ObjectFrame frame)
return visibleProcessObjects.Contains(frame.processObject);
return visibleButtonOwners.Contains(owner);
}

public static bool IsFrameVisible(ProcessObject processObject)
{
if (!IsActive) return true;
return visibleProcessObjects.Contains(processObject);
}
}
}
2 changes: 2 additions & 0 deletions Editor/KeyFilter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Cluster, Inc.",
"name": "mu.cluster.cck-process-tracer",
"version": "1.1.0",
"version": "1.2.0",
"displayName": "CCK Process Tracer",
"unity": "2021.3",
"description": "Visualize CCK Trigger transition",
Expand Down