예제 #1
0
        static void GenerateManifest(Yodo1AdSettings settings)
        {
            var outputFile = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");

            if (!File.Exists(outputFile))
            {
                var inputFile = Path.Combine(EditorApplication.applicationContentsPath, "PlaybackEngines/androidplayer/AndroidManifest.xml");
                if (!File.Exists(inputFile))
                {
                    inputFile = Path.Combine(EditorApplication.applicationContentsPath, "PlaybackEngines/AndroidPlayer/Apk/AndroidManifest.xml");
                }
                if (!File.Exists(inputFile))
                {
                    string s     = EditorApplication.applicationPath;
                    int    index = s.LastIndexOf("/");
                    s         = s.Substring(0, index + 1);
                    inputFile = Path.Combine(s, "PlaybackEngines/AndroidPlayer/Apk/AndroidManifest.xml");
                }
                if (!File.Exists(inputFile))
                {
                    string s     = EditorApplication.applicationPath;
                    int    index = s.LastIndexOf("/");
                    s         = s.Substring(0, index + 1);
                    inputFile = Path.Combine(s, "PlaybackEngines/AndroidPlayer/Apk/LauncherManifest.xml");
                }
                File.Copy(inputFile, outputFile);
            }
            ValidateManifest(settings);
        }
예제 #2
0
        public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            if (buildTarget == BuildTarget.iOS)
            {
#if UNITY_IOS
                Yodo1AdSettings settings = Yodo1AdSettingsSave.Load();
                if (CheckConfiguration_iOS(settings))
                {
                    UpdateIOSPlist(pathToBuiltProject, settings);
                    UpdateIOSProject(pathToBuiltProject);
                }
#endif
            }
            if (buildTarget == BuildTarget.Android)
            {
#if UNITY_ANDROID
                Yodo1AdSettings settings = Yodo1AdSettingsSave.Load();
                if (CheckConfiguration_Android(settings))
                {
#if UNITY_2019_1_OR_NEWER
#else
                    ValidateManifest(settings);
#endif
                }
#endif
            }
        }
