Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
DrawString.cs
Go to the documentation of this file.
1 using UnityEditor;
2 using UnityEngine;
3 
4 #if UNITY_EDITOR
5 namespace droid.Runtime.Utilities.Misc.Drawing {
6  public static partial class NeodroidDrawingUtilities {
14  public static void DrawString(string text,
15  Vector3 world_pos,
16  Color? color = null,
17  float o_x = 0,
18  float o_y = 0) {
19  Handles.BeginGUI();
20 
21  var restore_color = GUI.color;
22 
23  if (color.HasValue) {
24  GUI.color = color.Value;
25  }
26 
27  var view = SceneView.currentDrawingSceneView;
28  var screen_pos = view.camera.WorldToScreenPoint(world_pos);
29 
30  if (screen_pos.y < 0
31  || screen_pos.y > Screen.height
32  || screen_pos.x < 0
33  || screen_pos.x > Screen.width
34  || screen_pos.z < 0) {
35  GUI.color = restore_color;
36  Handles.EndGUI();
37  return;
38  }
39 
40  Handles.Label(TransformByPixel(world_pos, o_x, o_y), text);
41 
42  GUI.color = restore_color;
43  Handles.EndGUI();
44  }
45 
52  public static Vector3 TransformByPixel(Vector3 position, float x, float y) {
53  return TransformByPixel(position, new Vector3(x, y));
54  }
55 
61  public static Vector3 TransformByPixel(Vector3 position, Vector3 translate_by) {
62  var cam = SceneView.currentDrawingSceneView.camera;
63  return cam ? cam.ScreenToWorldPoint(cam.WorldToScreenPoint(position) + translate_by) : position;
64  }
65  }
66 }
67 #endif