Skip to content

Commit 5544a01

Browse files
authored
Merge pull request #2 from zigurous/release/1.5.0
Release/1.5.0
2 parents e35a094 + 04ac8bb commit 5544a01

21 files changed

+569
-12
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.5.0] - 2023/06/18
9+
10+
### Added
11+
12+
- New `ExitApplication` script
13+
- New `PauseApplication` script
14+
- New editor mesh debugger: Window > Analysis > Mesh Debugger
15+
- Behavior help URLs
16+
17+
### Changed
18+
19+
- Refactored the `Compare<T>` class
20+
- Changed the `Compare.Test` function to two distinct functions: `Compare.Equal` and `Compare.NotEqual`
21+
- The generics are now applied to the functions instead of the class, i.e., `Compare.Equal<int>` instead of `Compare<int>.Equal`
22+
823
## [1.4.0] - 2022/05/20
924

1025
### Added

Documentation~/articles/benchmarking.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Benchmark.Run(1000, Foo, Bar, Baz);
2323

2424
## 🎏 Compare Equality
2525

26-
Alternatively, sometimes it is useful to test if the results of two functions are equal. The **Debug Tools** package comes with another static class [Compare](/api/Zigurous.Debug/Compare-1) to handle these tests. The class uses generics to know the type of value you are looking to compare, and it returns the percentage of results that are equal.
26+
Sometimes it is useful to test if multiple functions return the same results. The **Debug Tools** package comes with another static class [Compare](/api/Zigurous.Debug/Compare-1) to handle these tests. The class uses generics to know the type of value you are looking to compare, and it returns the percentage of results that are equal (or not equal) for a given amount of iterations.
2727

2828
```csharp
29-
Compare<bool>.Test(Foo, Bar, 1000);
30-
Compare<float>.Test(Foo, Bar, 1000);
29+
Compare.Equal(Foo, Bar, 1000);
30+
Compare.NotEqual(Foo, Bar, 1000);
3131
```

Documentation~/articles/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ The **Debug Tools** package contains assets and scripts for debugging Unity proj
3030

3131
#### 🎨 [Debug Shaders](/manual/shaders)
3232

33+
#### 🖇️ [Mesh Debugger](/manual/mesh-debugger)
34+
3335
#### ✏️ [Drawing](/manual/drawing)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
slug: "/manual/mesh-debugger"
3+
---
4+
5+
# Mesh Debugger
6+
7+
The **Debug Tools** package includes a custom editor window for debugging and visualizing mesh data. To open this debugger, use the menu `Window > Analysis > Mesh Debugger`.
8+
9+
When a mesh is selected in the hierarchy while the window is open, a wireframe will be drawn around the current face of the mesh, and vertex and UV information will be shown in the editor. The window provides buttons to move to the next or previous face.
10+
11+
![](../images/mesh-debugger.jpg)

