PointGeneratorEditor.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Pathfinding {
  4. [CustomGraphEditor(typeof(PointGraph), "Point Graph")]
  5. public class PointGraphEditor : GraphEditor {
  6. static readonly GUIContent[] nearestNodeDistanceModeLabels = {
  7. new GUIContent("Node"),
  8. new GUIContent("Connection (pro version only)"),
  9. };
  10. public override void OnInspectorGUI (NavGraph target) {
  11. var graph = target as PointGraph;
  12. graph.root = ObjectField(new GUIContent("Root", "All childs of this object will be used as nodes, if it is not set, a tag search will be used instead (see below)"), graph.root, typeof(Transform), true) as Transform;
  13. graph.recursive = EditorGUILayout.Toggle(new GUIContent("Recursive", "Should childs of the childs in the root GameObject be searched"), graph.recursive);
  14. graph.searchTag = EditorGUILayout.TagField(new GUIContent("Tag", "If root is not set, all objects with this tag will be used as nodes"), graph.searchTag);
  15. if (graph.root != null) {
  16. EditorGUILayout.HelpBox("All childs "+(graph.recursive ? "and sub-childs " : "") +"of 'root' will be used as nodes\nSet root to null to use a tag search instead", MessageType.None);
  17. } else {
  18. EditorGUILayout.HelpBox("All object with the tag '"+graph.searchTag+"' will be used as nodes"+(graph.searchTag == "Untagged" ? "\nNote: the tag 'Untagged' cannot be used" : ""), MessageType.None);
  19. }
  20. graph.maxDistance = EditorGUILayout.FloatField(new GUIContent("Max Distance", "The max distance in world space for a connection to be valid. A zero counts as infinity"), graph.maxDistance);
  21. graph.limits = EditorGUILayout.Vector3Field("Max Distance (axis aligned)", graph.limits);
  22. graph.raycast = EditorGUILayout.Toggle(new GUIContent("Raycast", "Use raycasting to check if connections are valid between each pair of nodes"), graph.raycast);
  23. if (graph.raycast) {
  24. EditorGUI.indentLevel++;
  25. graph.use2DPhysics = EditorGUILayout.Toggle(new GUIContent("Use 2D Physics", "If enabled, all raycasts will use the Unity 2D Physics API instead of the 3D one."), graph.use2DPhysics);
  26. graph.thickRaycast = EditorGUILayout.Toggle(new GUIContent("Thick Raycast", "A thick raycast checks along a thick line with radius instead of just along a line"), graph.thickRaycast);
  27. if (graph.thickRaycast) {
  28. EditorGUI.indentLevel++;
  29. graph.thickRaycastRadius = EditorGUILayout.FloatField(new GUIContent("Raycast Radius", "The radius in world units for the thick raycast"), graph.thickRaycastRadius);
  30. EditorGUI.indentLevel--;
  31. }
  32. graph.mask = EditorGUILayoutx.LayerMaskField("Mask", graph.mask);
  33. EditorGUI.indentLevel--;
  34. }
  35. EditorGUILayout.Popup(new GUIContent("Nearest node queries find closest"), 0, nearestNodeDistanceModeLabels);
  36. }
  37. }
  38. }