AnalyzerSettingsProvider.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. namespace IntelligentProjectAnalyzer.Editor
  5. {
  6. // This class registers the settings provider, which is what makes the settings
  7. // appear in the Project Settings window.
  8. internal static class AnalyzerSettingsProvider
  9. {
  10. private static SerializedObject _mSettings;
  11. [SettingsProvider]
  12. public static SettingsProvider CreateAnalyzerSettingsProvider()
  13. {
  14. var provider = new SettingsProvider("Project/Project AssetDatabase/Analyzer Settings", SettingsScope.Project)
  15. {
  16. label = "Analyzer Settings",
  17. guiHandler = GuiDraw,
  18. keywords = new HashSet<string>(new[] { "Analyzer", "Dependency", "Roslyn", "System", "Types" })
  19. };
  20. return provider;
  21. }
  22. private static void GuiDraw(string _)
  23. {
  24. _mSettings ??= new SerializedObject(AnalyzerSettingsCrud.GetOrCreateSettings());
  25. EditorGUILayout.HelpBox("This settings is used to determine which types are system types, when the code is analyzed to find the dependencies till it reaches the root (e.g., 'System', 'UnityEngine', 'UnityEditor').", MessageType.Info);
  26. EditorGUILayout.LabelField("Default System Types", EditorStyles.boldLabel);
  27. EditorGUI.BeginDisabledGroup(true);
  28. EditorGUILayout.TextField("System");
  29. EditorGUILayout.TextField("UnityEngine");
  30. EditorGUILayout.TextField("UnityEditor");
  31. EditorGUI.EndDisabledGroup();
  32. EditorGUILayout.Space();
  33. EditorGUILayout.LabelField("Custom System Types", EditorStyles.boldLabel);
  34. EditorGUILayout.HelpBox("Add additional namespace prefixes to be ignored by the analyzer (e.g., 'MyCompany.CoreLib').", MessageType.Info);
  35. EditorGUILayout.PropertyField(_mSettings.FindProperty("mCustomSystemTypes"), new GUIContent("Ignored Namespaces"), true);
  36. EditorGUILayout.Space();
  37. EditorGUILayout.LabelField("Custom Analysis Rules", EditorStyles.boldLabel);
  38. EditorGUILayout.HelpBox("Choose which type of unity types to analyze.", MessageType.Info);
  39. EditorGUILayout.PropertyField(_mSettings.FindProperty("mAnalyzeScripts"), new GUIContent("Analyze Scripts"));
  40. EditorGUILayout.PropertyField(_mSettings.FindProperty("mAnalyzePrefabs"), new GUIContent("Analyze Prefabs"));
  41. EditorGUILayout.PropertyField(_mSettings.FindProperty("mAnalyzeScriptableObjects"), new GUIContent("Analyze Scriptable Objects"));
  42. EditorGUILayout.PropertyField(_mSettings.FindProperty("mAnalyzeMiscellaneous"), new GUIContent("Analyze Other Assets"));
  43. if (_mSettings.hasModifiedProperties)
  44. {
  45. _mSettings.ApplyModifiedProperties();
  46. }
  47. }
  48. }
  49. }