PluginSettings.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System.Reflection;
  2. using Unity.CodeEditor;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Packages.Rider.Editor
  6. {
  7. public class PluginSettings
  8. {
  9. public static LoggingLevel SelectedLoggingLevel
  10. {
  11. get => (LoggingLevel) EditorPrefs.GetInt("Rider_SelectedLoggingLevel", 0);
  12. set
  13. {
  14. EditorPrefs.SetInt("Rider_SelectedLoggingLevel", (int) value);
  15. }
  16. }
  17. public static bool OverrideLangVersion
  18. {
  19. get { return EditorPrefs.GetBool("Rider_OverrideLangVersion", false); }
  20. private set { EditorPrefs.SetBool("Rider_OverrideLangVersion", value);; }
  21. }
  22. public static string LangVersion
  23. {
  24. get { return EditorPrefs.GetString("Rider_LangVersion", "4"); }
  25. private set { EditorPrefs.SetString("Rider_LangVersion", value); }
  26. }
  27. public static bool LogEventsCollectorEnabled
  28. {
  29. get { return EditorPrefs.GetBool("Rider_LogEventsCollectorEnabled", true); }
  30. private set { EditorPrefs.SetBool("Rider_LogEventsCollectorEnabled", value); }
  31. }
  32. private static GUIStyle ourVersionInfoStyle = new GUIStyle()
  33. {
  34. normal = new GUIStyleState()
  35. {
  36. textColor = new Color(0, 0, 0, .6f),
  37. },
  38. margin = new RectOffset(4, 4, 4, 4),
  39. };
  40. /// <summary>
  41. /// Preferences menu layout
  42. /// </summary>
  43. /// <remarks>
  44. /// Contains all 3 toggles: Enable/Disable; Debug On/Off; Writing Launch File On/Off
  45. /// </remarks>
  46. [SettingsProvider]
  47. private static SettingsProvider RiderPreferencesItem()
  48. {
  49. if (!RiderScriptEditor.IsRiderInstallation(RiderScriptEditor.CurrentEditor))
  50. return null;
  51. if (!RiderScriptEditor.ShouldLoadEditorPlugin(RiderScriptEditor.CurrentEditor))
  52. return null;
  53. var provider = new SettingsProvider("Preferences/Rider", SettingsScope.User)
  54. {
  55. label = "Rider",
  56. keywords = new[] { "Rider" },
  57. guiHandler = (searchContext) =>
  58. {
  59. EditorGUIUtility.labelWidth = 200f;
  60. EditorGUILayout.BeginVertical();
  61. GUILayout.BeginVertical();
  62. LogEventsCollectorEnabled =
  63. EditorGUILayout.Toggle(new GUIContent("Pass Console to Rider:"), LogEventsCollectorEnabled);
  64. GUILayout.EndVertical();
  65. OverrideLangVersion = EditorGUILayout.Toggle(new GUIContent("Override LangVersion:"), OverrideLangVersion);
  66. if (OverrideLangVersion)
  67. {
  68. var workaroundUrl = "https://gist.github.com/van800/875ce55eaf88d65b105d010d7b38a8d4";
  69. var workaroundText = "Use this <color=#0000FF>workaround</color> if overriding doesn't work.";
  70. var helpLangVersion = @"Avoid overriding, unless there is no particular need.";
  71. LangVersion =
  72. EditorGUILayout.TextField(
  73. new GUIContent("LangVersion:",
  74. helpLangVersion), LangVersion);
  75. LinkButton(caption: workaroundText, url: workaroundUrl);
  76. EditorGUILayout.HelpBox(helpLangVersion, MessageType.None);
  77. }
  78. GUILayout.Label("");
  79. if (!string.IsNullOrEmpty(EditorPluginInterop.LogPath))
  80. {
  81. EditorGUILayout.BeginHorizontal();
  82. EditorGUILayout.PrefixLabel("Log file:");
  83. var previous = GUI.enabled;
  84. GUI.enabled = previous && SelectedLoggingLevel != LoggingLevel.OFF;
  85. var button = GUILayout.Button(new GUIContent("Open log"));
  86. if (button)
  87. {
  88. //UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(PluginEntryPoint.LogPath, 0);
  89. // works much faster than the commented code, when Rider is already started
  90. CodeEditor.CurrentEditor.OpenProject(EditorPluginInterop.LogPath, 0, 0);
  91. }
  92. GUI.enabled = previous;
  93. GUILayout.EndHorizontal();
  94. }
  95. var loggingMsg =
  96. @"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.";
  97. SelectedLoggingLevel =
  98. (LoggingLevel) EditorGUILayout.EnumPopup(new GUIContent("Logging Level:", loggingMsg),
  99. SelectedLoggingLevel);
  100. EditorGUILayout.HelpBox(loggingMsg, MessageType.None);
  101. var githubRepo = "https://github.com/JetBrains/resharper-unity";
  102. var caption = $"<color=#0000FF>{githubRepo}</color>";
  103. LinkButton(caption: caption, url: githubRepo);
  104. GUILayout.FlexibleSpace();
  105. GUILayout.BeginHorizontal();
  106. GUILayout.FlexibleSpace();
  107. var version = Assembly.GetExecutingAssembly().GetName().Version;
  108. GUILayout.Label("Plugin version: " + version, ourVersionInfoStyle);
  109. GUILayout.EndHorizontal();
  110. EditorGUILayout.EndVertical();
  111. }
  112. };
  113. return provider;
  114. }
  115. private static void LinkButton(string caption, string url)
  116. {
  117. var style = GUI.skin.label;
  118. style.richText = true;
  119. var bClicked = GUILayout.Button(caption, style);
  120. var rect = GUILayoutUtility.GetLastRect();
  121. rect.width = style.CalcSize(new GUIContent(caption)).x;
  122. EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
  123. if (bClicked)
  124. Application.OpenURL(url);
  125. }
  126. }
  127. }