NavmeshCutEditor.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Pathfinding {
  4. [CustomEditor(typeof(NavmeshCut))]
  5. [CanEditMultipleObjects]
  6. public class NavmeshCutEditor : EditorBase {
  7. protected override void Inspector () {
  8. EditorGUI.BeginChangeCheck();
  9. var type = FindProperty("type");
  10. var circleResolution = FindProperty("circleResolution");
  11. PropertyField("type", label: "Shape");
  12. EditorGUI.indentLevel++;
  13. if (!type.hasMultipleDifferentValues) {
  14. switch ((NavmeshCut.MeshType)type.intValue) {
  15. case NavmeshCut.MeshType.Circle:
  16. PropertyField("circleRadius");
  17. PropertyField("circleResolution");
  18. if (circleResolution.intValue >= 20) {
  19. EditorGUILayout.HelpBox("Be careful with large resolutions. It is often better with a relatively low resolution since it generates cleaner navmeshes with fewer nodes.", MessageType.Warning);
  20. }
  21. break;
  22. case NavmeshCut.MeshType.Rectangle:
  23. PropertyField("rectangleSize");
  24. break;
  25. case NavmeshCut.MeshType.CustomMesh:
  26. PropertyField("mesh");
  27. PropertyField("meshScale");
  28. EditorGUILayout.HelpBox("This mesh should be a planar surface. Take a look at the documentation for an example.", MessageType.Info);
  29. break;
  30. }
  31. }
  32. FloatField("height", min: 0f);
  33. PropertyField("center");
  34. EditorGUI.indentLevel--;
  35. EditorGUILayout.Separator();
  36. PropertyField("updateDistance");
  37. if (PropertyField("useRotationAndScale")) {
  38. EditorGUI.indentLevel++;
  39. FloatField("updateRotationDistance", min: 0f, max: 180f);
  40. EditorGUI.indentLevel--;
  41. }
  42. PropertyField("isDual");
  43. PropertyField("cutsAddedGeom");
  44. EditorGUI.BeginChangeCheck();
  45. PropertyField("graphMask", "Affected Graphs");
  46. bool changedMask = EditorGUI.EndChangeCheck();
  47. serializedObject.ApplyModifiedProperties();
  48. if (EditorGUI.EndChangeCheck()) {
  49. foreach (NavmeshCut tg in targets) {
  50. tg.ForceUpdate();
  51. // If the mask is changed we disable and then enable the component
  52. // to make sure it is removed from the right graphs and then added back
  53. if (changedMask && tg.enabled) {
  54. tg.enabled = false;
  55. tg.enabled = true;
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }