RiderInitializer.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 dllName = "JetBrains.Rider.Unity.Editor.Plugin.Full.Repacked.dll";
  18. var relPath = "../../plugins/rider-unity/EditorPlugin";
  19. if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
  20. relPath = "Contents/plugins/rider-unity/EditorPlugin";
  21. var dllFile = new FileInfo(Path.Combine(Path.Combine(editorPath, relPath), dllName));
  22. if (dllFile.Exists)
  23. {
  24. var bytes = File.ReadAllBytes(dllFile.FullName);
  25. assembly = AppDomain.CurrentDomain.Load(bytes); // doesn't lock assembly on disk
  26. // assembly = AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(dllFile.FullName)); // use this for external source debug
  27. EditorPluginInterop.InitEntryPoint(assembly);
  28. }
  29. else
  30. {
  31. Debug.Log($"Unable to find Rider EditorPlugin {dllFile.FullName} for Unity ");
  32. }
  33. }
  34. }
  35. }