mirror of
https://github.com/focus-creative-games/hybridclr_unity.git
synced 2026-11-19 14:52:41 +08:00
refactor: InstallerController find max-lower version as best match version
This commit is contained in:
@@ -35,17 +35,7 @@ namespace HybridCLR.Editor.Installer
|
||||
{
|
||||
_curVersion = ParseUnityVersion(Application.unityVersion);
|
||||
_versionManifest = GetHybridCLRVersionManifest();
|
||||
_curDefaultVersion = _versionManifest.versions.FirstOrDefault(v => {
|
||||
return _curVersion.isTuanjieEngine? v.unity_version == $"{_curVersion.major}-tuanjie"
|
||||
#if UNITY_6000_3_OR_NEWER && !UNITY_6000_5_OR_NEWER
|
||||
: v.unity_version == "6000.3.x"
|
||||
#elif UNITY_6000_5_OR_NEWER
|
||||
: v.unity_version == "6000.5.x"
|
||||
#else
|
||||
: v.unity_version == _curVersion.major.ToString()
|
||||
#endif
|
||||
;
|
||||
});
|
||||
_curDefaultVersion = FindMatchedVersion(_versionManifest.versions, _curVersion);
|
||||
PackageVersion = LoadPackageInfo().version;
|
||||
InstalledLibil2cppVersion = ReadLocalVersion();
|
||||
}
|
||||
@@ -130,6 +120,30 @@ namespace HybridCLR.Editor.Installer
|
||||
return GetMinCompatibleVersion(_curVersion.major, _curVersion.minor1);
|
||||
}
|
||||
|
||||
private HybridclrVersionInfo FindMatchedVersion(List<HybridclrVersionInfo> versions, UnityVersion curVer)
|
||||
{
|
||||
HybridclrVersionInfo bestMatch = null;
|
||||
foreach (var v in versions)
|
||||
{
|
||||
string[] versionWithEngineParts = v.unity_version.Split('-');
|
||||
if ((curVer.isTuanjieEngine && versionWithEngineParts.Length == 1) || (!curVer.isTuanjieEngine && versionWithEngineParts.Length == 2))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] versionParts = versionWithEngineParts[0].Split('.');
|
||||
if (int.Parse(versionParts[0]) == curVer.major && (versionParts.Length == 1 || int.Parse(versionParts[1]) <= curVer.minor1))
|
||||
{
|
||||
bestMatch = v;
|
||||
}
|
||||
}
|
||||
if (bestMatch == null)
|
||||
{
|
||||
throw new NotSupportedException($"No compatible version found for Unity {curVer.major}.{curVer.minor1}.{curVer.minor2}");
|
||||
}
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
private string GetMinCompatibleVersion(int majorVersion, int minorVersion)
|
||||
{
|
||||
switch(majorVersion)
|
||||
@@ -139,22 +153,14 @@ namespace HybridCLR.Editor.Installer
|
||||
case 2021: return "2021.3.0";
|
||||
case 2022: return "2022.3.0";
|
||||
case 2023: return "2023.2.0";
|
||||
case 6000:
|
||||
default:
|
||||
{
|
||||
if (minorVersion < 3)
|
||||
if (majorVersion < 2019)
|
||||
{
|
||||
return "6000.0.0";
|
||||
}
|
||||
else if (minorVersion < 5)
|
||||
{
|
||||
return "6000.3.0";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "6000.5.0";
|
||||
throw new NotSupportedException($"Unsupported major version: {majorVersion}");
|
||||
}
|
||||
return $"{majorVersion}.0.0";
|
||||
}
|
||||
default: return $"2020.3.0";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,11 +173,11 @@ namespace HybridCLR.Editor.Installer
|
||||
|
||||
public CompatibleType GetCompatibleType()
|
||||
{
|
||||
UnityVersion version = _curVersion;
|
||||
if (version == null)
|
||||
if (_curDefaultVersion == null)
|
||||
{
|
||||
return CompatibleType.Incompatible;
|
||||
}
|
||||
UnityVersion version = _curVersion;
|
||||
if ((version.major == 2019 && version.minor1 < 4)
|
||||
|| (version.major >= 2020 && version.major <= 2022 && version.minor1 < 3))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user