-
-
Save Neferetheka/4b79487e2c52870b93b07f7ad10d6d80 to your computer and use it in GitHub Desktop.
Call from OnDrawGizmos() to draw text at Unity3D glocal position in Editor
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
static void DrawString(string text, Vector3 worldPos, Color? colour = null) { | |
UnityEditor.Handles.BeginGUI(); | |
var originalColor = GUI.color; | |
if (colour.HasValue) | |
{ | |
GUI.color = colour.Value; | |
} | |
var view = UnityEditor.SceneView.currentDrawingSceneView; | |
Vector3 screenPos = view.camera.WorldToScreenPoint(worldPos); | |
Vector2 size = GUI.skin.label.CalcSize(new GUIContent(text)); | |
GUI.Label(new Rect(screenPos.x - (size.x / 2), -screenPos.y + view.position.height + 4, size.x, size.y), text); | |
GUI.color = originalColor; | |
UnityEditor.Handles.EndGUI(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment