コード例 #1
0
        public void OnPostGenerateGradleAndroidProject(string path)
        {
#if UNITY_2019_3_OR_NEWER
            // On Unity 2019.3+, the path returned is the path to the unityLibrary's module.
            // The AppLovin Quality Service buildscript closure related lines need to be added to the root build.gradle file.
            var rootGradleBuildFilePath = Path.Combine(path, "../build.gradle");
            var buildScriptChangesAdded = AddQualityServiceBuildScriptLines(rootGradleBuildFilePath);
            if (!buildScriptChangesAdded)
            {
                return;
            }

            // The plugin needs to be added to the application module (named launcher)
            var applicationGradleBuildFilePath = Path.Combine(path, "../launcher/build.gradle");
#else
            // If Gradle template is enabled, we would have already updated the plugin.
            if (AppLovinIntegrationManager.GradleTemplateEnabled)
            {
                return;
            }

            var applicationGradleBuildFilePath = Path.Combine(path, "build.gradle");
#endif

            if (!File.Exists(applicationGradleBuildFilePath))
            {
                MaxSdkLogger.UserWarning("Couldn't find build.gradle file. Failed to add AppLovin Quality Service plugin to the gradle project.");
                return;
            }

            AddAppLovinQualityServicePlugin(applicationGradleBuildFilePath);
        }
コード例 #2
0
 private static void _ensureHaveSdkKey()
 {
     if (_hasSdkKey)
     {
         return;
     }
     MaxSdkLogger.UserWarning(
         "MAX Ads SDK did not receive SDK key. Please call Max.SetSdkKey() to assign it");
 }
コード例 #3
0
    /// <summary>
    /// Show cross promo ad at a position determined by the 'CreateCrossPromoAd' call.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the cross promo ad to show</param>
    public static void ShowCrossPromoAd(string adUnitIdentifier)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show cross promo ad");

        if (!IsAdUnitRequested(adUnitIdentifier))
        {
            MaxSdkLogger.UserWarning("Cross promo ad '" + adUnitIdentifier + "' was not created, can not show it");
        }
    }
コード例 #4
0
    /// <summary>
    /// Show MREC at a position determined by the 'CreateMRec' call.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the MREC to show</param>
    public static void ShowMRec(string adUnitIdentifier)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show MREC");

        if (!IsAdUnitRequested(adUnitIdentifier))
        {
            MaxSdkLogger.UserWarning("MREC '" + adUnitIdentifier + "' was not created, can not show it");
        }
    }
コード例 #5
0
    /// <summary>
    /// Get the consent dialog state for this user. If no such determination could be made, <see cref="MaxSdkBase.ConsentDialogState.Unknown"/> will be returned.
    ///
    /// Note: this method should be called only after SDK has been initialized
    /// </summary>
    public static ConsentDialogState GetConsentDialogState()
    {
        if (!IsInitialized())
        {
            MaxSdkLogger.UserWarning(
                "MAX Ads SDK has not been initialized yet. GetConsentDialogState() may return ConsentDialogState.Unknown");
        }

        return((ConsentDialogState)_MaxConsentDialogState());
    }
コード例 #6
0
    public static ConsentDialogState GetConsentDialogState()
    {
        if (!IsInitialized())
        {
            MaxSdkLogger.UserWarning(
                "MAX Ads SDK has not been initialized yet. GetConsentDialogState() may return ConsentDialogState.Unknown");
        }

        return((ConsentDialogState)MaxUnityPluginClass.CallStatic <int>("getConsentDialogState"));
    }
コード例 #7
0
    private static void _ensureInitialized()
    {
        _ensureHaveSdkKey();

        if (_isInitialized)
        {
            return;
        }
        MaxSdkLogger.UserWarning(
            "MAX Ads SDK is not initialized by the time ad is requested. Please call Max.InitializeSdk() in your first scene");
    }
コード例 #8
0
    // Allocate the MaxSdkCallbacks singleton, which receives all callback events from the native SDKs.
    protected static void InitCallbacks()
    {
        var type = typeof(MaxSdkCallbacks);
        var mgr  = new GameObject("MaxSdkCallbacks", type)
                   .GetComponent <MaxSdkCallbacks>(); // Its Awake() method sets Instance.

        if (MaxSdkCallbacks.Instance != mgr)
        {
            MaxSdkLogger.UserWarning("It looks like you have the " + type.Name + " on a GameObject in your scene. Please remove the script from your scene.");
        }
    }
