DunGenSettingsProvider.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. namespace DunGen.Editor.Settings
  4. {
  5. public static class DunGenSettingsProvider
  6. {
  7. [SettingsProvider]
  8. public static SettingsProvider CreateDunGenSettingsProvider()
  9. {
  10. var provider = new SettingsProvider("Project/DunGen", SettingsScope.Project)
  11. {
  12. guiHandler = (searchContext) =>
  13. {
  14. var settings = DunGenSettings.Instance;
  15. if (settings == null)
  16. {
  17. EditorGUILayout.HelpBox("Failed to load DunGenSettings asset", MessageType.Error);
  18. return;
  19. }
  20. var serializedSettings = new SerializedObject(settings);
  21. // Save current label width and set a wider one
  22. float originalLabelWidth = EditorGUIUtility.labelWidth;
  23. EditorGUIUtility.labelWidth = 200;
  24. EditorGUI.BeginChangeCheck();
  25. // Draw the default inspector
  26. var editor = UnityEditor.Editor.CreateEditor(settings);
  27. editor.OnInspectorGUI();
  28. // Apply changes if any were made
  29. if (EditorGUI.EndChangeCheck())
  30. {
  31. serializedSettings.ApplyModifiedProperties();
  32. //AssetDatabase.SaveAssets();
  33. }
  34. // Restore original label width
  35. EditorGUIUtility.labelWidth = originalLabelWidth;
  36. },
  37. // Populate the search keywords
  38. keywords = new HashSet<string>(new[]
  39. {
  40. "DunGen",
  41. "dungeon",
  42. "broadphase",
  43. "collision",
  44. "tile",
  45. "cache",
  46. "pool",
  47. "pooling",
  48. "tag",
  49. "tags"
  50. })
  51. };
  52. return provider;
  53. }
  54. }
  55. }