AppLovinInitialize.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // MaxInitialization.cs
  3. // AppLovin MAX Unity Plugin
  4. //
  5. // Created by Thomas So on 5/24/19.
  6. // Copyright © 2019 AppLovin. All rights reserved.
  7. //
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using UnityEditor;
  11. namespace AppLovinMax.Scripts.IntegrationManager.Editor
  12. {
  13. [InitializeOnLoad]
  14. public class AppLovinInitialize
  15. {
  16. private static readonly List<string> ObsoleteNetworks = new List<string>
  17. {
  18. "AdColony",
  19. "Criteo",
  20. "Nend",
  21. "Snap",
  22. "Tapjoy",
  23. "VerizonAds",
  24. "VoodooAds"
  25. };
  26. private static readonly List<string> ObsoleteFileExportPathsToDelete = new List<string>
  27. {
  28. // The `MaxSdk/Scripts/Editor` folder contents have been moved into `MaxSdk/Scripts/IntegrationManager/Editor`.
  29. "MaxSdk/Scripts/Editor",
  30. "MaxSdk/Scripts/Editor.meta",
  31. // The `EventSystemChecker` has been renamed to `MaxEventSystemChecker`.
  32. "MaxSdk/Scripts/EventSystemChecker.cs",
  33. "MaxSdk/Scripts/EventSystemChecker.cs.meta",
  34. // Google AdMob adapter pre/post process scripts. The logic has been migrated to the main plugin.
  35. "MaxSdk/Mediation/Google/Editor/MaxGoogleInitialize.cs",
  36. "MaxSdk/Mediation/Google/Editor/MaxGoogleInitialize.cs.meta",
  37. "MaxSdk/Mediation/Google/Editor/MaxMediationGoogleUtils.cs",
  38. "MaxSdk/Mediation/Google/Editor/MaxMediationGoogleUtils.cs.meta",
  39. "MaxSdk/Mediation/Google/Editor/PostProcessor.cs",
  40. "MaxSdk/Mediation/Google/Editor/PostProcessor.cs.meta",
  41. "MaxSdk/Mediation/Google/Editor/PreProcessor.cs",
  42. "MaxSdk/Mediation/Google/Editor/PreProcessor.cs.meta",
  43. "MaxSdk/Mediation/Google/Editor/MaxSdk.Mediation.Google.Editor.asmdef",
  44. "MaxSdk/Mediation/Google/MaxSdk.Mediation.Google.Editor.asmdef.meta",
  45. "Plugins/Android/MaxMediationGoogle.androidlib",
  46. "Plugins/Android/MaxMediationGoogle.androidlib.meta",
  47. // Google Ad Manager adapter pre/post process scripts. The logic has been migrated to the main plugin.
  48. "MaxSdk/Mediation/GoogleAdManager/Editor/MaxGoogleAdManagerInitialize.cs",
  49. "MaxSdk/Mediation/GoogleAdManager/Editor/MaxGoogleAdManagerInitialize.cs.meta",
  50. "MaxSdk/Mediation/GoogleAdManager/Editor/PostProcessor.cs",
  51. "MaxSdk/Mediation/GoogleAdManager/Editor/PostProcessor.cs.meta",
  52. "MaxSdk/Mediation/GoogleAdManager/Editor/MaxSdk.Mediation.GoogleAdManager.Editor.asmdef",
  53. "MaxSdk/Mediation/GoogleAdManager/Editor/MaxSdk.Mediation.GoogleAdManager.Editor.asmdef.meta",
  54. "Plugins/Android/MaxMediationGoogleAdManager.androidlib",
  55. "Plugins/Android/MaxMediationGoogleAdManager.androidlib.meta",
  56. // The `VariableService` has been removed.
  57. "MaxSdk/Scripts/MaxVariableServiceAndroid.cs",
  58. "MaxSdk/Scripts/MaxVariableServiceAndroid.cs.meta",
  59. "MaxSdk/Scripts/MaxVariableServiceiOS.cs",
  60. "MaxSdk/Scripts/MaxVariableServiceiOS.cs.meta",
  61. "MaxSdk/Scripts/MaxVariableServiceUnityEditor.cs",
  62. "MaxSdk/Scripts/MaxVariableServiceUnityEditor.cs.meta",
  63. // The `MaxSdk/Scripts/Editor` folder contents have been moved into `MaxSdk/Scripts/IntegrationManager/Editor`.
  64. "MaxSdk/Version.md",
  65. "MaxSdk/Version.md.meta",
  66. // TODO: Add MaxTargetingData and MaxUserSegment when the plugin has enough traction.
  67. };
  68. static AppLovinInitialize()
  69. {
  70. // Don't run obsolete file cleanup logic when entering play mode.
  71. if (EditorApplication.isPlayingOrWillChangePlaymode) return;
  72. #if UNITY_IOS
  73. // Check that the publisher is targeting iOS 9.0+
  74. if (!PlayerSettings.iOS.targetOSVersionString.StartsWith("9.") && !PlayerSettings.iOS.targetOSVersionString.StartsWith("1"))
  75. {
  76. MaxSdkLogger.UserError("Detected iOS project version less than iOS 9 - The AppLovin MAX SDK WILL NOT WORK ON < iOS9!!!");
  77. }
  78. #endif
  79. var isPluginInPackageManager = AppLovinIntegrationManager.IsPluginInPackageManager;
  80. if (!isPluginInPackageManager)
  81. {
  82. var changesMade = false;
  83. foreach (var obsoleteFileExportPathToDelete in ObsoleteFileExportPathsToDelete)
  84. {
  85. var pathToDelete = MaxSdkUtils.GetAssetPathForExportPath(obsoleteFileExportPathToDelete);
  86. if (CheckExistence(pathToDelete))
  87. {
  88. MaxSdkLogger.UserDebug("Deleting obsolete file '" + pathToDelete + "' that is no longer needed.");
  89. FileUtil.DeleteFileOrDirectory(pathToDelete);
  90. changesMade = true;
  91. }
  92. }
  93. var pluginParentDir = AppLovinIntegrationManager.PluginParentDirectory;
  94. // Check if any obsolete networks are installed
  95. foreach (var obsoleteNetwork in ObsoleteNetworks)
  96. {
  97. var networkDir = Path.Combine(pluginParentDir, "MaxSdk/Mediation/" + obsoleteNetwork);
  98. if (CheckExistence(networkDir))
  99. {
  100. MaxSdkLogger.UserDebug("Deleting obsolete network " + obsoleteNetwork + " from path " + networkDir + "...");
  101. FileUtil.DeleteFileOrDirectory(networkDir);
  102. FileUtil.DeleteFileOrDirectory(networkDir + ".meta");
  103. changesMade = true;
  104. }
  105. }
  106. // Refresh UI
  107. if (changesMade)
  108. {
  109. AssetDatabase.Refresh();
  110. MaxSdkLogger.UserDebug("Obsolete networks and files removed.");
  111. }
  112. }
  113. AppLovinAutoUpdater.Update();
  114. }
  115. private static bool CheckExistence(string location)
  116. {
  117. return File.Exists(location) ||
  118. Directory.Exists(location) ||
  119. (location.EndsWith("/*") && Directory.Exists(Path.GetDirectoryName(location)));
  120. }
  121. }
  122. }