2022-09-22 08:56:07 +08:00
|
|
|
|
using System;
|
2022-10-09 03:25:56 +08:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEditor;
|
2022-09-22 08:56:07 +08:00
|
|
|
|
using UnityEngine;
|
2022-10-09 03:25:56 +08:00
|
|
|
|
|
2022-09-22 08:56:07 +08:00
|
|
|
|
|
|
|
|
|
namespace HybridCLR.Editor.Installer
|
|
|
|
|
{
|
|
|
|
|
public class InstallerWindow : EditorWindow
|
|
|
|
|
{
|
|
|
|
|
private InstallerController m_Controller;
|
|
|
|
|
|
2022-11-28 12:20:52 +08:00
|
|
|
|
string _hybridclrVersion = "";
|
|
|
|
|
string _il2cppPlusVersion = "";
|
|
|
|
|
|
2022-09-22 08:56:07 +08:00
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
m_Controller = new InstallerController();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGUI()
|
|
|
|
|
{
|
2022-10-09 03:25:56 +08:00
|
|
|
|
var rect = new Rect
|
|
|
|
|
{
|
|
|
|
|
x = EditorGUIUtility.currentViewWidth - 24,
|
|
|
|
|
y = 5,
|
|
|
|
|
width = 24,
|
|
|
|
|
height = 24
|
|
|
|
|
};
|
|
|
|
|
var content = EditorGUIUtility.IconContent("Settings");
|
|
|
|
|
content.tooltip = "点击打开HybridCLR Settings";
|
|
|
|
|
if (GUI.Button(rect, content, GUI.skin.GetStyle("IconButton")))
|
|
|
|
|
{
|
|
|
|
|
SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
|
|
|
|
|
}
|
2022-11-28 12:20:52 +08:00
|
|
|
|
|
|
|
|
|
string il2cppBranch = m_Controller.Il2CppBranch;
|
|
|
|
|
string minCompatibleVersion = m_Controller.GetMinCompatibleVersion(il2cppBranch);
|
2022-09-22 08:56:07 +08:00
|
|
|
|
GUI.enabled = true;
|
|
|
|
|
GUILayout.Space(10f);
|
|
|
|
|
EditorGUILayout.LabelField("=======================说明====================");
|
|
|
|
|
EditorGUILayout.LabelField(
|
2022-11-28 12:20:52 +08:00
|
|
|
|
$"你所在项目的Unity版本可以与il2cpp_plus版本:{il2cppBranch} 不一样。\n"
|
2022-09-22 08:56:07 +08:00
|
|
|
|
+ $"如果你的Unity的版本号 >= {minCompatibleVersion}, 可以直接安装。\n"
|
|
|
|
|
+ $"如果你的Unity的版本号 < {minCompatibleVersion}, \n"
|
2022-11-28 12:20:52 +08:00
|
|
|
|
+ $"由于安装HybridCLR时需要从il2cpp_plus兼容版本{il2cppBranch}(而不是你项目版本)拷贝il2cpp目录,\n"
|
|
|
|
|
+ $"你必须同时安装兼容版本 {il2cppBranch} 才能完成安装", EditorStyles.wordWrappedLabel);
|
2022-09-22 08:56:07 +08:00
|
|
|
|
EditorGUILayout.LabelField("==============================================");
|
2022-10-09 03:25:56 +08:00
|
|
|
|
|
2022-09-22 08:56:07 +08:00
|
|
|
|
GUILayout.Space(10f);
|
|
|
|
|
|
2022-11-28 12:20:52 +08:00
|
|
|
|
EditorGUILayout.LabelField($"当前Unity版本: {Application.unityVersion},匹配的il2cpp_plus分支: {il2cppBranch}");
|
2022-11-09 11:28:09 +08:00
|
|
|
|
GUILayout.Space(5f);
|
|
|
|
|
|
2022-09-22 08:56:07 +08:00
|
|
|
|
EditorGUILayout.BeginVertical("box");
|
2022-10-25 17:26:21 +08:00
|
|
|
|
bool hasInstall = m_Controller.HasInstalledHybridCLR();
|
|
|
|
|
EditorGUILayout.LabelField($"安装状态:{(hasInstall ? "已安装" : "未安装")}", EditorStyles.boldLabel);
|
2022-11-28 12:20:52 +08:00
|
|
|
|
|
|
|
|
|
string hybridclrLocalVersion = m_Controller.HybridclrLocalVersion;
|
|
|
|
|
string il2cppPlusLocalVersion = m_Controller.Il2cppPlusLocalVersion;
|
2022-10-25 17:26:21 +08:00
|
|
|
|
if (hasInstall)
|
|
|
|
|
{
|
2022-11-28 12:20:52 +08:00
|
|
|
|
EditorGUILayout.LabelField($"HybridCLR 版本: {hybridclrLocalVersion}");
|
2022-11-09 11:28:09 +08:00
|
|
|
|
GUILayout.Space(5f);
|
2022-11-28 12:20:52 +08:00
|
|
|
|
EditorGUILayout.LabelField($"il2cpp_plus 版本: {il2cppPlusLocalVersion}");
|
2022-11-09 11:28:09 +08:00
|
|
|
|
GUILayout.Space(5f);
|
2022-11-28 12:20:52 +08:00
|
|
|
|
//GUIInstallButton("检查更新", "检查", UpdateHybridCLR);
|
|
|
|
|
//GUILayout.Space(40f);
|
2022-10-25 17:26:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 12:35:34 +08:00
|
|
|
|
GUISelectUnityDirectory($"il2cpp_plus分支对应的Unity兼容版本的il2cpp路径", "Select");
|
2022-09-22 08:56:07 +08:00
|
|
|
|
GUILayout.Space(10f);
|
2022-11-28 12:20:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
EditorGUILayout.LabelField("待安装的 hybridclr 仓库版本号(或tag)(默认取最新版本):", GUILayout.MaxWidth(400));
|
|
|
|
|
_hybridclrVersion = EditorGUILayout.TextField(_hybridclrVersion);
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
EditorGUILayout.LabelField($"待安装的 il2cpp_plus 仓库版本号(或tag)(默认取{il2cppBranch}分支最新版本):", GUILayout.MaxWidth(400));
|
|
|
|
|
_il2cppPlusVersion = EditorGUILayout.TextField(_il2cppPlusVersion);
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIInstallButton("安装hybridclr+il2cpp_plus代码到本地目录", "安装", InitHybridCLR);
|
2022-09-22 08:56:07 +08:00
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GUIInstallButton(string content, string button, Action onClick)
|
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
EditorGUILayout.LabelField(content);
|
|
|
|
|
GUI.enabled = m_Controller.CheckValidIl2CppInstallDirectory(m_Controller.Il2CppBranch, m_Controller.Il2CppInstallDirectory) == InstallErrorCode.Ok;
|
|
|
|
|
if (GUILayout.Button(button, GUILayout.Width(100)))
|
|
|
|
|
{
|
|
|
|
|
onClick?.Invoke();
|
|
|
|
|
GUIUtility.ExitGUI();
|
|
|
|
|
}
|
|
|
|
|
GUI.enabled = true;
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
2022-10-09 03:25:56 +08:00
|
|
|
|
|
2022-09-22 08:56:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void GUISelectUnityDirectory(string content, string selectButton)
|
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
EditorGUILayout.LabelField(content, GUILayout.MaxWidth(300));
|
|
|
|
|
string il2cppInstallDirectory = m_Controller.Il2CppInstallDirectory = EditorGUILayout.TextField(m_Controller.Il2CppInstallDirectory);
|
|
|
|
|
if (GUILayout.Button(selectButton, GUILayout.Width(100)))
|
|
|
|
|
{
|
|
|
|
|
string temp = EditorUtility.OpenFolderPanel(content, m_Controller.Il2CppInstallDirectory, string.Empty);
|
|
|
|
|
if (!string.IsNullOrEmpty(temp))
|
|
|
|
|
{
|
|
|
|
|
il2cppInstallDirectory = m_Controller.Il2CppInstallDirectory = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
InstallErrorCode err = m_Controller.CheckValidIl2CppInstallDirectory(m_Controller.Il2CppBranch, il2cppInstallDirectory);
|
|
|
|
|
switch (err)
|
|
|
|
|
{
|
|
|
|
|
case InstallErrorCode.Ok:
|
2022-10-09 03:25:56 +08:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
|
case InstallErrorCode.Il2CppInstallPathNotExists:
|
2022-10-09 03:25:56 +08:00
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.HelpBox("li2cpp 路径不存在", MessageType.Error);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-28 21:48:09 +08:00
|
|
|
|
case InstallErrorCode.InvalidUnityInstallPath:
|
2022-10-09 03:25:56 +08:00
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.HelpBox($"Unity安装目录必须包含版本号,否则无法识别版本", MessageType.Error);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
|
case InstallErrorCode.Il2CppInstallPathNotMatchIl2CppBranch:
|
2022-10-09 03:25:56 +08:00
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.HelpBox($"il2cpp 版本不兼容,最小版本为 {m_Controller.GetMinCompatibleVersion(m_Controller.Il2CppBranch)}", MessageType.Error);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
|
case InstallErrorCode.NotIl2CppPath:
|
2022-10-09 03:25:56 +08:00
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.HelpBox($"当前选择的路径不是il2cpp目录(必须类似 xxx/il2cpp)", MessageType.Error);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
|
default: throw new Exception($"not support {err}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitHybridCLR()
|
|
|
|
|
{
|
2022-11-28 12:20:52 +08:00
|
|
|
|
m_Controller.InitHybridCLR(m_Controller.Il2CppBranch, m_Controller.Il2CppInstallDirectory, _hybridclrVersion, _il2cppPlusVersion);
|
2022-09-22 08:56:07 +08:00
|
|
|
|
}
|
2022-10-25 17:26:21 +08:00
|
|
|
|
|
|
|
|
|
private void UpdateHybridCLR()
|
|
|
|
|
{
|
|
|
|
|
bool hasUpdateIl2Cpp = m_Controller.HasUpdateIl2Cpp(m_Controller.Il2CppBranch);
|
|
|
|
|
if (hasUpdateIl2Cpp)
|
|
|
|
|
{
|
|
|
|
|
bool ret = EditorUtility.DisplayDialog("检查更新", "版本不一致", "更新","取消");
|
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
InitHybridCLR();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayDialog("检查更新", "暂无更新", "确定");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|