PluginSettings.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Unity.CodeEditor;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Packages.Rider.Editor
  5. {
  6. internal class PluginSettings
  7. {
  8. public static LoggingLevel SelectedLoggingLevel
  9. {
  10. get => (LoggingLevel) EditorPrefs.GetInt("Rider_SelectedLoggingLevel", 0);
  11. set
  12. {
  13. EditorPrefs.SetInt("Rider_SelectedLoggingLevel", (int) value);
  14. }
  15. }
  16. public static bool LogEventsCollectorEnabled
  17. {
  18. get { return EditorPrefs.GetBool("Rider_LogEventsCollectorEnabled", true); }
  19. private set { EditorPrefs.SetBool("Rider_LogEventsCollectorEnabled", value); }
  20. }
  21. private static GUIStyle ourVersionInfoStyle = new GUIStyle()
  22. {
  23. normal = new GUIStyleState()
  24. {
  25. textColor = new Color(0, 0, 0, .6f),
  26. },
  27. margin = new RectOffset(4, 4, 4, 4),
  28. };
  29. /// <summary>
  30. /// Preferences menu layout
  31. /// </summary>
  32. /// <remarks>
  33. /// Contains all 3 toggles: Enable/Disable; Debug On/Off; Writing Launch File On/Off
  34. /// </remarks>
  35. [SettingsProvider]
  36. private static SettingsProvider RiderPreferencesItem()
  37. {
  38. if (!RiderScriptEditor.IsRiderInstallation(RiderScriptEditor.CurrentEditor))
  39. return null;
  40. if (!RiderScriptEditorData.instance.shouldLoadEditorPlugin)
  41. return null;
  42. var provider = new SettingsProvider("Preferences/Rider", SettingsScope.User)
  43. {
  44. label = "Rider",
  45. keywords = new[] { "Rider" },
  46. guiHandler = (searchContext) =>
  47. {
  48. EditorGUIUtility.labelWidth = 200f;
  49. EditorGUILayout.BeginVertical();
  50. GUILayout.BeginVertical();
  51. LogEventsCollectorEnabled =
  52. EditorGUILayout.Toggle(new GUIContent("Pass Console to Rider:"), LogEventsCollectorEnabled);
  53. GUILayout.EndVertical();
  54. GUILayout.Label("");
  55. if (!string.IsNullOrEmpty(EditorPluginInterop.LogPath))
  56. {
  57. EditorGUILayout.BeginHorizontal();
  58. EditorGUILayout.PrefixLabel("Log file:");
  59. var previous = GUI.enabled;
  60. GUI.enabled = previous && SelectedLoggingLevel != LoggingLevel.OFF;
  61. var button = GUILayout.Button(new GUIContent("Open log"));
  62. if (button)
  63. {
  64. //UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(PluginEntryPoint.LogPath, 0);
  65. // works much faster than the commented code, when Rider is already started
  66. CodeEditor.CurrentEditor.OpenProject(EditorPluginInterop.LogPath, 0, 0);
  67. }
  68. GUI.enabled = previous;
  69. GUILayout.EndHorizontal();
  70. }
  71. var loggingMsg =
  72. @"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.";
  73. SelectedLoggingLevel =
  74. (LoggingLevel) EditorGUILayout.EnumPopup(new GUIContent("Logging Level:", loggingMsg),
  75. SelectedLoggingLevel);
  76. EditorGUILayout.HelpBox(loggingMsg, MessageType.None);
  77. LinkButton("https://github.com/JetBrains/resharper-unity");
  78. GUILayout.FlexibleSpace();
  79. GUILayout.BeginHorizontal();
  80. GUILayout.FlexibleSpace();
  81. var assembly = EditorPluginInterop.EditorPluginAssembly;
  82. if (assembly != null)
  83. {
  84. var version = assembly.GetName().Version;
  85. GUILayout.Label("Plugin version: " + version, ourVersionInfoStyle);
  86. }
  87. GUILayout.EndHorizontal();
  88. EditorGUILayout.EndVertical();
  89. }
  90. };
  91. return provider;
  92. }
  93. private static void LinkButton(string url)
  94. {
  95. var style = EditorStyles.linkLabel;
  96. var bClicked = GUILayout.Button(url, style);
  97. var rect = GUILayoutUtility.GetLastRect();
  98. rect.width = style.CalcSize(new GUIContent(url)).x;
  99. EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
  100. if (bClicked)
  101. Application.OpenURL(url);
  102. }
  103. }
  104. }