Created
February 14, 2018 10:50
-
-
Save simonwittber/60f32ffd122f570e9d643675c3c457a0 to your computer and use it in GitHub Desktop.
SceneView Gizmos labels that don't create clutter.
This file contains 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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
public static class CommandGizmos | |
{ | |
static GUIStyle sceneNote; | |
static CommandGizmos() | |
{ | |
sceneNote = new GUIStyle("box"); | |
sceneNote.fontStyle = FontStyle.Bold; | |
sceneNote.normal.textColor = Color.white; | |
sceneNote.margin = sceneNote.overflow = sceneNote.padding = new RectOffset(3, 3, 3, 3); | |
sceneNote.richText = true; | |
sceneNote.alignment = TextAnchor.MiddleLeft; | |
} | |
static void DrawNote(Vector3 position, string text, string warning = "", float distance = 10) | |
{ | |
if (!string.IsNullOrEmpty(warning)) | |
text = $"{text} <color=red>{warning}</color>"; | |
if ((Camera.current.transform.position - position).magnitude <= distance) | |
Handles.Label(position, text, sceneNote); | |
} | |
[DrawGizmo(GizmoType.InSelectionHierarchy | GizmoType.NotInSelectionHierarchy, typeof(Teleporter))] | |
static void DrawTeleporterGizmos(Teleporter teleporter, GizmoType gizmoType) | |
{ | |
if (teleporter.destinationTransform) | |
{ | |
DrawNote(teleporter.transform.position, "Teleport Enter"); | |
Handles.color = Color.yellow * 0.5f; | |
Handles.DrawDottedLine(teleporter.transform.position, teleporter.destinationTransform.position, 5); | |
var direction = Quaternion.LookRotation(teleporter.destinationTransform.position - teleporter.transform.position); | |
DrawNote(teleporter.destinationTransform.position, "Teleport Exit"); | |
} | |
else | |
{ | |
DrawNote(teleporter.transform.position, "Teleport Enter", "(No Destination!)"); | |
} | |
} | |
} |
Author
simonwittber
commented
Feb 14, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment