RiderInitializer.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEngine;
  6. namespace Packages.Rider.Editor
  7. {
  8. internal class RiderInitializer
  9. {
  10. public void Initialize(string editorPath)
  11. {
  12. if (EditorPluginInterop.EditorPluginIsLoadedFromAssets())
  13. {
  14. Debug.LogError($"Please delete {EditorPluginInterop.GetEditorPluginAssembly().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. // doesn't lock assembly on disk
  25. var bytes = File.ReadAllBytes(dllFile.FullName);
  26. var pdbFile = new FileInfo(Path.ChangeExtension(dllFile.FullName, ".pdb"));
  27. if (pdbFile.Exists)
  28. {
  29. AppDomain.CurrentDomain.Load(bytes, File.ReadAllBytes(pdbFile.FullName));
  30. }
  31. else
  32. {
  33. AppDomain.CurrentDomain.Load(bytes);
  34. // AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(dllFile.FullName)); // use this for external source debug
  35. }
  36. EditorPluginInterop.InitEntryPoint();
  37. }
  38. else
  39. {
  40. Debug.Log((object) ($"Unable to find Rider EditorPlugin {dllFile.FullName} for Unity "));
  41. }
  42. }
  43. }
  44. }