11using System . Collections . Generic ;
2- using UnityEditor ;
32using UnityEngine ;
43using UnityEngine . Rendering ;
54
5+ // Lightweight, Fast immediate mesh drawing. Works in runtime actually!
66public 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 ) ;
0 commit comments