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.

PluginSettings.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Packages.Rider.Editor
  4. {
  5. internal static class PluginSettings
  6. {
  7. public static LoggingLevel SelectedLoggingLevel
  8. {
  9. get => (LoggingLevel) EditorPrefs.GetInt("Rider_SelectedLoggingLevel", 0);
  10. private set => EditorPrefs.SetInt("Rider_SelectedLoggingLevel", (int) value);
  11. }
  12. public static bool LogEventsCollectorEnabled
  13. {
  14. get => EditorPrefs.GetBool("Rider_LogEventsCollectorEnabled", true);
  15. private set => EditorPrefs.SetBool("Rider_LogEventsCollectorEnabled", value);
  16. }
  17. /// <summary>
  18. /// Preferences menu layout
  19. /// </summary>
  20. /// <remarks>
  21. /// Contains all 3 toggles: Enable/Disable; Debug On/Off; Writing Launch File On/Off
  22. /// </remarks>
  23. [SettingsProvider]
  24. private static SettingsProvider RiderPreferencesItem()
  25. {
  26. if (!RiderScriptEditor.IsRiderInstallation(RiderScriptEditor.CurrentEditor))
  27. return null;
  28. if (!RiderScriptEditorData.instance.shouldLoadEditorPlugin)
  29. return null;
  30. var provider = new SettingsProvider("Preferences/Rider", SettingsScope.User)
  31. {
  32. label = "Rider",
  33. keywords = new[] { "Rider" },
  34. guiHandler = (searchContext) =>
  35. {
  36. EditorGUIUtility.labelWidth = 200f;
  37. EditorGUILayout.BeginVertical();
  38. GUILayout.BeginVertical();
  39. LogEventsCollectorEnabled =
  40. EditorGUILayout.Toggle(new GUIContent("Pass Console to Rider:"), LogEventsCollectorEnabled);
  41. GUILayout.EndVertical();
  42. GUILayout.Label("");
  43. if (!string.IsNullOrEmpty(EditorPluginInterop.LogPath))
  44. {
  45. EditorGUILayout.BeginHorizontal();
  46. EditorGUILayout.PrefixLabel("Log file:");
  47. var previous = GUI.enabled;
  48. GUI.enabled = previous && SelectedLoggingLevel != LoggingLevel.OFF;
  49. var button = GUILayout.Button(new GUIContent("Open log"));
  50. if (button)
  51. {
  52. // would use Rider if `log` is on the list of extensions, otherwise would use editor configured in the OS
  53. UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(EditorPluginInterop.LogPath, 0);
  54. }
  55. GUI.enabled = previous;
  56. GUILayout.EndHorizontal();
  57. }
  58. var loggingMsg =
  59. @"Sets the amount of Rider Debug output. If you are about to report an issue, please select Verbose logging level and attach Unity console output to the issue.";
  60. SelectedLoggingLevel =
  61. (LoggingLevel) EditorGUILayout.EnumPopup(new GUIContent("Logging Level:", loggingMsg),
  62. SelectedLoggingLevel);
  63. EditorGUILayout.HelpBox(loggingMsg, MessageType.None);
  64. const string url = "https://github.com/JetBrains/resharper-unity";
  65. if (LinkButton(url))
  66. Application.OpenURL(url);;
  67. GUILayout.FlexibleSpace();
  68. GUILayout.BeginHorizontal();
  69. GUILayout.FlexibleSpace();
  70. var assembly = EditorPluginInterop.EditorPluginAssembly;
  71. if (assembly != null)
  72. {
  73. var version = assembly.GetName().Version;
  74. GUILayout.Label("Plugin version: " + version, new GUIStyle(GUI.skin.label)
  75. {
  76. margin = new RectOffset(4, 4, 4, 4),
  77. });
  78. }
  79. GUILayout.EndHorizontal();
  80. EditorGUILayout.EndVertical();
  81. }
  82. };
  83. return provider;
  84. }
  85. public static bool LinkButton(string url)
  86. {
  87. var bClicked = GUILayout.Button(url, RiderStyles.LinkLabelStyle);
  88. var rect = GUILayoutUtility.GetLastRect();
  89. rect.width = RiderStyles.LinkLabelStyle.CalcSize(new GUIContent(url)).x;
  90. EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
  91. return bClicked;
  92. }
  93. }
  94. }