暫無描述
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.

RiderInitializer.cs 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using Rider.Editor.Util;
  6. using UnityEngine;
  7. using Debug = UnityEngine.Debug;
  8. namespace Packages.Rider.Editor
  9. {
  10. internal class RiderInitializer
  11. {
  12. public void Initialize(string editorPath)
  13. {
  14. var assembly = EditorPluginInterop.EditorPluginAssembly;
  15. if (EditorPluginInterop.EditorPluginIsLoadedFromAssets(assembly))
  16. {
  17. Debug.LogError($"Please delete {assembly.Location}. Unity 2019.2+ loads it directly from Rider installation. To disable this, open Rider's settings, search and uncheck 'Automatically install and update Rider's Unity editor plugin'.");
  18. return;
  19. }
  20. if (assembly != null) // already loaded RIDER-92419
  21. {
  22. return;
  23. }
  24. // for debugging rider editor plugin
  25. if (RiderPathUtil.IsRiderDevEditor(editorPath))
  26. {
  27. LoadEditorPluginForDevEditor(editorPath);
  28. }
  29. else
  30. {
  31. var relPath = "../../plugins/rider-unity/EditorPlugin";
  32. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
  33. relPath = "Contents/plugins/rider-unity/EditorPlugin";
  34. var baseDir = Path.Combine(editorPath, relPath);
  35. var dllFile = new FileInfo(Path.Combine(baseDir, $"{EditorPluginInterop.EditorPluginAssemblyName}.dll"));
  36. if (!dllFile.Exists)
  37. dllFile = new FileInfo(Path.Combine(baseDir,
  38. $"{EditorPluginInterop.EditorPluginAssemblyNameFallback}.dll"));
  39. if (dllFile.Exists)
  40. {
  41. var bytes = File.ReadAllBytes(dllFile.FullName);
  42. assembly = AppDomain.CurrentDomain.Load(bytes); // doesn't lock assembly on disk
  43. if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.TRACE)
  44. Debug.Log($"Rider EditorPlugin loaded from {dllFile.FullName}");
  45. EditorPluginInterop.InitEntryPoint(assembly);
  46. }
  47. else
  48. {
  49. Debug.Log($"Unable to find Rider EditorPlugin {dllFile.FullName} for Unity ");
  50. }
  51. }
  52. }
  53. private static void LoadEditorPluginForDevEditor(string editorPath)
  54. {
  55. var file = new FileInfo(editorPath);
  56. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
  57. file = new FileInfo(Path.Combine(editorPath, "rider-dev.bat"));
  58. if (!file.Exists)
  59. {
  60. Debug.Log($"Unable to determine path to EditorPlugin from {file}");
  61. return;
  62. }
  63. var dllPath = File.ReadLines(file.FullName).FirstOrDefault();
  64. if (dllPath == null)
  65. {
  66. Debug.Log($"Unable to determine path to EditorPlugin from {file}");
  67. return;
  68. }
  69. var dllFile = new FileInfo(dllPath);
  70. if (!dllFile.Exists)
  71. {
  72. Debug.Log($"Unable to find Rider EditorPlugin {dllPath} for Unity ");
  73. return;
  74. }
  75. var assembly = AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(dllFile.FullName));
  76. if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.TRACE)
  77. Debug.Log($"Rider EditorPlugin loaded from {dllFile.FullName}");
  78. EditorPluginInterop.InitEntryPoint(assembly);
  79. }
  80. }
  81. }