예제 #3
0
        public static bool CheckConfiguration_Android(Yodo1AdSettings settings)
        {
            if (settings == null)
            {
                string message = "MAS Android settings is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }

            if (string.IsNullOrEmpty(settings.androidSettings.AppKey))
            {
                string message = "MAS Android AppKey is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }

            if (settings.androidSettings.ChineseAndroidStores && string.IsNullOrEmpty(settings.androidSettings.Channel))
            {
                string message = "MAS Android Channel is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }

            if (settings.androidSettings.GooglePlayStore && string.IsNullOrEmpty(settings.androidSettings.AdmobAppID))
            {
                string message = "MAS Android AdMob App ID is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }
            return(true);
        }
예제 #4
0
        public static bool CheckConfiguration_iOS(Yodo1AdSettings settings)
        {
            if (settings == null)
            {
                string message = "MAS iOS settings is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }

            if (string.IsNullOrEmpty(settings.iOSSettings.AppKey))
            {
                string message = "MAS iOS AppKey is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }

            if (settings.iOSSettings.GlobalRegion && string.IsNullOrEmpty(settings.iOSSettings.AdmobAppID))
            {
                string message = "MAS iOS AdMob App ID is null, please check the configuration.";
                Debug.LogError("[Yodo1 Ads] " + message);
                Yodo1Utils.ShowAlert("Error", message, "Ok");
                return(false);
            }
            return(true);
        }
        public static Yodo1AdSettings Load()
        {
            Yodo1AdSettings settings = AssetDatabase.LoadAssetAtPath <Yodo1AdSettings>(YODO1_ADS_SETTINGS_PATH);

            if (settings == null)
            {
                settings = ScriptableObject.CreateInstance <Yodo1AdSettings>();
                try
                {
                    Debug.Log("[Yodo1 Ads] Creating new Yodo1AdSettings.asset");
                    string resPath = Path.GetFullPath(YODO1_RESOURCE_PATH);
                    if (!Directory.Exists(resPath))
                    {
                        Directory.CreateDirectory(resPath);
                    }
                    AssetDatabase.CreateAsset(settings, YODO1_ADS_SETTINGS_PATH);
                    AssetDatabase.SaveAssets();

                    settings = AssetDatabase.LoadAssetAtPath <Yodo1AdSettings>(YODO1_ADS_SETTINGS_PATH);
                    //Set default AppLovinSdkKey
                    settings.iOSSettings.AppLovinSdkKey = Yodo1EditorConstants.DEFAULT_APPLOVIN_SDK_KEY;
                }
                catch (UnityException)
                {
                    Debug.LogError("[Yodo1 Ads] Failed to create the Yodo1 Ad Settings asset.");
                }
            }
            return(settings);
        }
 void OnPreprocessAsset()
 {
     if (assetPath.Contains("Version.md"))
     {
         //DeleteFiles_Deprecated();
         Yodo1AdSettings settings = Yodo1AdSettingsSave.Load();
         Yodo1AdSettingsSave.UpdateDependencies(settings);
     }
 }
        public static void UpdateDependencies(Yodo1AdSettings settings)
        {
            if (settings == null)
            {
                Debug.LogError("[Yodo1 Ads] Update dependencies failed. Yodo1 ad settings is not exsit.");
                return;
            }
            string dependenciesPath         = Path.GetFullPath(Application.dataPath + "/Yodo1Ads/Editor/Dependencies/");
            string dependenciesTemplatePath = dependenciesPath + "Template/";

            string sourcePath = string.Empty;

            if (settings.androidSettings.ChineseAndroidStores)
            {
                sourcePath = dependenciesTemplatePath + "Android/Yodo1AdsAndroidDependenciesChina.xml";
            }
            else if (settings.androidSettings.GooglePlayStore)
            {
                sourcePath = dependenciesTemplatePath + "Android/Yodo1AdsAndroidDependenciesGlobal.xml";
            }
            if (File.Exists(sourcePath))
            {
                string destFile = dependenciesPath + "Yodo1AdsAndroidDependencies.xml";
                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                File.Copy(sourcePath, destFile, true);
            }

            //if (settings.iOSSettings.ChinaRegion) {
            //    string sourcePath = dependenciesTemplatePath + "iOS/ChinaDependenciesTemplate.xml";
            //    File.Copy(sourcePath,dependenciesPath + "Yodo1AdsiOSDependencies.xml", true);
            //} else if (settings.iOSSettings.GlobalRegion) {
            //    string sourcePath = dependenciesTemplatePath + "iOS/GlobalDependenciesTemplate.xml";
            //    File.Copy(sourcePath,dependenciesPath + "Yodo1AdsiOSDependencies.xml", true);
            //}

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
예제 #8
0
        static void Yodo1ValidateManifest(string path)
        {
            var mainfestPath = Path.Combine(path, "src/main/AndroidManifest.xml");

            if (mainfestPath.Contains("unityLibrary"))
            {
                mainfestPath = mainfestPath.Replace("unityLibrary", "launcher");
            }

            if (File.Exists(mainfestPath))
            {
                Yodo1AdSettings settings = Yodo1AdSettingsSave.Load();
                if (Yodo1PostProcess.CheckConfiguration_Android(settings))
                {
                    ValidateManifest(mainfestPath, settings);
                }
            }
        }
        private static void UpdateIOSPlist(string path, Yodo1AdSettings settings)
        {
            string        plistPath = Path.Combine(path, "Info.plist");
            PlistDocument plist     = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(plistPath));

            //Get Root
            PlistElementDict rootDict          = plist.root;
            PlistElementDict transportSecurity = rootDict.CreateDict("NSAppTransportSecurity");

            transportSecurity.SetBoolean("NSAllowsArbitraryLoads", true);

            //Set AppLovinSdkKey
            rootDict.SetString("AppLovinSdkKey", Yodo1EditorConstants.DEFAULT_APPLOVIN_SDK_KEY);

            //Set AdMob APP Id
            if (settings.iOSSettings.GlobalRegion)
            {
                rootDict.SetString("GADApplicationIdentifier", settings.iOSSettings.AdmobAppID);
            }

            PlistElementString privacy = (PlistElementString)rootDict["NSLocationAlwaysUsageDescription"];

            if (privacy == null)
            {
                rootDict.SetString("NSLocationAlwaysUsageDescription", "Some ad content may require access to the location for an interactive ad experience.");
            }

            PlistElementString privacy1 = (PlistElementString)rootDict["NSLocationWhenInUseUsageDescription"];

            if (privacy1 == null)
            {
                rootDict.SetString("NSLocationWhenInUseUsageDescription", "Some ad content may require access to the location for an interactive ad experience.");
            }

            File.WriteAllText(plistPath, plist.WriteToString());
        }
예제 #10
0
    public static void InitializeSdk()
    {
        if (initialized)
        {
            Debug.LogWarning("[Yodo1 Ads] The SDK has been initialized, please do not initialize the SDK repeatedly.");
            return;
        }

        var type   = typeof(Yodo1U3dSDK);
        var sdkObj = new GameObject("Yodo1U3dSDK", type).GetComponent <Yodo1U3dSDK>(); // Its Awake() method sets Instance.

        if (Yodo1U3dSDK.Instance != sdkObj)
        {
            Debug.LogError("[Yodo1 Ads] It looks like you have the " + type.Name + " on a GameObject in your scene. Please remove the script from your scene.");
            return;
        }

        Yodo1Ads.Yodo1AdSettings settings = Resources.Load("Yodo1Ads/Yodo1AdSettings", typeof(Yodo1Ads.Yodo1AdSettings)) as Yodo1Ads.Yodo1AdSettings;
        if (settings == null)
        {
            Debug.LogError("[Yodo1 Ads] The SDK has not been initialized yet. The Yodo1AdSettings is missing.");
            return;
        }

        string appKey = string.Empty;

#if UNITY_ANDROID
        appKey = settings.androidSettings.AppKey;
#elif UNITY_IOS
        appKey = settings.iOSSettings.AppKey;
#endif
        Debug.Log("[Yodo1 Ads] The SDK has been initialized, the app key is " + appKey);
        Yodo1U3dAds.InitWithAppKey(appKey);

        initialized = true;
    }
예제 #11
0
        static void ValidateManifest(string manifestFile, Yodo1AdSettings settings)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(manifestFile);

            if (doc == null)
            {
                Debug.LogError("[Yodo1 Ads] Couldn't load " + manifestFile);
                return;
            }

            XmlNode manNode = Yodo1PostProcess.FindChildNode(doc, "manifest");
            string  ns      = manNode.GetNamespaceOfPrefix("android");

            XmlNode app = Yodo1PostProcess.FindChildNode(manNode, "application");

            if (app == null)
            {
                Debug.LogError("[Yodo1 Ads] Error parsing " + manifestFile + ", tag for application not found.");
                return;
            }

            ////Enable hardware acceleration for video play
            //XmlElement elem = (XmlElement)app;

            //Add AdMob App ID
            if (settings.androidSettings.GooglePlayStore)
            {
                string admobAppIdValue = settings.androidSettings.AdmobAppID;
                if (string.IsNullOrEmpty(admobAppIdValue))
                {
                    Debug.LogError("[Yodo1 Ads] MAS Android AdMob App ID is null, please check the configuration.");
                    return;
                }
                string  admobAppIdName = "com.google.android.gms.ads.APPLICATION_ID";
                XmlNode metaNode       = Yodo1PostProcess.FindChildNodeWithAttribute(app, "meta-data", "android:name", admobAppIdName);
                if (metaNode == null)
                {
                    metaNode = (XmlElement)doc.CreateNode(XmlNodeType.Element, "meta-data", null);
                    app.AppendChild(metaNode);
                }

                XmlElement metaElement = (XmlElement)metaNode;
                metaElement.SetAttribute("name", ns, admobAppIdName);
                metaElement.SetAttribute("value", ns, admobAppIdValue);
                metaElement.GetNamespaceOfPrefix("android");
            }

            //Add Channel
            string channelValue = string.Empty;

            if (settings.androidSettings.ChineseAndroidStores)
            {
                channelValue = settings.androidSettings.Channel;
                if (string.IsNullOrEmpty(channelValue))
                {
                    Debug.LogError("[Yodo1 Ads] MAS Android Channel is null, please check the configuration.");
                    return;
                }
            }
            if (settings.androidSettings.GooglePlayStore)
            {
                channelValue = "GooglePlay";
            }
            string  channelName = "Yodo1ChannelCode";
            XmlNode meta1Node   = Yodo1PostProcess.FindChildNodeWithAttribute(app, "meta-data", "android:name", channelName);

            if (meta1Node == null)
            {
                meta1Node = (XmlElement)doc.CreateNode(XmlNodeType.Element, "meta-data", null);
                app.AppendChild(meta1Node);
            }

            XmlElement meta1Element = (XmlElement)meta1Node;

            meta1Element.SetAttribute("name", ns, channelName);
            meta1Element.SetAttribute("value", ns, channelValue);
            meta1Element.GetNamespaceOfPrefix("android");

            string ns2 = manNode.GetNamespaceOfPrefix("tools");

            meta1Element.SetAttribute("replace", ns2, "android:value");

            doc.Save(manifestFile);
        }
예제 #12
0
        private static void UpdateIOSPlist(string path, Yodo1AdSettings settings)
        {
            string        plistPath = Path.Combine(path, "Info.plist");
            PlistDocument plist     = new PlistDocument();

            plist.ReadFromString(File.ReadAllText(plistPath));

            //Get Root
            PlistElementDict rootDict          = plist.root;
            PlistElementDict transportSecurity = rootDict.CreateDict("NSAppTransportSecurity");

            transportSecurity.SetBoolean("NSAllowsArbitraryLoads", true);

            //Set SKAdNetwork
            PlistElementArray skItem = rootDict.CreateArray("SKAdNetworkItems");

            foreach (string sk in mSKAdNetworkId)
            {
                PlistElementDict skDic = skItem.AddDict();
                skDic.SetString("SKAdNetworkIdentifier", sk);
            }

            //Set AppLovinSdkKey
            rootDict.SetString("AppLovinSdkKey", Yodo1EditorConstants.DEFAULT_APPLOVIN_SDK_KEY);

            //Set AdMob APP Id
            if (settings.iOSSettings.GlobalRegion)
            {
                rootDict.SetString("GADApplicationIdentifier", settings.iOSSettings.AdmobAppID);
            }

            PlistElementString privacy = (PlistElementString)rootDict["NSLocationAlwaysUsageDescription"];

            if (privacy == null)
            {
                rootDict.SetString("NSLocationAlwaysUsageDescription", "Some ad content may require access to the location for an interactive ad experience.");
            }

            PlistElementString privacy1 = (PlistElementString)rootDict["NSLocationWhenInUseUsageDescription"];

            if (privacy1 == null)
            {
                rootDict.SetString("NSLocationWhenInUseUsageDescription", "Some ad content may require access to the location for an interactive ad experience.");
            }

            PlistElementString attPrivacy = (PlistElementString)rootDict["NSUserTrackingUsageDescription"];

            if (attPrivacy == null)
            {
                rootDict.SetString("NSUserTrackingUsageDescription", "This identifier will be used to deliver personalized ads to you.");
            }

            PlistElementString calendarsPrivacy = (PlistElementString)rootDict["NSCalendarsUsageDescription"];

            if (calendarsPrivacy == null)
            {
                rootDict.SetString("NSCalendarsUsageDescription", "The application wants to use your calendar. Is that allowed?");
            }

            File.WriteAllText(plistPath, plist.WriteToString());
        }
예제 #13
0
 private void OnEnable()
 {
     this.adSettings = Yodo1AdSettingsSave.Load();
 }
예제 #14
0
 private void OnDisable()
 {
     this.SaveConfig();
     this.adSettings = null;
 }
예제 #15
0
        public static bool ValidateManifest(Yodo1AdSettings settings)
        {
            if (settings == null)
            {
                Debug.LogError("[Yodo1 Ads] Validate manifest failed. Yodo1 ad settings is not exsit.");
                return(false);
            }

            var androidPluginPath = Path.Combine(Application.dataPath, "Plugins/Android/");
            var manifestFile      = androidPluginPath + "AndroidManifest.xml";

            if (!File.Exists(manifestFile))
            {
                GenerateManifest(settings);
                return(true);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(manifestFile);

            if (doc == null)
            {
                Debug.LogError("[Yodo1 Ads] Couldn't load " + manifestFile);
                return(false);
            }

            XmlNode manNode = FindChildNode(doc, "manifest");
            string  ns      = manNode.GetNamespaceOfPrefix("android");

            XmlNode app = FindChildNode(manNode, "application");

            if (app == null)
            {
                Debug.LogError("[Yodo1 Ads] Error parsing " + manifestFile + ", tag for application not found.");
                return(false);
            }

            ////Enable hardware acceleration for video play
            //XmlElement elem = (XmlElement)app;

            //Add AdMob App ID
            if (settings.androidSettings.GooglePlayStore)
            {
                string admobAppIdValue = settings.androidSettings.AdmobAppID;
                if (string.IsNullOrEmpty(admobAppIdValue))
                {
                    Debug.LogError("[Yodo1 Ads] MAS Android AdMob App ID is null, please check the configuration.");
                    return(false);
                }
                string  admobAppIdName = "com.google.android.gms.ads.APPLICATION_ID";
                XmlNode metaNode       = FindChildNodeWithAttribute(app, "meta-data", "android:name", admobAppIdName);
                if (metaNode == null)
                {
                    metaNode = (XmlElement)doc.CreateNode(XmlNodeType.Element, "meta-data", null);
                    app.AppendChild(metaNode);
                }

                XmlElement metaElement = (XmlElement)metaNode;
                metaElement.SetAttribute("name", ns, admobAppIdName);
                metaElement.SetAttribute("value", ns, admobAppIdValue);
                metaElement.GetNamespaceOfPrefix("android");
            }

            doc.Save(manifestFile);
            return(true);
        }
예제 #16
0
 public static void Save(Yodo1AdSettings settings)
 {
     EditorUtility.SetDirty(settings);
     //AssetDatabase.SaveAssets();
     //AssetDatabase.Refresh();
 }