Skip to content

Commit 02f4dce

Browse files
committed
MonoBehaviour -> EditorWindow
GUI + logic redesign Fix caching render logic Limit uses of IMGUI Add SkyCar model example
1 parent 9c5a314 commit 02f4dce

4 files changed

Lines changed: 250 additions & 145 deletions

File tree

Assets/Models.meta

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

Assets/Plugins/MeshDebugger/Editor/IMGizmo.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
using System.Collections.Generic;
2-
using UnityEditor;
32
using UnityEngine;
43
using UnityEngine.Rendering;
54

5+
// Lightweight, Fast immediate mesh drawing. Works in runtime actually!
66
public class IMGizmo : ScriptableObject
77
{
88
private void OnEnable()
99
{
1010
hideFlags = HideFlags.DontSave;
11-
SceneView.onSceneGUIDelegate += OnRenderScene;
1211
}
1312

1413
private void OnDisable()
1514
{
1615
Clear();
17-
SceneView.onSceneGUIDelegate -= OnRenderScene;
1816
}
1917

2018
private void OnDestroy()
@@ -97,7 +95,7 @@ private float GetHandleSize(Vector3 position)
9795
Vector3 a = current.WorldToScreenPoint(position2 + transform.TransformDirection(new Vector3(0f, 0f, z)));
9896
Vector3 b = current.WorldToScreenPoint(position2 + transform.TransformDirection(new Vector3(1f, 0f, z)));
9997
float magnitude = (a - b).magnitude;
100-
result = 80f / Mathf.Max(magnitude, 0.0001f) * EditorGUIUtility.pixelsPerPoint;
98+
result = 80f / Mathf.Max(magnitude, 0.0001f) * UnityEditor.EditorGUIUtility.pixelsPerPoint;
10199
}
102100
else
103101
{
@@ -169,7 +167,7 @@ public static Color HSVToRGB(float H)
169167
return white;
170168
}
171169

172-
public void Init(Transform transform, bool depth, bool equalSize)
170+
public void Init(Transform transform, Transform camera, bool depth, bool equalSize)
173171
{
174172
if (!m_Mesh)
175173
{
@@ -185,7 +183,7 @@ public void Init(Transform transform, bool depth, bool equalSize)
185183
m_Quads.Clear();
186184

187185
m_Matrix = transform.localToWorldMatrix;
188-
m_Camera = Camera.current.transform;
186+
m_Camera = camera;
189187
m_EqualSize = equalSize;
190188
m_Layer = transform.gameObject.layer;
191189
}
@@ -234,7 +232,7 @@ public void Clear()
234232

235233
}
236234

237-
private void OnRenderScene(SceneView view)
235+
public void Render()
238236
{
239237
m_Material.SetPass(0);
240238
Graphics.DrawMeshNow(m_Mesh, m_Matrix, 0);

Assets/Plugins/MeshDebugger/Editor/IMGizmos.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44

5+
// High management from IM Gizmos, with 65K mesh split!
56
[Serializable]
67
public class IMGizmos : IDisposable
78
{
@@ -58,7 +59,7 @@ private void CreateNewIter()
5859
m_Gizmos.Add(giz);
5960
}
6061

61-
public void Init(Transform transform, bool depth, bool equalSize)
62+
public void Init(Transform transform, Transform camera, bool depth, bool equalSize)
6263
{
6364
m_TotalVert = 0;
6465
m_CurIter = 0;
@@ -67,7 +68,7 @@ public void Init(Transform transform, bool depth, bool equalSize)
6768
for (int i = 0; i < m_Gizmos.Count; i++)
6869
{
6970
m_Gizmos[i].m_Active = i == 0;
70-
m_Gizmos[i].Init(transform, depth, equalSize);
71+
m_Gizmos[i].Init(transform, camera, depth, equalSize);
7172
}
7273
}
7374

@@ -80,11 +81,27 @@ public void End()
8081
}
8182
}
8283

84+
public void Render()
85+
{
86+
for (int i = 0; i < m_Gizmos.Count; i++)
87+
{
88+
m_Gizmos[i].Render();
89+
}
90+
}
91+
8392
public void Dispose()
8493
{
8594
foreach (var item in m_Gizmos)
8695
{
8796
UnityEngine.Object.DestroyImmediate(item);
8897
}
8998
}
99+
100+
public void Clear()
101+
{
102+
foreach (var item in m_Gizmos)
103+
{
104+
item.Clear();
105+
}
106+
}
90107
}

0 commit comments

Comments
 (0)