Documentation~/data/sidenav.json

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"name": "Debug Shaders",
4040
"path": "/manual/shaders"
4141
},
42+
{
43+
"name": "Mesh Debugger",
44+
"path": "/manual/mesh-debugger"
45+
},
4246
{
4347
"name": "Drawing",
4448
"path": "/manual/drawing"
96 KB
Loading

Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/MeshDebugger.cs

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Zigurous.Debug.Editor
5+
{
6+
public sealed class MeshDebugger : EditorWindow
7+
{
8+
private Mesh currentMesh;
9+
private MeshFilter currentMeshFilter;
10+
private SkinnedMeshRenderer currentSkinnedMeshRenderer;
11+
private int currentFace = 0, numFaces = 0, newFace = 0;
12+
private GUIStyle labelStyle = null;
13+
private Vector3 p1, p2, p3;
14+
15+
[MenuItem("Window/Analysis/Mesh Debugger")]
16+
public static void ShowWindow()
17+
{
18+
EditorWindow.GetWindow(typeof(MeshDebugger), true, "Mesh Debugger");
19+
}
20+
21+
private void OnEnable()
22+
{
23+
SceneView.duringSceneGui -= OnSceneGUI;
24+
SceneView.duringSceneGui += OnSceneGUI;
25+
26+
OnSelectionChange();
27+
}
28+
29+
private void OnDestroy()
30+
{
31+
SceneView.duringSceneGui -= OnSceneGUI;
32+
}
33+
34+
private void OnSelectionChange()
35+
{
36+
currentMesh = null;
37+
currentSkinnedMeshRenderer = null;
38+
numFaces = 0;
39+
40+
if (Selection.activeGameObject)
41+
{
42+
currentMeshFilter = Selection.activeGameObject.GetComponentInChildren<MeshFilter>();
43+
44+
if (currentMeshFilter != null)
45+
{
46+
currentMesh = currentMeshFilter.sharedMesh;
47+
numFaces = currentMesh.triangles.Length / 3;
48+
}
49+
else
50+
{
51+
currentSkinnedMeshRenderer = Selection.activeGameObject.GetComponentInChildren<SkinnedMeshRenderer>();
52+
53+
if (currentSkinnedMeshRenderer != null)
54+
{
55+
currentMesh = currentSkinnedMeshRenderer.sharedMesh;
56+
numFaces = currentMesh.triangles.Length / 3;
57+
}
58+
}
59+
}
60+
61+
currentFace = 0;
62+
newFace = currentFace;
63+
64+
Repaint();
65+
}
66+
67+
private void OnGUI()
68+
{
69+
if (currentMesh == null)
70+
{
71+
EditorGUILayout.LabelField("Current selection contains no mesh");
72+
return;
73+
}
74+
75+
EditorGUILayout.LabelField("Number of faces", numFaces.ToString());
76+
EditorGUILayout.LabelField("Current face", currentFace.ToString());
77+
78+
newFace = EditorGUILayout.IntField("Jump to face", currentFace);
79+
80+
if (newFace != currentFace)
81+
{
82+
if (newFace >= 0 && newFace < numFaces) {
83+
currentFace = newFace;
84+
}
85+
}
86+
87+
EditorGUILayout.BeginHorizontal();
88+
89+
if (GUILayout.Button("Previous Face"))
90+
{
91+
currentFace = (currentFace - 1) % numFaces;
92+
93+
if (currentFace < 0) {
94+
currentFace = currentFace + numFaces;
95+
}
96+
}
97+
98+
if (GUILayout.Button("Next Face")) {
99+
currentFace = (currentFace + 1) % numFaces;
100+
}
101+
102+
EditorGUILayout.EndHorizontal();
103+
104+
EditorGUILayout.Space();
105+
106+
int redIndex = currentMesh.triangles[currentFace * 3];
107+
int greenIndex = currentMesh.triangles[currentFace * 3 + 1];
108+
int blueIndex = currentMesh.triangles[currentFace * 3 + 2];
109+
110+
EditorGUILayout.LabelField("Red vertex", $"Index: {redIndex}, UV: ({currentMesh.uv[redIndex].x}, {currentMesh.uv[redIndex].y})");
111+
EditorGUILayout.LabelField("Green vertex", $"Index: {greenIndex}, UV: ({currentMesh.uv[greenIndex].x}, {currentMesh.uv[greenIndex].y})");
112+
EditorGUILayout.LabelField("Blue vertex", $"Index: {blueIndex}, UV: ({currentMesh.uv[blueIndex].x}, {currentMesh.uv[blueIndex].y})");
113+
}
114+
115+
private void OnSceneGUI(SceneView sceneView)
116+
{
117+
if (currentMesh == null) {
118+
return;
119+
}
120+
121+
int index1 = currentMesh.triangles[currentFace * 3];
122+
int index2 = currentMesh.triangles[currentFace * 3 + 1];
123+
int index3 = currentMesh.triangles[currentFace * 3 + 2];
124+
125+
if (currentMeshFilter != null)
126+
{
127+
p1 = currentMeshFilter.transform.TransformPoint(currentMesh.vertices[index1]);
128+
p2 = currentMeshFilter.transform.TransformPoint(currentMesh.vertices[index2]);
129+
p3 = currentMeshFilter.transform.TransformPoint(currentMesh.vertices[index3]);
130+
}
131+
else if (currentSkinnedMeshRenderer != null)
132+
{
133+
p1 = currentSkinnedMeshRenderer.transform.TransformPoint(currentMesh.vertices[index1]);
134+
p2 = currentSkinnedMeshRenderer.transform.TransformPoint(currentMesh.vertices[index2]);
135+
p3 = currentSkinnedMeshRenderer.transform.TransformPoint(currentMesh.vertices[index3]);
136+
}
137+
138+
Handles.color = Color.red;
139+
Handles.SphereHandleCap(0, p1, Quaternion.identity, 0.2f * HandleUtility.GetHandleSize(p1), EventType.Repaint);
140+
Handles.color = Color.green;
141+
Handles.SphereHandleCap(0, p2, Quaternion.identity, 0.2f * HandleUtility.GetHandleSize(p2), EventType.Repaint);
142+
Handles.color = Color.blue;
143+
Handles.SphereHandleCap(0, p3, Quaternion.identity, 0.2f * HandleUtility.GetHandleSize(p3), EventType.Repaint);
144+
145+
Handles.color = Color.white;
146+
Handles.DrawDottedLine(p1, p2, 5f);
147+
Handles.DrawDottedLine(p2, p3, 5f);
148+
Handles.DrawDottedLine(p3, p1, 5f);
149+
150+
if (labelStyle == null)
151+
{
152+
labelStyle = new GUIStyle(GUI.skin.label);
153+
labelStyle.normal.textColor = Color.white;
154+
labelStyle.fixedWidth = 40;
155+
labelStyle.fixedHeight = 20;
156+
labelStyle.alignment = TextAnchor.MiddleCenter;
157+
labelStyle.fontSize = 12;
158+
labelStyle.clipping = TextClipping.Overflow;
159+
}
160+
161+
Handles.Label(p1, index1.ToString(), labelStyle);
162+
Handles.Label(p2, index2.ToString(), labelStyle);
163+
Handles.Label(p3, index3.ToString(), labelStyle);
164+
165+
sceneView.Repaint();
166+
}
167+
168+
private void OnInspectorUpdate()
169+
{
170+
Repaint();
171+
}
172+
173+
}
174+
175+
}

Editor/MeshDebugger.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Zigurous.Debug.Editor.asmdef

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "Zigurous.Debug.Editor",
3+
"references": [
4+
"GUID:0186cdaa7ccbaeb4f91d3907506784d7"
5+
],
6+
"includePlatforms": [
7+
"Editor"
8+
],
9+
"excludePlatforms": [],
10+
"allowUnsafeCode": false,
11+
"overrideReferences": false,
12+
"precompiledReferences": [],
13+
"autoReferenced": true,
14+
"defineConstraints": [],
15+
"versionDefines": [],
16+
"noEngineReferences": false
17+
}

Editor/Zigurous.Debug.Editor.asmdef.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The **Debug Tools** package contains assets and scripts for debugging Unity proj
1010
- [Benchmarking](https://docs.zigurous.com/com.zigurous.debug/manual/benchmarking)
1111
- [Framerate Display](https://docs.zigurous.com/com.zigurous.debug/manual/framerate)
1212
- [Debug Shaders](https://docs.zigurous.com/com.zigurous.debug/manual/shaders)
13+
- [Mesh Debugger](https://docs.zigurous.com/com.zigurous.debug/manual/mesh-debugger)
14+
- [Drawing](https://docs.zigurous.com/com.zigurous.debug/manual/drawing)
1315

1416
## Installation
1517

Runtime/Compare.cs

+53-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
namespace Zigurous.Debug
44
{
55
/// <summary>
6-
/// Compares how many results are equal between two functions.
6+
/// Compares the results of multiple functions for equality.
77
/// </summary>
8-
/// <typeparam name="T">The type of value to compare.</typeparam>
9-
public static class Compare<T> where T: IEquatable<T>
8+
public static class Compare
109
{
1110
/// <summary>
12-
/// Tests the equality of the results of two functions with a given
11+
/// Compares how many results of the two functions are equal for a given
1312
/// amount of iterations.
1413
/// </summary>
1514
/// <param name="foo">The first function to execute.</param>
@@ -18,7 +17,8 @@ public static class Compare<T> where T: IEquatable<T>
1817
/// <param name="log">Logs the final comparison result.</param>
1918
/// <param name="logIndividual">Logs the result of each iteration of the functions.</param>
2019
/// <returns>The percentage of equal results.</returns>
21-
public static float Test(Func<T> foo, Func<T> bar, int iterations, bool log = true, bool logIndividual = false)
20+
public static float Equal<T>(Func<T> foo, Func<T> bar, int iterations, bool log = true, bool logIndividual = false)
21+
where T : IEquatable<T>
2222
{
2323
#if UNITY_EDITOR || DEVELOPMENT_BUILD
2424
int amountEqual = 0;
@@ -29,7 +29,10 @@ public static float Test(Func<T> foo, Func<T> bar, int iterations, bool log = tr
2929
T resultBar = bar();
3030

3131
bool equal = resultFoo.Equals(resultBar);
32-
if (equal) amountEqual++;
32+
33+
if (equal) {
34+
amountEqual++;
35+
}
3336

3437
if (log && logIndividual) {
3538
UnityEngine.Debug.Log($"[Compare] {resultFoo.ToString()} vs {resultBar.ToString()} | {(equal ? "Equal" : "Not Equal")}");
@@ -48,6 +51,50 @@ public static float Test(Func<T> foo, Func<T> bar, int iterations, bool log = tr
4851
#endif
4952
}
5053

54+
/// <summary>
55+
/// Compares how many results of the two functions are not equal for a
56+
/// given amount of iterations.
57+
/// </summary>
58+
/// <param name="foo">The first function to execute.</param>
59+
/// <param name="bar">The second function to execute.</param>
60+
/// <param name="iterations">The amount of times each function is executed.</param>
61+
/// <param name="log">Logs the final comparison result.</param>
62+
/// <param name="logIndividual">Logs the result of each iteration of the functions.</param>
63+
/// <returns>The percentage of equal results.</returns>
64+
public static float NotEqual<T>(Func<T> foo, Func<T> bar, int iterations, bool log = true, bool logIndividual = false)
65+
where T : IEquatable<T>
66+
{
67+
#if UNITY_EDITOR || DEVELOPMENT_BUILD
68+
int amountNotEqual = 0;
69+
70+
for (int i = 0; i < iterations; i++)
71+
{
72+
T resultFoo = foo();
73+
T resultBar = bar();
74+
75+
bool equal = resultFoo.Equals(resultBar);
76+
77+
if (!equal) {
78+
amountNotEqual++;
79+
}
80+
81+
if (log && logIndividual) {
82+
UnityEngine.Debug.Log($"[Compare] {resultFoo.ToString()} vs {resultBar.ToString()} | {(equal ? "Equal" : "Not Equal")}");
83+
}
84+
}
85+
86+
float percentNotEqual = (float)amountNotEqual / (float)iterations;
87+
88+
if (log) {
89+
UnityEngine.Debug.Log($"[Compare] {amountNotEqual.ToString()}/{iterations.ToString()} ({(percentNotEqual * 100f).ToString()}%) not equal results");
90+
}
91+
92+
return percentNotEqual;
93+
#else
94+
return float.NaN;
95+
#endif
96+
}
97+
5198
}
5299

53100
}

0 commit comments

Comments
 (0)