コード例 #9
0
 /// <summary>
 /// Present the mediation debugger UI.
 /// This debugger tool provides the status of your integration for each third-party ad network.
 ///
 /// Please call this method after the SDK has initialized.
 /// </summary>
 public static void ShowMediationDebugger()
 {
     if (!_isInitialized)
     {
         MaxSdkLogger.UserWarning("The mediation debugger cannot be shown before the MAX SDK has been initialized."
                                  + "\nCall 'MaxSdk.InitializeSdk();' and listen for 'MaxSdkCallbacks.OnSdkInitializedEvent' before showing the mediation debugger.");
     }
     else
     {
         MaxSdkLogger.UserWarning("The mediation debugger cannot be shown in the Unity Editor. Please export the project to Android or iOS first.");
     }
 }
コード例 #10
0
    /// <summary>
    /// Check if rewarded interstitial ad ad is loaded and ready to be displayed.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the rewarded ad to load</param>
    /// <returns>True if the ad is ready to be displayed</returns>
    public static bool IsRewardedInterstitialAdReady(string adUnitIdentifier)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "check rewarded interstitial ad loaded");

        if (!IsAdUnitRequested(adUnitIdentifier))
        {
            MaxSdkLogger.UserWarning("Rewarded interstitial ad '" + adUnitIdentifier +
                                     "' was not requested, can not check if it is loaded");
            return(false);
        }

        return(IsAdUnitReady(adUnitIdentifier));
    }
コード例 #11
0
    /// <summary>
    /// Present loaded rewarded interstitial ad for a given placement to tie ad events to. Note: if the rewarded interstitial ad is not ready to be displayed nothing will happen.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the rewarded interstitial to show</param>
    /// <param name="placement">The placement to tie the showing ad's events to</param>
    public static void ShowRewardedInterstitialAd(string adUnitIdentifier, string placement)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show rewarded interstitial ad");

        if (IsRewardedInterstitialAdReady(adUnitIdentifier))
        {
            _MaxShowRewardedInterstitialAd(adUnitIdentifier, placement);
        }
        else
        {
            MaxSdkLogger.UserWarning("Not showing MAX Ads rewarded interstitial ad: ad not ready");
        }
    }
コード例 #12
0
    /// <summary>
    /// Present loaded interstitial for a given placement to tie ad events to. Note: if the interstitial is not ready to be displayed nothing will happen.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the interstitial to load</param>
    /// <param name="placement">The placement to tie the showing ad's events to</param>
    public static void ShowInterstitial(string adUnitIdentifier, string placement)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show interstitial");

        if (IsInterstitialReady(adUnitIdentifier))
        {
            _MaxShowInterstitial(adUnitIdentifier, placement);
        }
        else
        {
            MaxSdkLogger.UserWarning("Not showing MAX Ads interstitial: ad not ready");
        }
    }
コード例 #13
0
    /// <summary> ready to be
    /// Present loaded rewarded ad for a given placement to tie ad events to. Note: if the rewarded ad is not ready to be displayed nothing will happen.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the interstitial to load</param>
    /// <param name="placement">The placement to tie the showing ad's events to</param>
    public static void ShowRewardedAd(string adUnitIdentifier, string placement)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show rewarded ad");

        if (IsRewardedAdReady(adUnitIdentifier))
        {
            MaxUnityPluginClass.CallStatic("showRewardedAd", adUnitIdentifier, placement);
        }
        else
        {
            MaxSdkLogger.UserWarning("Not showing MAX Ads rewarded ad: ad not ready");
        }
    }
コード例 #14
0
    private static bool CanInvokeEvent(Delegate evt)
    {
        if (evt == null)
        {
            return(false);
        }

        // Check that publisher is not over-subscribing
        if (evt.GetInvocationList().Length > 5)
        {
            MaxSdkLogger.UserWarning("Ads Event (" + evt + ") has over 5 subscribers. Please make sure you are properly un-subscribing to actions!!!");
        }

        return(true);
    }
コード例 #15
0
    /// <summary>
    /// Show banner at a position determined by the 'CreateBanner' call.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the banner to show</param>
    public static void ShowBanner(string adUnitIdentifier)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show banner");

        if (!IsAdUnitRequested(adUnitIdentifier))
        {
            MaxSdkLogger.UserWarning("Banner '" + adUnitIdentifier + "' was not created, can not show it");
        }
        else
        {
            GameObject stubBanner;
            if (StubBanners.TryGetValue(adUnitIdentifier, out stubBanner))
            {
                stubBanner.SetActive(true);
            }
        }
    }
コード例 #16
0
    /// <summary>
    /// Present loaded rewarded interstitial ad for a given placement to tie ad events to. Note: if the rewarded interstitial ad is not ready to be displayed nothing will happen.
    /// </summary>
    /// <param name="adUnitIdentifier">Ad unit identifier of the rewarded interstitial to show</param>
    /// <param name="placement">The placement to tie the showing ad's events to</param>
    public static void ShowRewardedInterstitialAd(string adUnitIdentifier, string placement)
    {
        ValidateAdUnitIdentifier(adUnitIdentifier, "show rewarded interstitial ad");

        if (!IsAdUnitRequested(adUnitIdentifier))
        {
            MaxSdkLogger.UserWarning("Rewarded interstitial ad '" + adUnitIdentifier +
                                     "' was not requested, can not show it");
            return;
        }

        if (!IsRewardedInterstitialAdReady(adUnitIdentifier))
        {
            MaxSdkLogger.UserWarning("Rewarded interstitial ad '" + adUnitIdentifier + "' is not ready, please check IsRewardedInterstitialAdReady() before showing.");
            return;
        }

        RemoveReadyAdUnit(adUnitIdentifier);

        if (_showStubAds)
        {
            ShowStubRewardedInterstitialAd(adUnitIdentifier);
        }
    }
コード例 #17
0
 /// <summary>
 /// Show the user consent dialog to the user using one from AppLovin's SDK. You should check that you actually need to show the consent dialog
 /// by checking <see cref="SdkConfiguration.ConsentDialogState"/> in the completion block of <see cref="MaxSdkCallbacks.OnSdkInitializedEvent"/>.
 /// Please make sure to implement the callback <see cref="MaxSdkCallbacks.OnSdkConsentDialogDismissedEvent"/>.
 /// </summary>
 public void ShowConsentDialog()
 {
     MaxSdkLogger.UserWarning("The consent dialog cannot be shown in the Unity Editor. Please export the project to Android or iOS first.");
 }
