Skip to content

Instantly share code, notes, and snippets.

@hiepnd
Created October 30, 2015 02:32
Show Gist options
  • Save hiepnd/ddc8ff5826b8cd56883a to your computer and use it in GitHub Desktop.
Save hiepnd/ddc8ff5826b8cd56883a to your computer and use it in GitHub Desktop.
Alternative to OnDrawGizmos
using UnityEngine;
using UnityEditor;
// http://unity3d.com/learn/tutorials/modules/intermediate/unity-tips-and-tricks-grab-bag
[CustomEditor(typeof(CharacterNavigation))]
public class CharacterNavigationEditor : Editor
{
static bool visualizePath = false;
public override void OnInspectorGUI()
{
DrawDefaultInspector();
visualizePath = EditorGUILayout.Toggle("Visualize Path", visualizePath);
}
[DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)]
static void DrawLinesForNavAgent(NavMeshAgent agent, GizmoType gizmoType)
{
if (!visualizePath || agent.path == null)
return;
Gizmos.color = Color.red;
Vector3[] points = agent.path.corners;
for (int i = 0; i < points.Length - 1; i++)
{
Gizmos.DrawLine(points[i], points[i + 1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment