show in the scene view. and game view if you enable gizmos
Last active
March 28, 2023 22:01
-
-
Save nicloay/8abcbf620346451993a9545336c5f606 to your computer and use it in GitHub Desktop.
Print text at OnDrawGizmos() and OnDrawGizmosSelected() small utiltiy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
namespace Utils | |
{ | |
public class GizmoText : IDisposable | |
{ | |
private Rect rect = new Rect(5, 5, 120, 20); | |
private const int VERTICAL_STEP = 25; | |
public GizmoText() | |
{ | |
#if UNITY_EDITOR | |
UnityEditor.Handles.BeginGUI(); | |
#endif | |
} | |
public void AddText(string text) | |
{ | |
GUI.Label(rect, text); | |
rect.y += VERTICAL_STEP; | |
} | |
public void Dispose() | |
{ | |
#if UNITY_EDITOR | |
UnityEditor.Handles.EndGUI(); | |
#endif | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UsageExample : MonoBehaviour { | |
... | |
private void OnDrawGizmosSelected() | |
{ | |
using var gizmoText = new GizmoText(); | |
gizmoText.AddText("HelloWorld 1"); | |
gizmoText.AddText("HelloWorld 2"); | |
gizmoText.AddText("HelloWorld 3"); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment