Exemple #1
0
        /// <summary>
        /// Checks if a new version of the plugin is available and prompts the user to update if one is available.
        /// </summary>
        public static void Update()
        {
            var now = (int)(DateTime.UtcNow - EpochTime).TotalSeconds;

            if (EditorPrefs.HasKey(KeyLastUpdateCheckTime))
            {
                var elapsedTime = now - EditorPrefs.GetInt(KeyLastUpdateCheckTime);

                // Check if we have checked for a new version in the last 24 hrs and skip update if we have.
                if (elapsedTime < SecondsInADay)
                {
                    return;
                }
            }

            // Update last checked time.
            EditorPrefs.SetInt(KeyLastUpdateCheckTime, now);

            // Load the plugin data
            AppLovinEditorCoroutine.StartCoroutine(AppLovinIntegrationManager.Instance.LoadPluginData(data =>
            {
                if (data == null)
                {
                    return;
                }

                ShowPluginUpdateDialogIfNeeded(data);
                ShowNetworkAdaptersUpdateDialogIfNeeded(data);
            }));
        }
Exemple #2
0
        /// <summary>
        /// Loads the plugin data to be displayed by this window.
        /// </summary>
        private void Load()
        {
            loadDataCoroutine = AppLovinEditorCoroutine.StartCoroutine(AppLovinIntegrationManager.Instance.LoadPluginData(data =>
            {
                if (data == null)
                {
                    pluginDataLoadFailed = true;
                }
                else
                {
                    pluginData           = data;
                    pluginDataLoadFailed = false;
                }

                CalculateFieldWidth();
                Repaint();
            }));
        }
        /// <summary>
        /// Draws AppLovin MAX plugin details.
        /// </summary>
        private void DrawPluginDetails()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            using (new EditorGUILayout.VerticalScope("box"))
            {
                // Draw plugin version details
                DrawHeaders("Platform", false);

                // Immediately after downloading and importing a plugin the entire IDE reloads and current versions can be null in that case. Will just show loading text in that case.
                if (pluginData == null || pluginData.AppLovinMax.CurrentVersions == null)
                {
                    DrawEmptyPluginData();
                }
                else
                {
                    var appLovinMax = pluginData.AppLovinMax;
                    // Check if a newer version is available to enable the upgrade button.
                    var upgradeButtonEnabled = appLovinMax.CurrentToLatestVersionComparisonResult == VersionComparisonResult.Lesser;
                    DrawPluginDetailRow("Unity 3D", appLovinMax.CurrentVersions.Unity, appLovinMax.LatestVersions.Unity);
                    DrawPluginDetailRow("Android", appLovinMax.CurrentVersions.Android, appLovinMax.LatestVersions.Android);
                    DrawPluginDetailRow("iOS", appLovinMax.CurrentVersions.Ios, appLovinMax.LatestVersions.Ios);

                    // BeginHorizontal combined with FlexibleSpace makes sure that the button is centered horizontally.
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    GUI.enabled = upgradeButtonEnabled;
                    if (GUILayout.Button(new GUIContent("Upgrade"), fieldWidth))
                    {
                        AppLovinEditorCoroutine.StartCoroutine(AppLovinIntegrationManager.Instance.DownloadPlugin(appLovinMax));
                    }

                    GUI.enabled = true;
                    GUILayout.Space(5);
                    GUILayout.EndHorizontal();

                    GUILayout.Space(5);
                }
            }

            GUILayout.Space(5);
            GUILayout.EndHorizontal();
        }
Exemple #4
0
        private static void ShowPluginUpdateDialogIfNeeded(PluginData data)
        {
            // Check if publisher has disabled auto update.
            if (!EditorPrefs.GetBool(KeyAutoUpdateEnabled, true))
            {
                return;
            }

            // Check if the current and latest version are the same or if the publisher is on a newer version (on beta). If so, skip update.
            var comparison = data.AppLovinMax.CurrentToLatestVersionComparisonResult;

            if (comparison == MaxSdkUtils.VersionComparisonResult.Equal || comparison == MaxSdkUtils.VersionComparisonResult.Greater)
            {
                return;
            }

            // A new version of the plugin is available. Show a dialog to the publisher.
            var option = EditorUtility.DisplayDialogComplex(
                "AppLovin MAX Plugin Update",
                "A new version of AppLovin MAX plugin is available for download. Update now?",
                "Download",
                "Not Now",
                "Don't Ask Again");

            if (option == 0) // Download
            {
                MaxSdkLogger.UserDebug("Downloading plugin...");
                AppLovinIntegrationManager.downloadPluginProgressCallback = AppLovinIntegrationManagerWindow.OnDownloadPluginProgress;
                AppLovinEditorCoroutine.StartCoroutine(AppLovinIntegrationManager.Instance.DownloadPlugin(data.AppLovinMax));
            }
            else if (option == 1) // Not Now
            {
                // Do nothing
                MaxSdkLogger.UserDebug("Update postponed.");
            }
            else if (option == 2) // Don't Ask Again
            {
                MaxSdkLogger.UserDebug("Auto Update disabled. You can enable it again from the AppLovin Integration Manager");
                EditorPrefs.SetBool(KeyAutoUpdateEnabled, false);
            }
        }
        /// <summary>
        /// Draws the network specific details for a given network.
        /// </summary>
        private void DrawNetworkDetailRow(Network network)
        {
            string action;
            var    currentVersion = network.CurrentVersions.Unity;
            var    latestVersion  = network.LatestVersions.Unity;
            bool   isActionEnabled;
            bool   isInstalled;

            if (string.IsNullOrEmpty(currentVersion))
            {
                action          = "Install";
                currentVersion  = "Not Installed";
                isActionEnabled = true;
                isInstalled     = false;
            }
            else
            {
                isInstalled = true;

                var comparison = network.CurrentToLatestVersionComparisonResult;
                // A newer version is available
                if (comparison == VersionComparisonResult.Lesser)
                {
                    action          = "Upgrade";
                    isActionEnabled = true;
                }
                // Current installed version is newer than latest version from DB (beta version)
                else if (comparison == VersionComparisonResult.Greater)
                {
                    action          = "Installed";
                    isActionEnabled = false;
                }
                // Already on the latest version
                else
                {
                    action          = "Installed";
                    isActionEnabled = false;
                }
            }

            GUILayout.Space(4);
            using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandHeight(false)))
            {
                GUILayout.Space(5);
                EditorGUILayout.LabelField(new GUIContent(network.DisplayName), networkWidthOption);
                EditorGUILayout.LabelField(new GUIContent(currentVersion), versionWidthOption);
                GUILayout.Space(3);
                EditorGUILayout.LabelField(new GUIContent(latestVersion), versionWidthOption);
                GUILayout.Space(3);
                GUILayout.FlexibleSpace();

                if (network.RequiresUpdate)
                {
                    GUILayout.Label(new GUIContent {
                        image = alertIcon, tooltip = "Adapter not compatible, please update to the latest version."
                    }, iconStyle);
                }
                else if ((network.Name.Equals("ADMOB_NETWORK") || network.Name.Equals("GOOGLE_AD_MANAGER_NETWORK")) && shouldShowGoogleWarning)
                {
                    GUILayout.Label(new GUIContent {
                        image = warningIcon, tooltip = "You may see unexpected errors if you use different versions of the AdMob and Google Ad Manager adapter SDKs."
                    }, iconStyle);
                }

                GUI.enabled = isActionEnabled;
                if (GUILayout.Button(new GUIContent(action), fieldWidth))
                {
                    // Download the plugin.
                    AppLovinEditorCoroutine.StartCoroutine(AppLovinIntegrationManager.Instance.DownloadPlugin(network));
                }

                GUI.enabled = true;
                GUILayout.Space(2);

                GUI.enabled = isInstalled;
                if (GUILayout.Button(new GUIContent {
                    image = uninstallIcon, tooltip = "Uninstall"
                }, iconStyle))
                {
                    EditorUtility.DisplayProgressBar("Integration Manager", "Deleting " + network.Name + "...", 0.5f);
                    var pluginRoot = AppLovinIntegrationManager.MediationSpecificPluginParentDirectory;
                    foreach (var pluginFilePath in network.PluginFilePaths)
                    {
                        FileUtil.DeleteFileOrDirectory(Path.Combine(pluginRoot, pluginFilePath));
                    }

                    AppLovinIntegrationManager.UpdateCurrentVersions(network, pluginRoot);

                    // Refresh UI
                    AssetDatabase.Refresh();
                    EditorUtility.ClearProgressBar();
                }

                GUI.enabled = true;
                GUILayout.Space(5);
            }

            // Custom integration for AdMob where the user can enter the Android and iOS App IDs.
            if (network.Name.Equals("ADMOB_NETWORK") && isInstalled)
            {
                // Custom integration requires Google AdMob adapter version newer than android_19.0.1.0_ios_7.57.0.0.
                if (MaxSdkUtils.CompareUnityMediationVersions(network.CurrentVersions.Unity, "android_19.0.1.0_ios_7.57.0.0") == VersionComparisonResult.Greater)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    using (new EditorGUILayout.VerticalScope("box"))
                    {
                        string requiredVersion;
                        string warningMessage;
                        if (isPluginMoved)
                        {
                            requiredVersion = "android_19.6.0.1_ios_7.69.0.0";
                            warningMessage  = "Looks like the MAX plugin has been moved to a different directory. This requires Google adapter version newer than " + requiredVersion + " for auto-export of AdMob App ID to work correctly.";
                        }
                        else
                        {
                            requiredVersion = "android_19.2.0.0_ios_7.61.0.0";
                            warningMessage  = "The current version of AppLovin MAX plugin requires Google adapter version newer than " + requiredVersion + " to enable auto-export of AdMob App ID.";
                        }

                        GUILayout.Space(2);
                        if (MaxSdkUtils.CompareUnityMediationVersions(network.CurrentVersions.Unity, requiredVersion) == VersionComparisonResult.Greater)
                        {
                            AppLovinSettings.Instance.AdMobAndroidAppId = DrawTextField("App ID (Android)", AppLovinSettings.Instance.AdMobAndroidAppId, networkWidthOption);
                            AppLovinSettings.Instance.AdMobIosAppId     = DrawTextField("App ID (iOS)", AppLovinSettings.Instance.AdMobIosAppId, networkWidthOption);
                        }
                        else
                        {
                            EditorGUILayout.HelpBox(warningMessage, MessageType.Warning);
                        }
                    }

                    GUILayout.EndHorizontal();
                }
            }
        }