Пример #1
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 Mas] " + message);
                Yodo1AdUtils.ShowAlert("Error", message, "Ok");
                return(false);
            }

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

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

            if (settings.androidSettings.GooglePlayStore && string.IsNullOrEmpty(settings.androidSettings.AdmobAppID.Trim()))
            {
                string message = "MAS Android AdMob App ID is null, please check the configuration.";
                Debug.LogError("[Yodo1 Mas] " + message);
                Yodo1AdUtils.ShowAlert("Error", message, "Ok");
                return(false);
            }
            return(true);
        }
Пример #2
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);
        }
Пример #3
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 Mas] " + message);
                Yodo1AdUtils.ShowAlert("Error", message, "Ok");
                return(false);
            }

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

            if (settings.iOSSettings.GlobalRegion && string.IsNullOrEmpty(settings.iOSSettings.AdmobAppID.Trim()))
            {
                string message = "MAS iOS AdMob App ID is null, please check the configuration.";
                Debug.LogError("[Yodo1 Mas] " + message);
                Yodo1AdUtils.ShowAlert("Error", message, "Ok");
                return(false);
            }
            return(true);
        }
Пример #4
0
        public static Yodo1AdSettings Load()
        {
            Yodo1AdSettings settings = AssetDatabase.LoadAssetAtPath <Yodo1AdSettings>(YODO1_ADS_SETTINGS_PATH);

            if (settings == null)
            {
                settings = ScriptableObject.CreateInstance <Yodo1AdSettings>();
                try
                {
                    Debug.Log("[Yodo1 Mas] 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 = Yodo1AdEditorConstants.DEFAULT_APPLOVIN_SDK_KEY;
                }
                catch (UnityException)
                {
                    Debug.LogError("[Yodo1 Mas] Failed to create the Yodo1 Ad Settings asset.");
                }
            }
            return(settings);
        }
Пример #5
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
            }
        }
Пример #6
0
 void OnPreprocessAsset()
 {
     if (assetPath.Contains("Version.md"))
     {
         //DeleteFiles_Deprecated();
         Yodo1AdSettings settings = Yodo1AdSettingsSave.Load();
         Yodo1AdSettingsSave.UpdateDependencies(settings);
     }
 }
Пример #7
0
        public static void UpdateDependencies(Yodo1AdSettings settings)
        {
            if (settings == null)
            {
                Debug.LogError("[Yodo1 Mas] Update dependencies failed. Yodo1 ad settings is not exsit.");
                return;
            }
            string dependenciesPath         = Path.GetFullPath(Application.dataPath + "/Yodo1/MAS/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);
                }
            }
        }
Пример #9
0
        public static void InitializeSdk()
        {
            if (initialized)
            {
                Debug.LogWarning("[Yodo1 Mas] The SDK has been initialized, please do not initialize the SDK repeatedly.");
                return;
            }

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

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

            Yodo1AdSettings settings = Resources.Load("Yodo1/Yodo1AdSettings", typeof(Yodo1AdSettings)) as Yodo1AdSettings;

            if (settings == null)
            {
                Debug.LogError("[Yodo1 Mas] The SDK has not been initialized yet. The Yodo1AdSettings is missing.");
                return;
            }

            string appKey = string.Empty;

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

            initialized = true;
        }
Пример #10
0
 private void OnDisable()
 {
     this.SaveConfig();
     this.adSettings = null;
 }
Пример #11
0
 private void OnEnable()
 {
     this.adSettings = Yodo1AdSettingsSave.Load();
 }
Пример #12
0
        public static bool ValidateManifest(Yodo1AdSettings settings)
        {
            if (settings == null)
            {
                Debug.LogError("[Yodo1 Mas] 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 Mas] 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 Mas] 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.Trim();
                if (string.IsNullOrEmpty(admobAppIdValue))
                {
                    Debug.LogError("[Yodo1 Mas] 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");
            }

            //Add Channel
            string channelValue = string.Empty;

            if (settings.androidSettings.ChineseAndroidStores)
            {
                channelValue = settings.androidSettings.Channel.Trim();
                if (string.IsNullOrEmpty(channelValue))
                {
                    Debug.LogError("[Yodo1 Mas] MAS Android Channel is null, please check the configuration.");
                    return(false);
                }
            }
            if (settings.androidSettings.GooglePlayStore)
            {
                channelValue = "GooglePlay";
            }
            string  channelName = "Yodo1ChannelCode";
            XmlNode meta1Node   = 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);
            return(true);
        }
Пример #13
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", Yodo1AdEditorConstants.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 bluetoothPrivacy = (PlistElementString)rootDict["NSBluetoothAlwaysUsageDescription"];

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

            File.WriteAllText(plistPath, plist.WriteToString());
        }
Пример #14
0
 public static void Save(Yodo1AdSettings settings)
 {
     EditorUtility.SetDirty(settings);
     //AssetDatabase.SaveAssets();
     //AssetDatabase.Refresh();
 }