LayerGridGraphEditor.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Pathfinding {
  4. [CustomGraphEditor(typeof(LayerGridGraph), "Layered Grid Graph")]
  5. public class LayerGridGraphEditor : GridGraphEditor {
  6. public override void OnInspectorGUI (NavGraph target) {
  7. var graph = target as LayerGridGraph;
  8. base.OnInspectorGUI(target);
  9. if (graph.neighbours != NumNeighbours.Four) {
  10. Debug.Log("Note: Only 4 neighbours per grid node is allowed in this graph type");
  11. }
  12. }
  13. protected override void DrawJPS (GridGraph graph) {
  14. // No JPS for layered grid graph
  15. }
  16. protected override void DrawMiddleSection (GridGraph graph) {
  17. var layerGridGraph = graph as LayerGridGraph;
  18. DrawNeighbours(graph);
  19. layerGridGraph.characterHeight = EditorGUILayout.FloatField("Character Height", layerGridGraph.characterHeight);
  20. DrawMaxClimb(graph);
  21. DrawMaxSlope(graph);
  22. DrawErosion(graph);
  23. layerGridGraph.mergeSpanRange = EditorGUILayout.FloatField("Merge Span Range", layerGridGraph.mergeSpanRange);
  24. }
  25. protected override void DrawMaxClimb (GridGraph graph) {
  26. var layerGridGraph = graph as LayerGridGraph;
  27. base.DrawMaxClimb(graph);
  28. layerGridGraph.maxClimb = Mathf.Clamp(layerGridGraph.maxClimb, 0, layerGridGraph.characterHeight);
  29. if (layerGridGraph.maxClimb == layerGridGraph.characterHeight) {
  30. EditorGUILayout.HelpBox("Max climb needs to be smaller or equal to character height", MessageType.Info);
  31. }
  32. }
  33. protected override void DrawTextureData (GridGraph.TextureData data, GridGraph graph) {
  34. // No texture data for layered grid graphs
  35. }
  36. protected override void DrawNeighbours (GridGraph graph) {
  37. graph.neighbours = NumNeighbours.Four;
  38. EditorGUI.BeginDisabledGroup(true);
  39. EditorGUILayout.EnumPopup(new GUIContent("Connections", "Only 4 connections per node is possible on layered grid graphs"), graph.neighbours);
  40. EditorGUI.EndDisabledGroup();
  41. }
  42. protected override void DrawCutCorners (GridGraph graph) {
  43. // No corner cutting since only 4 neighbours are possible
  44. }
  45. protected override void DrawCollisionEditor (GraphCollision collision) {
  46. base.DrawCollisionEditor(collision);
  47. if (collision.thickRaycast) {
  48. EditorGUILayout.HelpBox("Note: Thick raycast cannot be used with this graph type", MessageType.Error);
  49. }
  50. }
  51. protected override void DrawUse2DPhysics (GraphCollision collision) {
  52. // 2D physics does not make sense for a layered grid graph
  53. collision.use2D = false;
  54. }
  55. }
  56. }