Ejemplo n.º 1
0
    private static void NotifyBuildFailure(string message)
    {
        string prefix = "[GoogleMobileAds] ";

        bool openSettings = EditorUtility.DisplayDialog(
            "Google Mobile Ads", "Error: " + message, "Open Settings", "Close");

        if (openSettings)
        {
            GoogleMobileAdsSettingsEditor.OpenInspector();
        }
#if UNITY_2017_1_OR_NEWER
        throw new BuildPlayerWindow.BuildMethodException(prefix + message);
#else
        throw new OperationCanceledException(prefix + message);
#endif
    }
    private static void NotifyBuildFailure(string message, bool showOpenSettingsButton = true)
    {
        string dialogTitle   = "Google Mobile Ads";
        string dialogMessage = "Error: " + message;

        if (showOpenSettingsButton)
        {
            bool openSettings = EditorUtility.DisplayDialog(
                dialogTitle, dialogMessage, "Open Settings", "Close");
            if (openSettings)
            {
                GoogleMobileAdsSettingsEditor.OpenInspector();
            }
        }
        else
        {
            EditorUtility.DisplayDialog(dialogTitle, dialogMessage, "Close");
        }

        ThrowBuildException("[GoogleMobileAds] " + message);
    }
Ejemplo n.º 3
0
    public void OnPreprocessBuild(BuildTarget target, string path)
#endif
    {
        string manifestPath = Path.Combine(
            Application.dataPath, "Plugins/Android/GoogleMobileAdsPlugin.androidlib/AndroidManifest.xml");

        XDocument manifest = null;

        try
        {
            manifest = XDocument.Load(manifestPath);
        }
        #pragma warning disable 0168
        catch (IOException e)
        #pragma warning restore 0168
        {
            StopBuildWithMessage("AndroidManifest.xml is missing. Try re-importing the plugin.");
        }

        XElement elemManifest = manifest.Element("manifest");
        if (elemManifest == null)
        {
            StopBuildWithMessage("AndroidManifest.xml is not valid. Try re-importing the plugin.");
        }

        XElement elemApplication = elemManifest.Element("application");
        if (elemApplication == null)
        {
            StopBuildWithMessage("AndroidManifest.xml is not valid. Try re-importing the plugin.");
        }

        if (!GoogleMobileAdsSettings.Instance.IsAdManagerEnabled && !GoogleMobileAdsSettings.Instance.IsAdMobEnabled)
        {
            GoogleMobileAdsSettingsEditor.OpenInspector();
            StopBuildWithMessage("Neither Ad Manager nor AdMob is enabled yet.");
        }

        IEnumerable <XElement> metas = elemApplication.Descendants()
                                       .Where(elem => elem.Name.LocalName.Equals("meta-data"));

        XElement elemAdManagerEnabled = GetMetaElement(metas, META_AD_MANAGER_APP);
        if (GoogleMobileAdsSettings.Instance.IsAdManagerEnabled)
        {
            if (elemAdManagerEnabled == null)
            {
                elemApplication.Add(CreateMetaElement(META_AD_MANAGER_APP, true));
            }
            else
            {
                elemAdManagerEnabled.SetAttributeValue(ns + "value", true);
            }
        }
        else
        {
            if (elemAdManagerEnabled != null)
            {
                elemAdManagerEnabled.Remove();
            }
        }

        XElement elemAdMobEnabled = GetMetaElement(metas, META_APPLICATION_ID);
        if (GoogleMobileAdsSettings.Instance.IsAdMobEnabled)
        {
            string appId = GoogleMobileAdsSettings.Instance.AdMobAndroidAppId;

            if (appId.Length == 0)
            {
                StopBuildWithMessage(
                    "Android AdMob app ID is empty. Please enter a valid app ID to run ads properly.");
            }

            if (elemAdMobEnabled == null)
            {
                elemApplication.Add(CreateMetaElement(META_APPLICATION_ID, appId));
            }
            else
            {
                elemAdMobEnabled.SetAttributeValue(ns + "value", appId);
            }
        }
        else
        {
            if (elemAdMobEnabled != null)
            {
                elemAdMobEnabled.Remove();
            }
        }

        XElement elemDelayAppMeasurementInit =
            GetMetaElement(metas, META_DELAY_APP_MEASUREMENT_INIT);
        if (GoogleMobileAdsSettings.Instance.DelayAppMeasurementInit)
        {
            if (elemDelayAppMeasurementInit == null)
            {
                elemApplication.Add(CreateMetaElement(META_DELAY_APP_MEASUREMENT_INIT, true));
            }
            else
            {
                elemDelayAppMeasurementInit.SetAttributeValue(ns + "value", true);
            }
        }
        else
        {
            if (elemDelayAppMeasurementInit != null)
            {
                elemDelayAppMeasurementInit.Remove();
            }
        }

        elemManifest.Save(manifestPath);
    }