public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iPhone)
            {
                return;
            }

            #if NO_GPGS
            // remove plugin code from generated project
            string pluginDir = pathToBuiltProject + "/Libraries/Plugins/iOS";
            GPGSUtil.WriteFile(pluginDir + "/GPGSAppController.mm", "// Empty since NO_GPGS is defined\n");
            return;
            #endif

            if (GetBundleId() == null)
            {
                UnityEngine.Debug.LogError("The iOS bundle ID has not been set up through the " +
                                           "'iOS Setup' submenu of 'Google Play Games' - the generated xcode project will " +
                                           "not work properly.");
                return;
            }

            UnityEngine.Debug.Log("Adding URL Types for authentication using PlistBuddy.");

            UpdateGeneratedInfoPlistFile(pathToBuiltProject + "/Info.plist");
            UpdateGeneratedPbxproj(pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj");

            EditorWindow.GetWindow <GPGSInstructionWindow>(
                utility: true,
                title: "Building for IOS",
                focus: true);
        }
예제 #2
0
        public static void UpdateGameInfo()
        {
            string fileBody = GPGSUtil.ReadFully(GameInfoTemplatePath);
            var    appId    = GPGSProjectSettings.Instance.Get("proj.AppId", null);

            if (appId != null)
            {
                fileBody = fileBody.Replace("__APPID__", appId);
            }

            var clientId = GPGSProjectSettings.Instance.Get("ios.ClientId", null);

            if (clientId != null)
            {
                fileBody = fileBody.Replace("__CLIENTID__", clientId);
            }

            var bundleId = GPGSProjectSettings.Instance.Get("ios.BundleId", null);

            if (bundleId != null)
            {
                fileBody = fileBody.Replace("__BUNDLEID__", bundleId);
            }
            GPGSUtil.WriteFile(GameInfoPath, fileBody);
        }
        public static void GenerateAndroidManifest(bool needTokenPermissions)
        {
            string destFilename = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            // Generate AndroidManifest.xml
            string manifestBody = GPGSUtil.ReadEditorTemplate("template-AndroidManifest");

            Dictionary <string, string> overrideValues = new Dictionary <string, string>();

            if (!needTokenPermissions)
            {
                overrideValues[TOKENPERMISSIONKEY]     = "";
                overrideValues[WEBCLIENTIDPLACEHOLDER] = "";
            }
            else
            {
                overrideValues[TOKENPERMISSIONKEY] = TokenPermissions;
            }

            foreach (KeyValuePair <string, string> ent in Replacements)
            {
                string value =
                    GPGSProjectSettings.Instance.Get(ent.Value, overrideValues);
                manifestBody = manifestBody.Replace(ent.Key, value);
            }

            GPGSUtil.WriteFile(destFilename, manifestBody);
            GPGSUtil.UpdateGameInfo();
        }
예제 #4
0
        public static void UpdateGameInfo()
        {
            string fileBody = GPGSUtil.ReadFully(GameInfoTemplatePath);
            var    appId    = GPGSProjectSettings.Instance.Get(APPIDKEY, null);

            if (appId != null)
            {
                fileBody = fileBody.Replace(APPIDPLACEHOLDER, appId);
            }

            var nearbyServiceId = GPGSProjectSettings.Instance.Get(SERVICEIDKEY, null);

            if (nearbyServiceId != null)
            {
                fileBody = fileBody.Replace(SERVICEIDPLACEHOLDER, appId);
            }

            var clientId = GPGSProjectSettings.Instance.Get(IOSCLIENTIDKEY, null);

            if (clientId != null)
            {
                fileBody = fileBody.Replace(IOSCLIENTIDPLACEHOLDER, clientId);
            }

            var bundleId = GPGSProjectSettings.Instance.Get(IOSBUNDLEIDKEY, null);

            if (bundleId != null)
            {
                fileBody = fileBody.Replace(IOSBUNDLEIDPLACEHOLDER, bundleId);
            }

            GPGSUtil.WriteFile(GameInfoPath, fileBody);
        }
        private void FillInAppData(string sourcePath, string outputPath)
        {
            string fileBody = GPGSUtil.ReadFully(sourcePath);

            fileBody = fileBody.Replace("__CLIENTID__", mClientId);
            fileBody = fileBody.Replace("__BUNDLEID__", mBundleId);
            GPGSUtil.WriteFile(outputPath, fileBody);
        }
