AppLovinIntegrationManagerUtils.cs 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace AppLovinMax.Scripts.IntegrationManager.Editor
  5. {
  6. public static class AppLovinIntegrationManagerUtils
  7. {
  8. /// <summary>
  9. /// Compares AppLovin MAX Unity mediation adapter plugin versions. Returns <see cref="MaxSdkUtils.VersionComparisonResult.Lesser"/>, <see cref="MaxSdkUtils.VersionComparisonResult.Equal"/>,
  10. /// or <see cref="MaxSdkUtils.VersionComparisonResult.Greater"/> as the first version is less than, equal to, or greater than the second.
  11. ///
  12. /// If a version for a specific platform is only present in one of the provided versions, the one that contains it is considered newer.
  13. /// </summary>
  14. /// <param name="versionA">The first version to be compared.</param>
  15. /// <param name="versionB">The second version to be compared.</param>
  16. /// <returns>
  17. /// <see cref="MaxSdkUtils.VersionComparisonResult.Lesser"/> if versionA is less than versionB.
  18. /// <see cref="MaxSdkUtils.VersionComparisonResult.Equal"/> if versionA and versionB are equal.
  19. /// <see cref="MaxSdkUtils.VersionComparisonResult.Greater"/> if versionA is greater than versionB.
  20. /// </returns>
  21. internal static MaxSdkUtils.VersionComparisonResult CompareUnityMediationVersions(string versionA, string versionB)
  22. {
  23. if (versionA.Equals(versionB)) return MaxSdkUtils.VersionComparisonResult.Equal;
  24. // Unity version would be of format: android_w.x.y.z_ios_a.b.c.d
  25. // For Android only versions it would be: android_w.x.y.z
  26. // For iOS only version it would be: ios_a.b.c.d
  27. // After splitting into their respective components, the versions would be at the odd indices.
  28. var versionAComponents = versionA.Split('_').ToList();
  29. var versionBComponents = versionB.Split('_').ToList();
  30. var androidComparison = MaxSdkUtils.VersionComparisonResult.Equal;
  31. if (versionA.Contains("android") && versionB.Contains("android"))
  32. {
  33. var androidVersionA = versionAComponents[1];
  34. var androidVersionB = versionBComponents[1];
  35. androidComparison = MaxSdkUtils.CompareVersions(androidVersionA, androidVersionB);
  36. // Remove the Android version component so that iOS versions can be processed.
  37. versionAComponents.RemoveRange(0, 2);
  38. versionBComponents.RemoveRange(0, 2);
  39. }
  40. else if (versionA.Contains("android"))
  41. {
  42. androidComparison = MaxSdkUtils.VersionComparisonResult.Greater;
  43. // Remove the Android version component so that iOS versions can be processed.
  44. versionAComponents.RemoveRange(0, 2);
  45. }
  46. else if (versionB.Contains("android"))
  47. {
  48. androidComparison = MaxSdkUtils.VersionComparisonResult.Lesser;
  49. // Remove the Android version component so that iOS version can be processed.
  50. versionBComponents.RemoveRange(0, 2);
  51. }
  52. var iosComparison = MaxSdkUtils.VersionComparisonResult.Equal;
  53. if (versionA.Contains("ios") && versionB.Contains("ios"))
  54. {
  55. var iosVersionA = versionAComponents[1];
  56. var iosVersionB = versionBComponents[1];
  57. iosComparison = MaxSdkUtils.CompareVersions(iosVersionA, iosVersionB);
  58. }
  59. else if (versionA.Contains("ios"))
  60. {
  61. iosComparison = MaxSdkUtils.VersionComparisonResult.Greater;
  62. }
  63. else if (versionB.Contains("ios"))
  64. {
  65. iosComparison = MaxSdkUtils.VersionComparisonResult.Lesser;
  66. }
  67. // If either one of the Android or iOS version is greater, the entire version should be greater.
  68. return (androidComparison == MaxSdkUtils.VersionComparisonResult.Greater || iosComparison == MaxSdkUtils.VersionComparisonResult.Greater) ? MaxSdkUtils.VersionComparisonResult.Greater : MaxSdkUtils.VersionComparisonResult.Lesser;
  69. }
  70. }
  71. }