Skip to content

Instantly share code, notes, and snippets.

@simonwittber
Created February 14, 2018 10:50
Show Gist options
  • Save simonwittber/60f32ffd122f570e9d643675c3c457a0 to your computer and use it in GitHub Desktop.
Save simonwittber/60f32ffd122f570e9d643675c3c457a0 to your computer and use it in GitHub Desktop.
SceneView Gizmos labels that don't create clutter.
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!)");
}
}
}
@simonwittber
Copy link
Author

screen shot 2018-02-14 at 10 51 05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment