public static Rect DrawLabel(UnityEngine.Vector3 position, UnityEngine.Vector3 alignmentDirection, GUIContent content, GUIStyle style) { if (Event.current.type == EventType.Repaint) { var matrix = SceneHandles.matrix; var pt = UnityEngine.Camera.current.WorldToViewportPoint(matrix.MultiplyPoint(position)); // cull if behind camera if (pt.z < 0) { return(emptyRect); } var rect = GetLabelRect(position, alignmentDirection, content, style); SceneHandles.BeginGUI(); { GUI.Label(rect, content, style); } SceneHandles.EndGUI(); return(rect); } else if (Event.current.type == EventType.Layout) { return(GetLabelRect(position, alignmentDirection, content, style)); } return(emptyRect); }
public static Rect DrawLabel(UnityEngine.Vector3 position, UnityEngine.Vector3 alignmentDirection, int padding, string text) { var matrix = SceneHandles.matrix; var pt = UnityEngine.Camera.current.WorldToViewportPoint(matrix.MultiplyPoint(position)); // cull if behind camera if (pt.z < 0) { return(new Rect()); } var labelStyle = new LabelStyle(SceneHandles.color, padding); if (!labelStyles.TryGetValue(labelStyle, out GUIStyle style)) { style = new UnityEngine.GUIStyle(); style.normal.textColor = SceneHandles.color; style.alignment = UnityEngine.TextAnchor.UpperLeft; // some eyeballed offsets because CalcSize returns a non-centered rect style.padding.left = 4 + padding; style.padding.right = padding; style.padding.top = 1 + padding; style.padding.bottom = 4 + padding; labelStyles[labelStyle] = style; } //SceneHandles.Label(position, text, style); = alignment is broken, positioning of text on coordinate is *weird* tempContent.text = text; var size = style.CalcSize(tempContent); var halfSize = size * 0.5f; var screenpos = UnityEditor.HandleUtility.WorldToGUIPoint(position); var screendir = (UnityEditor.HandleUtility.WorldToGUIPoint(position + alignmentDirection) - screenpos).normalized; // align on the rect around the text in the direction of alignmentDirection screenpos.x += (screendir.x - 1) * halfSize.x; screenpos.y += (screendir.y - 1) * halfSize.y; var rect = new Rect(screenpos.x, screenpos.y, size.x, size.y); if (Event.current.type == EventType.Repaint) { SceneHandles.BeginGUI(); { GUI.Label(rect, tempContent, style); } SceneHandles.EndGUI(); } return(rect); }
public static void DrawSelectionRectangle(Rect rect) { var origMatrix = SceneHandles.matrix; SceneHandles.matrix = Matrix4x4.identity; if (rect.width >= 0 || rect.height >= 0) { SceneHandles.BeginGUI(); selectionRect.Draw(rect, GUIContent.none, false, false, false, false); SceneHandles.EndGUI(); } SceneHandles.matrix = origMatrix; }