RiderInitializer.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using Debug = UnityEngine.Debug;
  5. namespace Packages.Rider.Editor
  6. {
  7. internal class RiderInitializer
  8. {
  9. public void Initialize(string editorPath)
  10. {
  11. var assembly = EditorPluginInterop.EditorPluginAssembly;
  12. if (EditorPluginInterop.EditorPluginIsLoadedFromAssets(assembly))
  13. {
  14. 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'.");
  15. return;
  16. }
  17. var relPath = "../../plugins/rider-unity/EditorPlugin";
  18. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
  19. relPath = "Contents/plugins/rider-unity/EditorPlugin";
  20. var baseDir = Path.Combine(editorPath, relPath);
  21. var dllFile = new FileInfo(Path.Combine(baseDir, $"{EditorPluginInterop.EditorPluginAssemblyName}.dll"));
  22. if (!dllFile.Exists)
  23. dllFile = new FileInfo(Path.Combine(baseDir, $"{EditorPluginInterop.EditorPluginAssemblyNameFallback}.dll"));
  24. // use this for debugging
  25. // dllFile = new FileInfo(@"C:\Work\resharper-unity\unity\build\EditorPluginNet46\bin\Debug\net461\JetBrains.Rider.Unity.Editor.Plugin.Net46.dll");
  26. if (dllFile.Exists)
  27. {
  28. var bytes = File.ReadAllBytes(dllFile.FullName);
  29. assembly = AppDomain.CurrentDomain.Load(bytes); // doesn't lock assembly on disk
  30. // assembly = AppDomain.CurrentDomain.Load(System.Reflection.AssemblyName.GetAssemblyName(dllFile.FullName)); // use this for debugging
  31. if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.TRACE)
  32. Debug.Log($"Rider EditorPlugin loaded from {dllFile.FullName}");
  33. EditorPluginInterop.InitEntryPoint(assembly);
  34. }
  35. else
  36. {
  37. Debug.Log($"Unable to find Rider EditorPlugin {dllFile.FullName} for Unity ");
  38. }
  39. }
  40. }
  41. }