RecastMeshObjEditor.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Pathfinding {
  4. [CustomEditor(typeof(RecastMeshObj))]
  5. [CanEditMultipleObjects]
  6. public class RecastMeshObjEditor : EditorBase {
  7. SerializedProperty areaProp;
  8. SerializedProperty dynamicProp;
  9. protected override void OnEnable () {
  10. areaProp = serializedObject.FindProperty("area");
  11. dynamicProp = serializedObject.FindProperty("dynamic");
  12. }
  13. protected override void Inspector () {
  14. var customValue = 1;
  15. for (int i = 0; i < targets.Length; i++) {
  16. var script = targets[i] as RecastMeshObj;
  17. if (script.area > 0) {
  18. customValue = script.area;
  19. }
  20. }
  21. EditorGUILayout.IntPopup(areaProp, new GUIContent[] {
  22. new GUIContent("Unwalkable Surface"),
  23. new GUIContent("Walkable Surface"),
  24. new GUIContent("Custom Surface Area")
  25. }, new int[] {
  26. -1,
  27. 0,
  28. customValue
  29. },
  30. new GUIContent("Area Type")
  31. );
  32. if (areaProp.intValue < -1) {
  33. areaProp.intValue = 0;
  34. }
  35. if (!areaProp.hasMultipleDifferentValues && areaProp.intValue >= 1) {
  36. PropertyField(areaProp);
  37. }
  38. if (!areaProp.hasMultipleDifferentValues) {
  39. if (areaProp.intValue == -1) {
  40. EditorGUILayout.HelpBox("All surfaces on this mesh will be made unwalkable", MessageType.None);
  41. } else if (areaProp.intValue == 0) {
  42. EditorGUILayout.HelpBox("All surfaces on this mesh will be walkable", MessageType.None);
  43. } else if (areaProp.intValue > 0) {
  44. EditorGUILayout.HelpBox("All surfaces on this mesh will be walkable and a " +
  45. "seam will be created between the surfaces on this mesh and the surfaces on other meshes", MessageType.None);
  46. }
  47. }
  48. PropertyField(dynamicProp, "Dynamic", "Setting this value to false will give better scanning performance, but you will not be able to move the object during runtime");
  49. if (!dynamicProp.hasMultipleDifferentValues && !dynamicProp.boolValue) {
  50. EditorGUILayout.HelpBox("This object must not be moved during runtime since 'dynamic' is set to false", MessageType.Info);
  51. }
  52. }
  53. }
  54. }