Created
December 1, 2016 08:26
-
-
Save kennir/6a45deb62cbed338dca669926b63dc7f to your computer and use it in GitHub Desktop.
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 public void drawString(string text, Vector3 worldPos, Color? colour = null) { | |
UnityEditor.Handles.BeginGUI(); | |
var restoreColor = GUI.color; | |
if (colour.HasValue) GUI.color = colour.Value; | |
var view = UnityEditor.SceneView.currentDrawingSceneView; | |
Vector3 screenPos = view.camera.WorldToScreenPoint(worldPos); | |
if (screenPos.y < 0 || screenPos.y > Screen.height || screenPos.x < 0 || screenPos.x > Screen.width || screenPos.z < 0) | |
{ | |
GUI.color = restoreColor; | |
UnityEditor.Handles.EndGUI(); | |
return; | |
} | |
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 = restoreColor; | |
UnityEditor.Handles.EndGUI(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment