コード例 #1
0
        internal static string DownloadRemoteSettings(string managerID, BuildTarget platform, CASInitSettings settings, DependencyManager deps)
        {
            const string title = "Update CAS remote settings";

            var editorSettings = CASEditorSettings.Load();

            #region Create request URL
            #region Hash
            var managerIdBytes = new UTF8Encoding().GetBytes(managerID);
            var suffix         = new byte[] { 48, 77, 101, 68, 105, 65, 116, 73, 111, 78, 104, 65, 115, 72 };
            if (platform == BuildTarget.iOS)
            {
                suffix[0] = 49;
            }
            var sourceBytes = new byte[managerID.Length + suffix.Length];
            Array.Copy(managerIdBytes, 0, sourceBytes, 0, managerIdBytes.Length);
            Array.Copy(suffix, 0, sourceBytes, managerIdBytes.Length, suffix.Length);

            var           hashBytes   = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(sourceBytes);
            StringBuilder hashBuilder = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                hashBuilder.Append(Convert.ToString(hashBytes[i], 16).PadLeft(2, '0'));
            }
            var hash = hashBuilder.ToString().PadLeft(32, '0');
            #endregion

            var urlBuilder = new StringBuilder("https://psvpromo.psvgamestudio.com/Scr/cas.php?platform=")
                             .Append(platform == BuildTarget.Android ? 0 : 1)
                             .Append("&bundle=").Append(UnityWebRequest.EscapeURL(managerID))
                             .Append("&hash=").Append(hash)
                             .Append("&lang=").Append(SystemLanguage.English)
                             .Append("&appDev=2")
                             .Append("&appV=").Append(PlayerSettings.bundleVersion)
                             .Append("&coppa=").Append(( int )settings.defaultAudienceTagged)
                             .Append("&adTypes=").Append(( int )settings.allowedAdFlags)
                             .Append("&nets=").Append(DependencyManager.GetActiveMediationPattern(deps))
                             .Append("&orient=").Append(Utils.GetOrientationId())
                             .Append("&framework=Unity_").Append(Application.unityVersion);
            if (deps != null)
            {
                var buildCode = deps.GetInstalledBuildCode();
                if (buildCode > 0)
                {
                    urlBuilder.Append("&sdk=").Append(buildCode);
                }
            }
            if (string.IsNullOrEmpty(editorSettings.mostPopularCountryOfUsers))
            {
                urlBuilder.Append("&country=").Append("US");
            }
            else
            {
                urlBuilder.Append("&country=").Append(editorSettings.mostPopularCountryOfUsers);
            }
            if (platform == BuildTarget.Android)
            {
                urlBuilder.Append("&appVC=").Append(PlayerSettings.Android.bundleVersionCode);
            }

            #endregion

            using (var loader = UnityWebRequest.Get(urlBuilder.ToString()))
            {
                try
                {
                    loader.SendWebRequest();
                    while (!loader.isDone)
                    {
                        if (EditorUtility.DisplayCancelableProgressBar(title, managerID,
                                                                       Mathf.Repeat(( float )EditorApplication.timeSinceStartup * 0.2f, 1.0f)))
                        {
                            loader.Dispose();
                            throw new Exception("Update CAS Settings canceled");
                        }
                    }
                    if (string.IsNullOrEmpty(loader.error))
                    {
                        var content = loader.downloadHandler.text.Trim();
                        if (string.IsNullOrEmpty(content))
                        {
                            throw new Exception("ManagerID [" + managerID + "] is not registered in CAS.");
                        }

                        EditorUtility.DisplayProgressBar(title, "Write CAS settings", 0.7f);
                        var data = JsonUtility.FromJson <AdmobAppIdData>(content);
                        Utils.WriteToFile(content, Utils.GetNativeSettingsPath(platform, managerID));
                        return(data.admob_app_id);
                    }
                    throw new Exception("Server response " + loader.responseCode + ": " + loader.error);
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
            }
        }
コード例 #2
0
        public static void ConfigureProject(BuildTarget target, CASEditorSettings editorSettings)
        {
            if (target != BuildTarget.Android && target != BuildTarget.iOS)
            {
                return;
            }

            var settings = Utils.GetSettingsAsset(target, false);

            if (!settings)
            {
                Utils.StopBuildWithMessage("Settings asset not found. Please use menu Assets > CleverAdsSolutions > Settings " +
                                           "to create and set settings for build.", target);
            }

            var deps = DependencyManager.Create(target, Audience.Mixed, true);

            if (!Application.isBatchMode)
            {
                var newCASVersion = Utils.GetNewVersionOrNull(Utils.gitUnityRepo, MobileAds.wrapperVersion, false);
                if (newCASVersion != null)
                {
                    Utils.DialogOrCancelBuild("There is a new version " + newCASVersion + " of the CAS Unity available for update.", target);
                }

                if (deps != null)
                {
                    if (!deps.installedAny)
                    {
                        Utils.StopBuildWithMessage("Dependencies of native SDK were not found. " +
                                                   "Please use 'Assets > CleverAdsSolutions > Settings' menu to integrate solutions or any SDK separately.", target);
                    }

                    if (deps.IsNewerVersionFound())
                    {
                        Utils.DialogOrCancelBuild("There is a new versions of the native dependencies available for update." +
                                                  "Please use 'Assets > CleverAdsSolutions >Settings' menu to update.", target);
                    }
                }
            }

            if (settings.managersCount == 0 || string.IsNullOrEmpty(settings.GetManagerId(0)))
            {
                StopBuildIDNotFound(target);
            }

            string admobAppId = UpdateRemoteSettingsAndGetAppId(settings, target, deps);

            if (target == BuildTarget.Android)
            {
                ConfigureAndroid(settings, editorSettings, admobAppId);
            }
            else if (target == BuildTarget.iOS)
            {
                ConfigureIOS();
            }

#pragma warning disable CS0618 // Type or member is obsolete
            // Use directrly property to avoid Debug build
            if (settings.testAdMode && !EditorUserBuildSettings.development)
            {
                Debug.LogWarning(Utils.logTag + "Test Ads Mode enabled! Make sure the build is for testing purposes only!\n" +
                                 "Use 'Assets > CleverAdsSolutions > Settings' menu to disable Test Ad Mode.");
            }
            else
            {
                Debug.Log(Utils.logTag + "Project configuration completed");
            }
#pragma warning restore CS0618 // Type or member is obsolete
        }
コード例 #3
0
        private static string UpdateRemoteSettingsAndGetAppId(CASInitSettings settings, BuildTarget platform, DependencyManager deps)
        {
            string appId = null;
            string updateSettingsError = "";

            for (int i = 0; i < settings.managersCount; i++)
            {
                var managerId = settings.GetManagerId(i);
                if (managerId == null || managerId.Length < 5)
                {
                    continue;
                }
                try
                {
                    string newAppId = DownloadRemoteSettings(managerId, platform, settings, deps);
                    if (!string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(newAppId))
                    {
                        continue;
                    }
                    if (newAppId.Contains('~'))
                    {
                        appId = newAppId;
                        continue;
                    }
                    if (i == 0)
                    {
                        Debug.LogError(Utils.logTag + "CAS id [" + managerId +
                                       "] has an error in server settings. Please contact support!");
                    }
                }
                catch (Exception e)
                {
                    updateSettingsError = e.Message;
                }
            }
            if (!string.IsNullOrEmpty(appId) || settings.IsTestAdMode())
            {
                return(appId);
            }

            const string title          = "Update CAS remote settings";
            int          dialogResponse = 0;
            var          targetId       = settings.GetManagerId(0);

            var message = updateSettingsError +
                          "\nPlease try using a real identifier in the first place else contact support." +
                          "\n- Warning! -" +
                          "\n1. Continue build the app for release with current settings can reduce monetization revenue." +
                          "\n2. When build to testing your app, make sure you use Test Ads mode rather than live ads. " +
                          "Failure to do so can lead to suspension of your account.";

            Debug.LogError(Utils.logTag + message);
            if (!Application.isBatchMode)
            {
                dialogResponse = EditorUtility.DisplayDialogComplex(title, message,
                                                                    "Continue", "Cancel Build", "Select settings file");
            }

            if (dialogResponse == 0)
            {
                var cachePath = Utils.GetNativeSettingsPath(platform, targetId);
                if (File.Exists(cachePath))
                {
                    return(Utils.GetAdmobAppIdFromJson(File.ReadAllText(cachePath)));
                }
                return(null);
            }
            if (dialogResponse == 1)
            {
                Utils.StopBuildWithMessage("Build canceled", BuildTarget.NoTarget);
                return(null);
            }
            return(Utils.SelectSettingsFileAndGetAppId(targetId, platform));
        }
コード例 #4
0
        private static void EmbedDynamicLibrariesIfNeeded(string buildPath, PBXProject project, string targetGuid, DependencyManager deps)
        {
            for (int i = 0; i < deps.networks.Length; i++)
            {
                var dynamicLibraryPath = deps.networks[i].embedFramework;
                if (string.IsNullOrEmpty(dynamicLibraryPath))
                {
                    continue;
                }
                dynamicLibraryPath = Path.Combine("Pods", dynamicLibraryPath);
                if (!Directory.Exists(Path.Combine(buildPath, dynamicLibraryPath)))
                {
                    continue;
                }

#if UNITY_2019_3_OR_NEWER
                var fileGuid = project.AddFile(dynamicLibraryPath, dynamicLibraryPath);
                project.AddFileToEmbedFrameworks(targetGuid, fileGuid);
#endif
            }
        }
コード例 #5
0
        private static void SetExecutablePath(string buildPath, PBXProject project, string targetGuid, DependencyManager deps)
        {
#if !UNITY_2019_3_OR_NEWER
#if UNITY_2018_2_OR_NEWER
            string runpathSearchPaths = project.GetBuildPropertyForAnyConfig(targetGuid, "LD_RUNPATH_SEARCH_PATHS");
#else
            string runpathSearchPaths = "$(inherited)";
#endif
            if (string.IsNullOrEmpty(runpathSearchPaths))
            {
                runpathSearchPaths = "";
            }
            else
            {
                // Check if runtime search paths already contains the required search paths for dynamic libraries.
                if (runpathSearchPaths.Contains("@executable_path/Frameworks"))
                {
                    return;
                }

                runpathSearchPaths += " ";
            }

            runpathSearchPaths += "@executable_path/Frameworks";
            project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", runpathSearchPaths);
#endif

            // Needed to build successfully on Xcode 12+,
            // as framework was build with latest Xcode but not as an xcframework

            //project.AddBuildProperty( targetGuid, "VALIDATE_WORKSPACE", "YES" );
        }
コード例 #6
0
        private static void ApplyCrosspromoDynamicLinks(string buildPath, string targetGuid, CASInitSettings casSettings, DependencyManager deps)
        {
            if (!casSettings || casSettings.IsTestAdMode() || casSettings.managersCount == 0 ||
                string.IsNullOrEmpty(casSettings.GetManagerId(0)))
            {
                return;
            }
            if (deps != null)
            {
                var crossPromoDependency = deps.FindCrossPromotion();
                if (crossPromoDependency != null && !crossPromoDependency.IsInstalled())
                {
                    return;
                }
            }
            try
            {
                var identifier   = Application.identifier;
                var productName  = identifier.Substring(identifier.LastIndexOf(".") + 1);
                var projectPath  = GetXCodeProjectPath(buildPath);
                var entitlements = new ProjectCapabilityManager(projectPath, productName + ".entitlements",
#if UNITY_2019_3_OR_NEWER
                                                                null, targetGuid);
#else
                                                                PBXProject.GetUnityTargetName());
#endif
                string link = "applinks:psvios" + casSettings.GetManagerId(0) + ".page.link";
                entitlements.AddAssociatedDomains(new[] { link });
                entitlements.WriteToFile();
                Debug.Log(CASEditorUtils.logTag + "Apply application shame: " + link);
            }
            catch (Exception e)
            {
                Debug.LogError(CASEditorUtils.logTag + "Dynamic link creation fail: " + e.ToString());
            }
        }
コード例 #7
0
        private static void UpdateGADAppId(PlistDocument plist, CASInitSettings initSettings, DependencyManager deps)
        {
            if (!initSettings)
            {
                return;
            }
            #region Read Admob App ID from CAS Settings
            bool admobAppIdRequired = deps == null;
            if (deps != null)
            {
                var admobDep = deps.Find(AdNetwork.GoogleAds);
                if (admobDep != null)
                {
                    admobAppIdRequired = admobDep.IsInstalled();
                }
            }

            string admobAppId = null;
            if (initSettings.managersCount > 0)
            {
                string settingsPath = CASEditorUtils.GetNativeSettingsPath(BuildTarget.iOS, initSettings.GetManagerId(0));
                if (File.Exists(settingsPath))
                {
                    try
                    {
                        admobAppId = CASEditorUtils.GetAdmobAppIdFromJson(File.ReadAllText(settingsPath));
                    }
                    catch (Exception e)
                    {
                        if (!initSettings.IsTestAdMode() && admobAppIdRequired)
                        {
                            CASEditorUtils.StopBuildWithMessage(e.ToString(), BuildTarget.iOS);
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(admobAppId) && initSettings.IsTestAdMode())
            {
                admobAppId = CASEditorUtils.iosAdmobSampleAppID;
            }

            #endregion

            if (!string.IsNullOrEmpty(admobAppId))
            {
                plist.root.SetString("GADApplicationIdentifier", admobAppId);
            }
        }