ProjectExporterSettingsProvider.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace AssetBank.Settings
  4. {
  5. internal class ProjectExporterSettingsProvider : SettingsProvider
  6. {
  7. private SerializedObject m_Settings;
  8. private SerializedProperty m_FoldersToIgnore;
  9. private SerializedProperty m_FileExtensionsToIgnore;
  10. private SerializedProperty m_UnityTypesToIgnore;
  11. const string k_SettingsPath = "Project/Project AssetDatabase";
  12. public ProjectExporterSettingsProvider(string path, SettingsScope scope = SettingsScope.Project)
  13. : base(path, scope) {}
  14. public override void OnActivate(string searchContext, UnityEngine.UIElements.VisualElement rootElement)
  15. {
  16. m_Settings = ProjectExporterSettings.GetSerializedSettings();
  17. m_FoldersToIgnore = m_Settings.FindProperty("m_FoldersToIgnore");
  18. m_FileExtensionsToIgnore = m_Settings.FindProperty("m_FileExtensionsToIgnore");
  19. m_UnityTypesToIgnore = m_Settings.FindProperty("m_UnityTypesToIgnore");
  20. }
  21. public override void OnGUI(string searchContext)
  22. {
  23. if (m_Settings == null || m_Settings.targetObject == null)
  24. {
  25. EditorGUILayout.HelpBox("Settings asset not found. It will be created automatically.", MessageType.Info);
  26. m_Settings = ProjectExporterSettings.GetSerializedSettings();
  27. return;
  28. }
  29. m_Settings.Update();
  30. EditorGUILayout.PropertyField(m_FoldersToIgnore, new GUIContent("Folders to Ignore"), true);
  31. EditorGUILayout.PropertyField(m_FileExtensionsToIgnore, new GUIContent("File Extensions to Ignore"), true);
  32. EditorGUILayout.PropertyField(m_UnityTypesToIgnore, new GUIContent("Unity Types to Ignore"), true);
  33. if (m_Settings.hasModifiedProperties)
  34. {
  35. m_Settings.ApplyModifiedProperties();
  36. }
  37. }
  38. [SettingsProvider]
  39. public static SettingsProvider CreateSettingsProvider()
  40. {
  41. var provider = new ProjectExporterSettingsProvider(k_SettingsPath, SettingsScope.Project);
  42. provider.keywords = GetSearchKeywordsFromGUIContentProperties<Styles>();
  43. return provider;
  44. }
  45. private class Styles
  46. {
  47. public static GUIContent foldersToIgnore = new GUIContent("Folders to Ignore");
  48. public static GUIContent fileExtensionsToIgnore = new GUIContent("File Extensions to Ignore");
  49. public static GUIContent unityTypesToIgnore = new GUIContent("Unity Types to Ignore");
  50. }
  51. }
  52. }