更新max

This commit is contained in:
2026-05-22 16:11:40 +08:00
parent dd55b961df
commit c8a5c4f2e5
69 changed files with 3719 additions and 3672 deletions
+46 -75
View File
@@ -12,7 +12,7 @@ using UnityEditor;
#endif
public class MaxSdkUtils
public static class MaxSdkUtils
{
/// <summary>
/// An Enum to be used when comparing two versions.
@@ -488,75 +488,11 @@ public class MaxSdkUtils
}
}
/// <summary>
/// Compares AppLovin MAX Unity mediation adapter plugin versions. Returns <see cref="VersionComparisonResult.Lesser"/>, <see cref="VersionComparisonResult.Equal"/>,
/// or <see cref="VersionComparisonResult.Greater"/> as the first version is less than, equal to, or greater than the second.
///
/// If a version for a specific platform is only present in one of the provided versions, the one that contains it is considered newer.
/// </summary>
/// <param name="versionA">The first version to be compared.</param>
/// <param name="versionB">The second version to be compared.</param>
/// <returns>
/// <see cref="VersionComparisonResult.Lesser"/> if versionA is less than versionB.
/// <see cref="VersionComparisonResult.Equal"/> if versionA and versionB are equal.
/// <see cref="VersionComparisonResult.Greater"/> if versionA is greater than versionB.
/// </returns>
public static VersionComparisonResult CompareUnityMediationVersions(string versionA, string versionB)
public static bool IsVersionInRange(string currentVersion, string minVersion, string maxVersion)
{
if (versionA.Equals(versionB)) return VersionComparisonResult.Equal;
// Unity version would be of format: android_w.x.y.z_ios_a.b.c.d
// For Android only versions it would be: android_w.x.y.z
// For iOS only version it would be: ios_a.b.c.d
// After splitting into their respective components, the versions would be at the odd indices.
var versionAComponents = versionA.Split('_').ToList();
var versionBComponents = versionB.Split('_').ToList();
var androidComparison = VersionComparisonResult.Equal;
if (versionA.Contains("android") && versionB.Contains("android"))
{
var androidVersionA = versionAComponents[1];
var androidVersionB = versionBComponents[1];
androidComparison = CompareVersions(androidVersionA, androidVersionB);
// Remove the Android version component so that iOS versions can be processed.
versionAComponents.RemoveRange(0, 2);
versionBComponents.RemoveRange(0, 2);
}
else if (versionA.Contains("android"))
{
androidComparison = VersionComparisonResult.Greater;
// Remove the Android version component so that iOS versions can be processed.
versionAComponents.RemoveRange(0, 2);
}
else if (versionB.Contains("android"))
{
androidComparison = VersionComparisonResult.Lesser;
// Remove the Android version component so that iOS version can be processed.
versionBComponents.RemoveRange(0, 2);
}
var iosComparison = VersionComparisonResult.Equal;
if (versionA.Contains("ios") && versionB.Contains("ios"))
{
var iosVersionA = versionAComponents[1];
var iosVersionB = versionBComponents[1];
iosComparison = CompareVersions(iosVersionA, iosVersionB);
}
else if (versionA.Contains("ios"))
{
iosComparison = VersionComparisonResult.Greater;
}
else if (versionB.Contains("ios"))
{
iosComparison = VersionComparisonResult.Lesser;
}
// If either one of the Android or iOS version is greater, the entire version should be greater.
return (androidComparison == VersionComparisonResult.Greater || iosComparison == VersionComparisonResult.Greater) ? VersionComparisonResult.Greater : VersionComparisonResult.Lesser;
var greaterThanOrEqualToMin = string.IsNullOrEmpty(minVersion) || MaxSdkUtils.CompareVersions(currentVersion, minVersion) != MaxSdkUtils.VersionComparisonResult.Lesser;
var lessThanOrEqualToMax = string.IsNullOrEmpty(maxVersion) || MaxSdkUtils.CompareVersions(currentVersion, maxVersion) != MaxSdkUtils.VersionComparisonResult.Greater;
return greaterThanOrEqualToMin && lessThanOrEqualToMax;
}
/// <summary>
@@ -581,7 +517,7 @@ public class MaxSdkUtils
var versionABetaNumber = 0;
if (isVersionABeta)
{
var components = versionA.Split(new[] { "-beta" }, StringSplitOptions.None);
var components = versionA.Split(new[] {"-beta"}, StringSplitOptions.None);
versionA = components[0];
versionABetaNumber = int.TryParse(components[1], out piece) ? piece : 0;
}
@@ -590,7 +526,7 @@ public class MaxSdkUtils
var versionBBetaNumber = 0;
if (isVersionBBeta)
{
var components = versionB.Split(new[] { "-beta" }, StringSplitOptions.None);
var components = versionB.Split(new[] {"-beta"}, StringSplitOptions.None);
versionB = components[0];
versionBBetaNumber = int.TryParse(components[1], out piece) ? piece : 0;
}
@@ -644,6 +580,16 @@ public class MaxSdkUtils
return !string.IsNullOrEmpty(toCheck);
}
/// <summary>
/// Check if the given array is null or empty.
/// </summary>
/// <param name="array">The array to be checked.</param>
/// <returns><c>true</c> if the given array is <c>null</c> or has zero length.</returns>
public static bool IsNullOrEmpty<T>(T[] array)
{
return array == null || array.Length == 0;
}
#if UNITY_EDITOR
/// <summary>
/// Gets the path of the asset in the project for a given MAX plugin export path.
@@ -652,11 +598,36 @@ public class MaxSdkUtils
/// <returns>The exported path of the MAX plugin asset or the default export path if the asset is not found.</returns>
public static string GetAssetPathForExportPath(string exportPath)
{
var defaultPath = Path.Combine("Assets", exportPath);
var assetLabelToFind = "l:al_max_export_path-" + exportPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var assetGuids = AssetDatabase.FindAssets(assetLabelToFind);
var assetLabelToFind = "al_max_export_path-" + NormalizeToUnityPath(exportPath);
var labelSearchQuery = "l:" + assetLabelToFind;
var assetGuids = AssetDatabase.FindAssets(labelSearchQuery);
return assetGuids.Length < 1 ? defaultPath : AssetDatabase.GUIDToAssetPath(assetGuids[0]);
// Search all assets returned from the label query (may include partial matches)
foreach (var guid in assetGuids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var asset = AssetDatabase.LoadMainAssetAtPath(path);
if (asset == null) continue;
var labels = AssetDatabase.GetLabels(asset);
// Check if any label exactly matches
if (labels.Any(label => label == assetLabelToFind)) return path;
}
// Fall back to the default path if no exact label match is found
return Path.Combine("Assets", exportPath);
}
/// <summary>
/// Turns a path into a Unity compatible path by replacing backslashes with forward slashes.
/// This is important when dealing with Unity's AssetDatabase, which expects paths to use forward slashes.
/// </summary>
/// <param name="path">The path to normalize</param>
/// <returns>A Unity compatible normalized path with only forward slashes.</returns>
public static string NormalizeToUnityPath(string path)
{
return path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}
#endif
}