RVOControllerEditor.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Pathfinding.RVO {
  4. [CustomEditor(typeof(RVOController))]
  5. [CanEditMultipleObjects]
  6. public class RVOControllerEditor : EditorBase {
  7. protected override void Inspector () {
  8. Section("Shape");
  9. var ai = (target as MonoBehaviour).GetComponent<IAstarAI>();
  10. if (ai != null) {
  11. var drivenStr = "Driven by " + ai.GetType().Name + " component";
  12. EditorGUILayout.LabelField("Radius", drivenStr);
  13. if ((target as RVOController).movementPlane == MovementPlane.XZ) {
  14. EditorGUILayout.LabelField("Height", drivenStr);
  15. EditorGUILayout.LabelField("Center", drivenStr);
  16. }
  17. } else {
  18. FloatField("radiusBackingField", label: "Radius", min: 0.01f);
  19. if ((target as RVOController).movementPlane == MovementPlane.XZ) {
  20. FloatField("heightBackingField", label: "Height", min: 0.01f);
  21. PropertyField("centerBackingField", label: "Center");
  22. }
  23. }
  24. Section("Avoidance");
  25. FloatField("agentTimeHorizon", min: 0f);
  26. FloatField("obstacleTimeHorizon", min: 0f);
  27. PropertyField("maxNeighbours");
  28. PropertyField("layer");
  29. PropertyField("collidesWith");
  30. PropertyField("priority");
  31. EditorGUILayout.Separator();
  32. EditorGUI.BeginDisabledGroup(PropertyField("lockWhenNotMoving"));
  33. PropertyField("locked");
  34. EditorGUI.EndDisabledGroup();
  35. EditorGUILayout.Separator();
  36. PropertyField("debug");
  37. bool maxNeighboursLimit = false;
  38. bool debugAndMultithreading = false;
  39. for (int i = 0; i < targets.Length; i++) {
  40. var controller = targets[i] as RVOController;
  41. maxNeighboursLimit |= controller.rvoAgent != null && controller.rvoAgent.NeighbourCount >= controller.rvoAgent.MaxNeighbours;
  42. debugAndMultithreading |= controller.simulator != null && controller.simulator.Multithreading && controller.debug;
  43. }
  44. if (maxNeighboursLimit) {
  45. EditorGUILayout.HelpBox("Limit of how many neighbours to consider (Max Neighbours) has been reached. Some nearby agents may have been ignored. " +
  46. "To ensure all agents are taken into account you can raise the 'Max Neighbours' value at a cost to performance.", MessageType.Warning);
  47. }
  48. if (debugAndMultithreading) {
  49. EditorGUILayout.HelpBox("Debug mode can only be used when no multithreading is used. Set the 'Worker Threads' field on the RVOSimulator to 'None'", MessageType.Error);
  50. }
  51. if (RVOSimulator.active == null && !EditorUtility.IsPersistent(target)) {
  52. EditorGUILayout.HelpBox("There is no enabled RVOSimulator component in the scene. A single RVOSimulator component is required for local avoidance.", MessageType.Warning);
  53. }
  54. }
  55. }
  56. }