コード例 #18
0
    public void ForwardEvent(string eventPropsStr)
    {
        var eventProps = MaxSdkUtils.PropsStringToDict(eventPropsStr);

        var eventName = eventProps["name"];

        if (eventName == "OnSdkInitializedEvent")
        {
            var sdkConfiguration = MaxSdkBase.SdkConfiguration.Create(eventProps);
            InvokeEvent(_onSdkInitializedEvent, sdkConfiguration);
        }
        else if (eventName == "OnVariablesUpdatedEvent")
        {
            InvokeEvent(_onVariablesUpdatedEvent);
        }
        else if (eventName == "OnSdkConsentDialogDismissedEvent")
        {
            InvokeEvent(_onSdkConsentDialogDismissedEvent);
        }
        // Ad Events
        else
        {
            var adUnitIdentifier = eventProps["adUnitId"];
            if (eventName == "OnBannerAdLoadedEvent")
            {
                InvokeEvent(_onBannerAdLoadedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnBannerAdLoadFailedEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onBannerAdLoadFailedEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnBannerAdClickedEvent")
            {
                InvokeEvent(_onBannerAdClickedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnBannerAdExpandedEvent")
            {
                InvokeEvent(_onBannerAdExpandedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnBannerAdCollapsedEvent")
            {
                InvokeEvent(_onBannerAdCollapsedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnMRecAdLoadedEvent")
            {
                InvokeEvent(_onMRecAdLoadedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnMRecAdLoadFailedEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onMRecAdLoadFailedEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnMRecAdClickedEvent")
            {
                InvokeEvent(_onMRecAdClickedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnMRecAdExpandedEvent")
            {
                InvokeEvent(_onMRecAdExpandedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnMRecAdCollapsedEvent")
            {
                InvokeEvent(_onMRecAdCollapsedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnCrossPromoAdLoadedEvent")
            {
                InvokeEvent(_onCrossPromoAdLoadedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnCrossPromoAdLoadFailedEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onCrossPromoAdLoadFailedEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnCrossPromoAdClickedEvent")
            {
                InvokeEvent(_onCrossPromoAdClickedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnCrossPromoAdExpandedEvent")
            {
                InvokeEvent(_onCrossPromoAdExpandedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnCrossPromoAdCollapsedEvent")
            {
                InvokeEvent(_onCrossPromoAdCollapsedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnInterstitialLoadedEvent")
            {
                InvokeEvent(_onInterstitialLoadedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnInterstitialLoadFailedEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onInterstitialLoadFailedEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnInterstitialHiddenEvent")
            {
                InvokeEvent(_onInterstitialHiddenEvent, adUnitIdentifier);
            }
            else if (eventName == "OnInterstitialDisplayedEvent")
            {
                InvokeEvent(_onInterstitialDisplayedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnInterstitialAdFailedToDisplayEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onInterstitialAdFailedToDisplayEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnInterstitialClickedEvent")
            {
                InvokeEvent(_onInterstitialClickedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedAdLoadedEvent")
            {
                InvokeEvent(_onRewardedAdLoadedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedAdLoadFailedEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onRewardedAdLoadFailedEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnRewardedAdDisplayedEvent")
            {
                InvokeEvent(_onRewardedAdDisplayedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedAdHiddenEvent")
            {
                InvokeEvent(_onRewardedAdHiddenEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedAdClickedEvent")
            {
                InvokeEvent(_onRewardedAdClickedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedAdFailedToDisplayEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onRewardedAdFailedToDisplayEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnRewardedAdReceivedRewardEvent")
            {
                var reward = new MaxSdkBase.Reward {
                    Label = eventProps["rewardLabel"]
                };

                int.TryParse(eventProps["rewardAmount"], out reward.Amount);

                InvokeEvent(_onRewardedAdReceivedRewardEvent, adUnitIdentifier, reward);
            }
            else if (eventName == "OnRewardedInterstitialAdLoadedEvent")
            {
                InvokeEvent(_onRewardedInterstitialAdLoadedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedInterstitialAdLoadFailedEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onRewardedInterstitialAdLoadFailedEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnRewardedInterstitialAdDisplayedEvent")
            {
                InvokeEvent(_onRewardedInterstitialAdDisplayedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedInterstitialAdHiddenEvent")
            {
                InvokeEvent(_onRewardedInterstitialAdHiddenEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedInterstitialAdClickedEvent")
            {
                InvokeEvent(_onRewardedInterstitialAdClickedEvent, adUnitIdentifier);
            }
            else if (eventName == "OnRewardedInterstitialAdFailedToDisplayEvent")
            {
                var errorCode = 0;
                int.TryParse(eventProps["errorCode"], out errorCode);
                InvokeEvent(_onRewardedInterstitialAdFailedToDisplayEvent, adUnitIdentifier, errorCode);
            }
            else if (eventName == "OnRewardedInterstitialAdReceivedRewardEvent")
            {
                var reward = new MaxSdkBase.Reward {
                    Label = eventProps["rewardLabel"]
                };

                int.TryParse(eventProps["rewardAmount"], out reward.Amount);

                InvokeEvent(_onRewardedInterstitialAdReceivedRewardEvent, adUnitIdentifier, reward);
            }
            else
            {
                MaxSdkLogger.UserWarning("Unknown MAX Ads event fired: " + eventName);
            }
        }
    }
コード例 #19
0
        private static void EnableVerboseLoggingIfNeeded(string path)
        {
            if (!EditorPrefs.HasKey(MaxSdkLogger.KeyVerboseLoggingEnabled))
            {
                return;
            }

            var       enabled      = EditorPrefs.GetBool(MaxSdkLogger.KeyVerboseLoggingEnabled);
            var       manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml");
            XDocument manifest;

            try
            {
                manifest = XDocument.Load(manifestPath);
            }
#pragma warning disable 0168
            catch (IOException exception)
#pragma warning restore 0168
            {
                MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is missing.");
                return;
            }

            // Get the `manifest` element.
            var elementManifest = manifest.Element("manifest");
            if (elementManifest == null)
            {
                MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is invalid.");
                return;
            }

            var elementApplication = elementManifest.Element("application");
            if (elementApplication == null)
            {
                MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is invalid.");
                return;
            }

            var descendants            = elementApplication.Descendants();
            var verboseLoggingMetaData = descendants.FirstOrDefault(descendant => descendant.FirstAttribute != null &&
                                                                    descendant.FirstAttribute.Name.LocalName.Equals("name") &&
                                                                    descendant.FirstAttribute.Value.Equals(AppLovinVerboseLoggingOnKey) &&
                                                                    descendant.LastAttribute != null &&
                                                                    descendant.LastAttribute.Name.LocalName.Equals("value"));

            // check if applovin.sdk.verbose_logging meta data exists.
            if (verboseLoggingMetaData != null)
            {
                if (enabled)
                {
                    // update applovin.sdk.verbose_logging meta data value.
                    verboseLoggingMetaData.LastAttribute.Value = enabled.ToString();
                }
                else
                {
                    // remove applovin.sdk.verbose_logging meta data.
                    verboseLoggingMetaData.Remove();
                }
            }
            else
            {
                if (enabled)
                {
                    // add applovin.sdk.verbose_logging meta data if it does not exist.
                    var        metaData         = new XElement("meta-data");
                    XNamespace androidNamespace = "http://schemas.android.com/apk/res/android";
                    metaData.Add(new XAttribute(androidNamespace + "name", AppLovinVerboseLoggingOnKey));
                    metaData.Add(new XAttribute(androidNamespace + "value", enabled.ToString()));
                    elementApplication.Add(metaData);
                }
            }

            // Save the updated manifest file.
            manifest.Save(manifestPath);
        }