RVOControllerEditor.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. EditorGUILayout.Separator();
  9. EditorGUILayout.LabelField("Shape", EditorStyles.boldLabel);
  10. PropertyField("radius");
  11. Clamp("radius", 0.01f);
  12. if ((target as RVOController).movementPlane == MovementPlane.XZ) {
  13. PropertyField("height");
  14. Clamp("height", 0.01f);
  15. PropertyField("center");
  16. }
  17. EditorGUILayout.Separator();
  18. EditorGUILayout.LabelField("Avoidance", EditorStyles.boldLabel);
  19. PropertyField("agentTimeHorizon");
  20. PropertyField("obstacleTimeHorizon");
  21. PropertyField("maxNeighbours");
  22. PropertyField("layer");
  23. PropertyField("collidesWith");
  24. PropertyField("priority");
  25. EditorGUILayout.Separator();
  26. EditorGUI.BeginDisabledGroup(PropertyField("lockWhenNotMoving"));
  27. PropertyField("locked");
  28. EditorGUI.EndDisabledGroup();
  29. EditorGUILayout.Separator();
  30. PropertyField("debug");
  31. bool maxNeighboursLimit = false;
  32. bool debugAndMultithreading = false;
  33. for (int i = 0; i < targets.Length; i++) {
  34. var controller = targets[i] as RVOController;
  35. maxNeighboursLimit |= controller.rvoAgent != null && controller.rvoAgent.NeighbourCount >= controller.rvoAgent.MaxNeighbours;
  36. debugAndMultithreading |= controller.simulator != null && controller.simulator.Multithreading && controller.debug;
  37. }
  38. if (maxNeighboursLimit) {
  39. EditorGUILayout.HelpBox("Limit of how many neighbours to consider (Max Neighbours) has been reached. Some nearby agents may have been ignored. " +
  40. "To ensure all agents are taken into account you can raise the 'Max Neighbours' value at a cost to performance.", MessageType.Warning);
  41. }
  42. if (debugAndMultithreading) {
  43. 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);
  44. }
  45. if (RVOSimulator.active == null && !EditorUtility.IsPersistent(target)) {
  46. EditorGUILayout.HelpBox("There is no enabled RVOSimulator component in the scene. A single RVOSimulator component is required for local avoidance.", MessageType.Warning);
  47. }
  48. }
  49. }
  50. }