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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // for debugging rider editor plugin
  21. if (RiderPathUtil.IsRiderDevEditor(editorPath))
  22. {
  23. LoadEditorPluginForDevEditor(editorPath);
  24. }
  25. else
  26. {
  27. var relPath = "../../plugins/rider-unity/EditorPlugin";
  28. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
  29. relPath = "Contents/plugins/rider-unity/EditorPlugin";
  30. var baseDir = Path.Combine(editorPath, relPath);
  31. var dllFile = new FileInfo(Path.Combine(baseDir, $"{EditorPluginInterop.EditorPluginAssemblyName}.dll"));
  32. if (!dllFile.Exists)
  33. dllFile = new FileInfo(Path.Combine(baseDir,
  34. $"{EditorPluginInterop.EditorPluginAssemblyNameFallback}.dll"));
  35. if (dllFile.Exists)
  36. {
  37. var bytes = File.ReadAllBytes(dllFile.FullName);
  38. assembly = AppDomain.CurrentDomain.Load(bytes); // doesn't lock assembly on disk
  39. if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.TRACE)
  40. Debug.Log($"Rider EditorPlugin loaded from {dllFile.FullName}");
  41. EditorPluginInterop.InitEntryPoint(assembly);
  42. }
  43. else
  44. {
  45. Debug.Log($"Unable to find Rider EditorPlugin {dllFile.FullName} for Unity ");
  46. }
  47. }
  48. }
  49. private static void LoadEditorPluginForDevEditor(string editorPath)
  50. {
  51. var file = new FileInfo(editorPath);
  52. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
  53. file = new FileInfo(Path.Combine(editorPath, "rider-dev.bat"));
  54. if (!file.Exists)
  55. {
  56. Debug.Log($"Unable to determine path to EditorPlugin from {file}");
  57. return;
  58. }
  59. var dllPath = File.ReadLines(file.FullName).FirstOrDefault();
  60. if (dllPath == null)
  61. {
  62. Debug.Log($"Unable to determine path to EditorPlugin from {file}");
  63. return;
  64. }
  65. var dllFile = new FileInfo(dllPath);
  66. if (!dllFile.Exists)
  67. {
  68. Debug.Log($"Unable to find Rider EditorPlugin {dllPath} for Unity ");
  69. return;
  70. }
  71. var assembly = AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(dllFile.FullName));
  72. if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.TRACE)
  73. Debug.Log($"Rider EditorPlugin loaded from {dllFile.FullName}");
  74. EditorPluginInterop.InitEntryPoint(assembly);
  75. }
  76. }
  77. }