Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEngine.AI;
  6.  
  7. [CustomEditor(typeof(AIWaypointNetwork))]
  8. public class AIWaypointNetworkEditor : Editor
  9. {
  10.  
  11.     public override void OnInspectorGUI()
  12.     {
  13.         AIWaypointNetwork network = (AIWaypointNetwork)target;          
  14.  
  15.         network.DisplayMode = (PathDisplayMode)EditorGUILayout.EnumPopup ("Display Mode", network.DisplayMode);
  16.         network.UIStart = EditorGUILayout.IntSlider ("Waypoint Start", network.UIStart, 0, network.Waypoints.Count-1);
  17.         network.UIEnd = EditorGUILayout.IntSlider("Waypoint End", network.UIEnd, 0, network.Waypoints.Count-1);
  18.  
  19.         DrawDefaultInspector();
  20.     }
  21.  
  22.     private void OnSceneGUI()
  23.     {
  24.         AIWaypointNetwork network = (AIWaypointNetwork)target;
  25.         for(int i=0; i<network.Waypoints.Count; i++)
  26.         {
  27.             if (network.Waypoints[i]!=null)
  28.             Handles.Label (network.Waypoints[i].position, "Waypoint "+i.ToString ());
  29.         }
  30.  
  31.         if(network.DisplayMode == PathDisplayMode.Connections)
  32.         {
  33.             Vector3[] linePoints = new Vector3[network.Waypoints.Count + 1];
  34.  
  35.             for (int i = 0; i <= network.Waypoints.Count; i++)
  36.             {
  37.                 int index = i != network.Waypoints.Count ? i : 0;
  38.                 if (network.Waypoints[index] != null)
  39.  
  40.                     linePoints[i] = network.Waypoints[index].position;
  41.                 else
  42.                 {
  43.                     linePoints[i] = new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity);
  44.                 }
  45.             }
  46.             Handles.color = Color.cyan;
  47.             Handles.DrawPolyLine(linePoints);
  48.         }
  49.         else
  50.         {
  51.             if (network.DisplayMode == PathDisplayMode.Paths)
  52.             {
  53.                 NavMeshPath path = new NavMeshPath();
  54.                 Vector3 from = network.Waypoints[network.UIStart].position;
  55.                 Vector3 to = network.Waypoints[network.UIEnd].position;
  56.  
  57.                 NavMesh.CalculatePath (from, to, NavMesh.AllAreas, path);
  58.                 Handles.color = Color.yellow;
  59.                 Handles.DrawPolyLine(path.corners);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement