Unity Viewport 显示文字

Editor

代码

1
2
3
4
5
6
7
8
9
10
11
void DrawText(Vector3 worldPos, string text, Color? colour = null)
{
Handles.BeginGUI();
if (colour.HasValue) GUI.color = colour.Value;
var view = 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.Label(new Rect(screenPos.x + 15, view.position.height - screenPos.y, size.x, size.y), text);
Handles.EndGUI();
}

Unity Viewport 显示文字
https://automask.github.io/wild/2022/06/20/lab/S_Unity_Viewport_Text/
作者
Kyle Zhou
发布于
2022年6月20日
许可协议