InstallerWindow.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace HybridCLR.Editor.Installer
  7. {
  8. public class InstallerWindow : EditorWindow
  9. {
  10. private InstallerController _controller;
  11. private bool _installFromDir;
  12. private string _installLibil2cppWithHybridclrSourceDir;
  13. private void OnEnable()
  14. {
  15. _controller = new InstallerController();
  16. }
  17. private void OnGUI()
  18. {
  19. var rect = new Rect
  20. {
  21. x = EditorGUIUtility.currentViewWidth - 24,
  22. y = 5,
  23. width = 24,
  24. height = 24
  25. };
  26. var content = EditorGUIUtility.IconContent("Settings");
  27. content.tooltip = "HybridCLR Settings";
  28. if (GUI.Button(rect, content, GUI.skin.GetStyle("IconButton")))
  29. {
  30. SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
  31. }
  32. bool hasInstall = _controller.HasInstalledHybridCLR();
  33. GUILayout.Space(10f);
  34. EditorGUILayout.BeginVertical("box");
  35. EditorGUILayout.LabelField($"Installed: {hasInstall}", EditorStyles.boldLabel);
  36. GUILayout.Space(10f);
  37. EditorGUILayout.LabelField($"Package Version: v{_controller.PackageVersion}");
  38. GUILayout.Space(5f);
  39. EditorGUILayout.LabelField($"Installed libil2cpp Version: {_controller.InstalledLibil2cppVersion ?? "Unknown"}");
  40. GUILayout.Space(5f);
  41. GUILayout.Space(10f);
  42. InstallerController.CompatibleType compatibleType = _controller.GetCompatibleType();
  43. if (compatibleType != InstallerController.CompatibleType.Incompatible)
  44. {
  45. if (compatibleType == InstallerController.CompatibleType.MaybeIncompatible)
  46. {
  47. EditorGUILayout.HelpBox($"Maybe incompatible with current version, recommend minimum compatible version:{_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}", MessageType.Warning);
  48. }
  49. EditorGUILayout.BeginHorizontal();
  50. _installFromDir = EditorGUILayout.Toggle("Copy libil2cpp from local", _installFromDir, GUILayout.MinWidth(100));
  51. EditorGUI.BeginDisabledGroup(!_installFromDir);
  52. EditorGUILayout.TextField(_installLibil2cppWithHybridclrSourceDir, GUILayout.Width(400));
  53. if (GUILayout.Button("Choose", GUILayout.Width(100)))
  54. {
  55. _installLibil2cppWithHybridclrSourceDir = EditorUtility.OpenFolderPanel("Select libil2cpp", Application.dataPath, "libil2cpp");
  56. }
  57. EditorGUI.EndDisabledGroup();
  58. EditorGUILayout.EndHorizontal();
  59. GUILayout.Space(20f);
  60. EditorGUILayout.BeginHorizontal();
  61. if (GUILayout.Button("Install", GUILayout.Width(100)))
  62. {
  63. InstallLocalHybridCLR();
  64. GUIUtility.ExitGUI();
  65. }
  66. EditorGUILayout.EndHorizontal();
  67. }
  68. else
  69. {
  70. EditorGUILayout.HelpBox($"Incompatible with current version, minimum compatible version:{_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}", MessageType.Error);
  71. }
  72. EditorGUILayout.EndVertical();
  73. }
  74. private void InstallLocalHybridCLR()
  75. {
  76. if (_installFromDir)
  77. {
  78. if (!Directory.Exists(_installLibil2cppWithHybridclrSourceDir))
  79. {
  80. Debug.LogError($"Source libil2cpp:'{_installLibil2cppWithHybridclrSourceDir}' doesn't exist.");
  81. return;
  82. }
  83. if (!File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/il2cpp-config.h") || !File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/hybridclr/RuntimeApi.cpp"))
  84. {
  85. Debug.LogError($"Source libil2cpp:' {_installLibil2cppWithHybridclrSourceDir} ' is invalid");
  86. return;
  87. }
  88. _controller.InstallFromLocal(_installLibil2cppWithHybridclrSourceDir);
  89. }
  90. else
  91. {
  92. _controller.InstallDefaultHybridCLR();
  93. }
  94. }
  95. }
  96. }