예제 #6
0
        /// <summary>
        /// Helper function to do search and replace of the client and bundle ids.
        /// </summary>
        /// <param name="sourcePath">Source path.</param>
        /// <param name="outputPath">Output path.</param>
        /// <param name="clientId">Client identifier.</param>
        /// <param name="bundleId">Bundle identifier.</param>
        private static void FillInAppData(string sourcePath,
                                          string outputPath,
                                          string clientId)
        {
            string fileBody = GPGSUtil.ReadFully(sourcePath);

            fileBody = fileBody.Replace(GPGSUtil.ANDROIDCLIENTIDPLACEHOLDER, clientId);
            GPGSUtil.WriteFile(outputPath, fileBody);
        }
예제 #7
0
        public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
        {
#if UNITY_5
            if (target != BuildTarget.iOS)
            {
                return;
            }
#else
            if (target != BuildTarget.iPhone)
            {
                return;
            }
#endif

            #if NO_GPGS
            Debug.Log("Removing AppController code since NO_GPGS is defined");
            // remove plugin code from generated project
            string pluginDir = pathToBuiltProject + "/Libraries/Plugins/iOS";
            if (System.IO.Directory.Exists(pluginDir))
            {
                GPGSUtil.WriteFile(pluginDir + "/GPGSAppController.mm", "// Empty since NO_GPGS is defined\n");
                return;
            }
            #else
            if (GetBundleId() == null)
            {
                UnityEngine.Debug.LogError("The iOS bundle ID has not been set up through the " +
                                           "'iOS Setup' submenu of 'Google Play Games' - the generated xcode project will " +
                                           "not work properly.");
                return;
            }

            //Copy the podfile into the project.
            string podfile     = "Assets/GooglePlayGames/Editor/Podfile.txt";
            string destpodfile = pathToBuiltProject + "/Podfile";
            if (!System.IO.File.Exists(destpodfile))
            {
                FileUtil.CopyFileOrDirectory(podfile, destpodfile);
            }

            GPGSInstructionWindow w = EditorWindow.GetWindow <GPGSInstructionWindow>(
                true,
                "Building for IOS",
                true);
            w.UsingCocoaPod = CocoaPodHelper.Update(pathToBuiltProject);

            UnityEngine.Debug.Log("Adding URL Types for authentication using PlistBuddy.");

            UpdateGeneratedInfoPlistFile(pathToBuiltProject + "/Info.plist");
            UpdateGeneratedPbxproj(pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj");
        #endif
        }
        public static void UpdateGameInfo()
        {
            string fileBody = GPGSUtil.ReadEditorTemplate("template-GameInfo");

            foreach (KeyValuePair <string, string> ent in Replacements)
            {
                string value =
                    GPGSProjectSettings.Instance.Get(ent.Value);
                fileBody = fileBody.Replace(ent.Key, value);
            }

            GPGSUtil.WriteFile(GameInfoPath, fileBody);
        }
예제 #9
0
        public static void GenerateAndroidManifest()
        {
            string destFilename = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            // Generate AndroidManifest.xml
            string appId           = GPGSProjectSettings.Instance.Get(APPIDKEY, string.Empty);
            string nearbyServiceId = GPGSProjectSettings.Instance.Get(SERVICEIDKEY, string.Empty);
            string manifestBody    = GPGSUtil.ReadEditorTemplate("template-AndroidManifest");

            manifestBody = manifestBody.Replace(APPIDPLACEHOLDER, appId);
            manifestBody = manifestBody.Replace(SERVICEIDPLACEHOLDER, nearbyServiceId);
            GPGSUtil.WriteFile(destFilename, manifestBody);
            GPGSUtil.UpdateGameInfo();
        }
        /// <summary>
        /// Updates the generated pbxproj to reduce manual work required by developers. Currently
        /// this just adds the '-fobjc-arc' flag for the Play Games ObjC source files.
        /// </summary>
        /// <param name="pbxprojPath">Pbxproj path.</param>
        private static void UpdateGeneratedPbxproj(string pbxprojPath)
        {
            // We're looking for lines in the form:
            // ... = {isa = PBXBuildFile; fileRef = DEADBEEF /* GPGSFileName.mm */; };
            // And we want to append "settings = {COMPILER_FLAGS = "-fobjc-arc"};" to the content in
            // between the braces. This is done with a regex replace.
            // The expression is structured as follows:
            // - Begin a capturing group.
            // - Find any line that begins with "<anything>{isa = PBXBuildFile" followed by a
            //   reference to a file beginning with "GPGS" and ending with ".m" (e.g. "GPGSFile.m")
            // - Close the capture group - leaving a trailing "};"
            // - Replace that line with the captured group with
            //   "settings = {COMPILER_FLAGS = "-fobjc-arc";};};" appended. The trailing "};" is needed
            //   because we omitted the "};" from the group.
            var withFlagAdded = Regex.Replace(
                GPGSUtil.ReadFully(pbxprojPath),
                @"(.*\{isa\s*=\s*PBXBuildFile.*GPGS\w*\.m.*)\}\;",
                @"$1settings = {COMPILER_FLAGS = ""-fobjc-arc""; }; };");

            // Overwrite the pbxproj with the updated value.
            GPGSUtil.WriteFile(pbxprojPath, withFlagAdded);
        }
        //Provide static access to setup for facilitating automated builds.
        public static void PerformSetup(string appId)
        {
            string sdkPath     = GPGSUtil.GetAndroidSdkPath();
            string libProjPath = sdkPath +
                                 GPGSUtil.SlashesToPlatformSeparator(
                "/extras/google/google_play_services/libproject/google-play-services_lib");
            string libProjAM =
                libProjPath + GPGSUtil.SlashesToPlatformSeparator("/AndroidManifest.xml");
            string libProjDestDir = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/google-play-services_lib");
            string projAM = GPGSUtil.SlashesToPlatformSeparator(
                "Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

            GPGSProjectSettings.Instance.Set("proj.AppId", appId);
            GPGSProjectSettings.Instance.Save();

            // check for valid app id
            if (!GPGSUtil.LooksLikeValidAppId(appId))
            {
                GPGSUtil.Alert(GPGSStrings.Setup.AppIdError);
                return;
            }

            // check that Android SDK is there
            if (!GPGSUtil.HasAndroidSdk())
            {
                Debug.LogError("Android SDK not found.");
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SdkNotFound,
                                            GPGSStrings.AndroidSetup.SdkNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            // check that the Google Play Services lib project is there
            if (!System.IO.Directory.Exists(libProjPath) || !System.IO.File.Exists(libProjAM))
            {
                Debug.LogError("Google Play Services lib project not found at: " + libProjPath);
                EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.LibProjNotFound,
                                            GPGSStrings.AndroidSetup.LibProjNotFoundBlurb, GPGSStrings.Ok);
                return;
            }

            string supportJarPath = sdkPath +
                                    GPGSUtil.SlashesToPlatformSeparator(
                "/extras/android/support/v4/android-support-v4.jar");
            string supportJarDest =
                GPGSUtil.SlashesToPlatformSeparator("Assets/Plugins/Android/android-support-v4.jar");

            if (!System.IO.File.Exists(supportJarPath))
            {
                // check for the new location
                supportJarPath = sdkPath + GPGSUtil.SlashesToPlatformSeparator(
                    "/extras/android/support/v7/appcompat/libs/android-support-v4.jar");
                Debug.LogError("Android support library v4 not found at: " + supportJarPath);
                if (!System.IO.File.Exists(supportJarPath))
                {
                    EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SupportJarNotFound,
                                                GPGSStrings.AndroidSetup.SupportJarNotFoundBlurb, GPGSStrings.Ok);
                    return;
                }
            }

            // create needed directories
            EnsureDirExists("Assets/Plugins");
            EnsureDirExists("Assets/Plugins/Android");

            // clear out the destination library project
            DeleteDirIfExists(libProjDestDir);

            // Clear out any stale version of the support jar.
            System.IO.File.Delete(supportJarDest);

            // Copy Google Play Services library
            FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir);

            // Copy Android Support Library
            FileUtil.CopyFileOrDirectory(supportJarPath, supportJarDest);

            // Generate AndroidManifest.xml
            string manifestBody = GPGSUtil.ReadEditorTemplate("template-AndroidManifest");

            manifestBody = manifestBody.Replace("___APP_ID___", appId);
            GPGSUtil.WriteFile(projAM, manifestBody);
            GPGSUtil.UpdateGameInfo();

            // refresh assets, and we're done
            AssetDatabase.Refresh();
            GPGSProjectSettings.Instance.Set("android.SetupDone", true);
            GPGSProjectSettings.Instance.Save();
            EditorUtility.DisplayDialog(GPGSStrings.Success,
                                        GPGSStrings.AndroidSetup.SetupComplete, GPGSStrings.Ok);
        }