- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- [CustomEditor(typeof(Waypoint))]
- [CanEditMultipleObjects]
- public class WaypointEditor : Editor
- {
-
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- if (GUILayout.Button("Link Waypoints"))
- {
- Waypoint wp = (Waypoint)target;
- if (wp.edges != null)
- {
- foreach (Waypoint neighbouringWaypoint in wp.edges)
- {
- Waypoint elementLinked = null;
- foreach (Waypoint neighbourElement in neighbouringWaypoint.edges)
- {
- if (neighbourElement != null)
- {
- if (neighbourElement.Equals(wp))
- {
- elementLinked = neighbourElement;
- break;
- }
- }
- }
- if (elementLinked == null)
- {
- List<Waypoint> newWaypointList = new List<Waypoint>(neighbouringWaypoint.edges);
- newWaypointList.Add(wp);
- neighbouringWaypoint.edges = newWaypointList.ToArray();
- }
- }
- }
- }
-
- }
-
- }