Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Editor / WaypointEditor.cs
@Rackday Rackday on 21 Aug 2024 1 KB Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. [CustomEditor(typeof(Waypoint))]
  6. [CanEditMultipleObjects]
  7. public class WaypointEditor : Editor
  8. {
  9. // Start is called before the first frame update
  10. public override void OnInspectorGUI()
  11. {
  12. base.OnInspectorGUI();
  13. if (GUILayout.Button("Link Waypoints"))
  14. {
  15. Waypoint wp = (Waypoint)target;
  16. if (wp.edges != null)
  17. {
  18. foreach (Waypoint neighbouringWaypoint in wp.edges)
  19. {
  20. Waypoint elementLinked = null;
  21. foreach (Waypoint neighbourElement in neighbouringWaypoint.edges)
  22. {
  23. if (neighbourElement != null)
  24. {
  25. if (neighbourElement.Equals(wp))
  26. {
  27. elementLinked = neighbourElement;
  28. break;
  29. }
  30. }
  31. }
  32. if (elementLinked == null)
  33. {
  34. List<Waypoint> newWaypointList = new List<Waypoint>(neighbouringWaypoint.edges);
  35. newWaypointList.Add(wp);
  36. neighbouringWaypoint.edges = newWaypointList.ToArray();
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }