Skip to content

Instantly share code, notes, and snippets.

@nicloay
Last active March 28, 2023 22:01
Show Gist options
  • Save nicloay/8abcbf620346451993a9545336c5f606 to your computer and use it in GitHub Desktop.
Save nicloay/8abcbf620346451993a9545336c5f606 to your computer and use it in GitHub Desktop.
Print text at OnDrawGizmos() and OnDrawGizmosSelected() small utiltiy

image

show in the scene view. and game view if you enable gizmos

image

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
}
}
}
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