Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NavigationPreferences.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #if UNITY_2022_2_OR_NEWER
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using VisualizationSettings = UnityEditor.AI.NavMeshVisualizationSettings;
  6. namespace Unity.AI.Navigation.Editor
  7. {
  8. class NavigationPreferencesProvider : SettingsProvider
  9. {
  10. class Styles
  11. {
  12. internal static readonly GUIContent NavMeshVisualizationSettingsLabel =
  13. EditorGUIUtility.TrTextContent("NavMesh Visualization Settings");
  14. internal static readonly GUIContent SelectedSurfacesOpacityLabel =
  15. EditorGUIUtility.TrTextContent("Selected Surfaces Opacity", "Controls the mesh transparency for surfaces inside the selection hierarchy");
  16. internal static readonly GUIContent UnselectedSurfacesOpacityLabel =
  17. EditorGUIUtility.TrTextContent("Unselected Surfaces Opacity", "Controls the mesh transparency for surfaces outside the selection hierarchy");
  18. internal static readonly GUIContent HeightMeshColorLabel =
  19. EditorGUIUtility.TrTextContent("Height Mesh Color", "Color used to display height mesh information in the scene view");
  20. internal static readonly GUIContent ResetVisualizationSettingsButtonLabel =
  21. EditorGUIUtility.TrTextContent("Reset to Defaults", "Revert visualization settings to their original values. Customized values will be lost");
  22. }
  23. NavigationPreferencesProvider(string path, SettingsScope scopes, IEnumerable<string> keywords = null)
  24. : base(path, scopes, keywords)
  25. {
  26. }
  27. public override void OnGUI(string searchContext)
  28. {
  29. using (new SettingsWindow.GUIScope())
  30. {
  31. EditorGUILayout.LabelField(Styles.NavMeshVisualizationSettingsLabel, EditorStyles.boldLabel);
  32. EditorGUI.BeginChangeCheck();
  33. // Visualization settings
  34. VisualizationSettings.selectedSurfacesOpacity = EditorGUILayout.Slider(Styles.SelectedSurfacesOpacityLabel, VisualizationSettings.selectedSurfacesOpacity, 0, 1);
  35. VisualizationSettings.unselectedSurfacesOpacity = EditorGUILayout.Slider(Styles.UnselectedSurfacesOpacityLabel, VisualizationSettings.unselectedSurfacesOpacity, 0, 1);
  36. VisualizationSettings.heightMeshColor = EditorGUILayout.ColorField(Styles.HeightMeshColorLabel, VisualizationSettings.heightMeshColor);
  37. EditorGUILayout.Space(5);
  38. EditorGUILayout.BeginHorizontal();
  39. GUILayout.FlexibleSpace();
  40. // Option to reset the visualization settings to their default values
  41. if (GUILayout.Button(Styles.ResetVisualizationSettingsButtonLabel, GUILayout.Width(160)))
  42. {
  43. VisualizationSettings.ResetSelectedSurfacesOpacity();
  44. VisualizationSettings.ResetUnselectedSurfacesOpacity();
  45. VisualizationSettings.ResetHeightMeshColor();
  46. }
  47. EditorGUILayout.Space(10);
  48. EditorGUILayout.EndHorizontal();
  49. // Repaint the scene view when settings changed to update the visualization accordingly
  50. if (EditorGUI.EndChangeCheck())
  51. {
  52. SceneView.RepaintAll();
  53. }
  54. }
  55. }
  56. [SettingsProvider]
  57. internal static SettingsProvider CreateNavigationProjectSettingProvider()
  58. {
  59. var provider = new NavigationPreferencesProvider("Preferences/AI Navigation", SettingsScope.User, GetSearchKeywordsFromGUIContentProperties<Styles>());
  60. return provider;
  61. }
  62. }
  63. }
  64. #endif