Esempio n. 1
0
        /// <summary>
        /// Starts the setup process.
        /// </summary>
        public void DoSetup()
        {
            if (PerformSetup(mWebClientId, mConstantDirectory, mClassName, mConfigData, null))
            {
                CheckBundleId();

                EditorUtility.DisplayDialog(
                    GPGSStrings.Success,
                    GPGSStrings.AndroidSetup.SetupComplete,
                    GPGSStrings.Ok);

                GPGSProjectSettings.Instance.Set(GPGSUtil.ANDROIDSETUPDONEKEY, true);
                Close();
            }
            else
            {
                GPGSUtil.Alert(
                    GPGSStrings.Error,
                    "Invalid or missing XML resource data.  Make sure the data is" +
                    " valid and contains the app_id element");
            }
        }
        /// Provide static access to setup for facilitating automated builds.
        /// <param name="nearbyServiceId">The nearby connections service Id</param>
        /// <param name="androidBuild">true if building android</param>
        public static bool PerformSetup(string nearbyServiceId, bool androidBuild)
        {
            // check for valid app id
            if (!GPGSUtil.LooksLikeValidServiceId(nearbyServiceId))
            {
                GPGSUtil.Alert(GPGSStrings.Setup.ServiceIdError);
                return(false);
            }

            GPGSProjectSettings.Instance.Set(GPGSUtil.SERVICEIDKEY, nearbyServiceId);
            GPGSProjectSettings.Instance.Save();

            if (androidBuild)
            {
                // create needed directories
                GPGSUtil.EnsureDirExists("Assets/Plugins");
                GPGSUtil.EnsureDirExists("Assets/Plugins/Android");

                // Generate AndroidManifest.xml
                GPGSUtil.GenerateAndroidManifest();

                GPGSProjectSettings.Instance.Set(GPGSUtil.NEARBYSETUPDONEKEY, true);
                GPGSProjectSettings.Instance.Save();

                // Resolve the dependencies
                Google.VersionHandler.VerboseLoggingEnabled = true;
                Google.VersionHandler.UpdateVersionedAssets(forceUpdate: true);
                Google.VersionHandler.Enabled = true;
                AssetDatabase.Refresh();

                Google.VersionHandler.InvokeStaticMethod(
                    Google.VersionHandler.FindClass(
                        "Google.JarResolver",
                        "GooglePlayServices.PlayServicesResolver"),
                    "MenuResolve", null);
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Performs the setup.  This is called externally to facilitate
        /// build automation.
        /// </summary>
        /// <param name="clientId">Client identifier.</param>
        /// <param name="bundleId">Bundle identifier.</param>
        /// <param name="webClientId">web app client id.</param>
        /// <param name="nearbySvcId">Nearby connections service Id.</param>
        /// <param name="requiresGooglePlus">App requires G+ access</param>
        public static bool PerformSetup(string clientId, string bundleId,
                                        string webClientId, string nearbySvcId, bool requiresGooglePlus)
        {
            if (!GPGSUtil.LooksLikeValidClientId(clientId))
            {
                GPGSUtil.Alert(GPGSStrings.Setup.ClientIdError);
                return(false);
            }

            if (!GPGSUtil.LooksLikeValidBundleId(bundleId))
            {
                GPGSUtil.Alert(GPGSStrings.IOSSetup.BundleIdError);
                return(false);
            }

            // nearby is optional - only set it up if present.
            if (nearbySvcId != null)
            {
#if (UNITY_IPHONE && !NO_GPGS)
                bool ok = NearbyConnectionUI.PerformSetup(nearbySvcId, false);
                if (!ok)
                {
                    Debug.LogError("NearbyConnection Setup failed, returing false.");
                    return(false);
                }
#endif
            }

            Save(clientId, bundleId, webClientId, requiresGooglePlus);
            GPGSUtil.UpdateGameInfo();

            // Finished!
            GPGSProjectSettings.Instance.Set(GPGSUtil.IOSSETUPDONEKEY, true);
            GPGSProjectSettings.Instance.Save();
            AssetDatabase.Refresh();
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes static members of the <see cref="GooglePlayGames.GPGSUpgrader"/> class.
        /// </summary>
        static GPGSUpgrader()
        {
            string prevVer = GPGSProjectSettings.Instance.Get(GPGSUtil.LASTUPGRADEKEY, "00000");

            if (!prevVer.Equals(PluginVersion.VersionKey))
            {
                // if this is a really old version, upgrade to 911 first, then 915
                if (!prevVer.Equals(PluginVersion.VersionKeyCPP))
                {
                    prevVer = Upgrade911(prevVer);
                }

                prevVer = Upgrade915(prevVer);

                prevVer = Upgrade927Patch(prevVer);

                // Upgrade to remove gpg version of jar resolver
                prevVer = Upgrade928(prevVer);

                prevVer = Upgrade930(prevVer);

                prevVer = Upgrade931(prevVer);

                prevVer = Upgrade935(prevVer);

                prevVer = Upgrade941(prevVer);

                prevVer = Upgrade942(prevVer);

                // there is no migration needed to 930+
                if (!prevVer.Equals(PluginVersion.VersionKey))
                {
                    Debug.Log("Upgrading from format version " + prevVer + " to " + PluginVersion.VersionKey);
                    prevVer = PluginVersion.VersionKey;
                }

                string msg = GPGSStrings.PostInstall.Text.Replace(
                    "$VERSION",
                    PluginVersion.VersionString);
                EditorUtility.DisplayDialog(GPGSStrings.PostInstall.Title, msg, "OK");
            }

            GPGSProjectSettings.Instance.Set(GPGSUtil.LASTUPGRADEKEY, prevVer);
            GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY,
                                             PluginVersion.VersionString);
            GPGSProjectSettings.Instance.Save();

            // clean up duplicate scripts if Unity 5+
            int ver = GPGSUtil.GetUnityMajorVersion();

            if (ver >= 5)
            {
                string[] paths =
                {
                    "Assets/GooglePlayGames",
                    "Assets/Plugins/Android",
                    "Assets/PlayServicesResolver"
                };
                foreach (string p in paths)
                {
                    CleanDuplicates(p);
                }

                // remove support lib from old location.
                string jarFile =
                    "Assets/Plugins/Android/libs/android-support-v4.jar";
                if (File.Exists(jarFile))
                {
                    File.Delete(jarFile);
                }

                // remove the massive play services client lib
                string clientDir = "Assets/Plugins/Android/google-play-services_lib";
                GPGSUtil.DeleteDirIfExists(clientDir);
            }

            // Check that there is a AndroidManifest.xml file
            if (!GPGSUtil.AndroidManifestExists())
            {
                GPGSUtil.GenerateAndroidManifest();
            }

            AssetDatabase.Refresh();
        }
Esempio n. 5
0
        /// <summary>
        /// Writes the resource identifiers file.  This file contains the
        /// resource ids copied (downloaded?) from the play game app console.
        /// </summary>
        /// <param name="classDirectory">Class directory.</param>
        /// <param name="className">Class name.</param>
        /// <param name="resourceKeys">Resource keys.</param>
        public static void WriteResourceIds(string classDirectory, string className, Hashtable resourceKeys)
        {
            string constantsValues = string.Empty;

            string[] parts   = className.Split('.');
            string   dirName = classDirectory;

            if (string.IsNullOrEmpty(dirName))
            {
                dirName = "Assets";
            }

            string nameSpace = string.Empty;

            for (int i = 0; i < parts.Length - 1; i++)
            {
                dirName += "/" + parts[i];
                if (nameSpace != string.Empty)
                {
                    nameSpace += ".";
                }

                nameSpace += parts[i];
            }

            EnsureDirExists(dirName);
            foreach (DictionaryEntry ent in resourceKeys)
            {
                string key = MakeIdentifier((string)ent.Key);
                constantsValues += "        public const string " +
                                   key + " = \"" + ent.Value + "\"; // <GPGSID>\n";
            }

            string fileBody = GPGSUtil.ReadEditorTemplate("template-Constants");

            if (nameSpace != string.Empty)
            {
                fileBody = fileBody.Replace(
                    NAMESPACESTARTPLACEHOLDER,
                    "namespace " + nameSpace + "\n{");
            }
            else
            {
                fileBody = fileBody.Replace(NAMESPACESTARTPLACEHOLDER, string.Empty);
            }

            fileBody = fileBody.Replace(CLASSNAMEPLACEHOLDER, parts[parts.Length - 1]);
            fileBody = fileBody.Replace(CONSTANTSPLACEHOLDER, constantsValues);
            if (nameSpace != string.Empty)
            {
                fileBody = fileBody.Replace(
                    NAMESPACEENDPLACEHOLDER,
                    "}");
            }
            else
            {
                fileBody = fileBody.Replace(NAMESPACEENDPLACEHOLDER, string.Empty);
            }

            WriteFile(Path.Combine(dirName, parts[parts.Length - 1] + ".cs"), fileBody);
        }
Esempio n. 6
0
        /// <summary>
        /// Called when the GUI should be rendered.
        /// </summary>
        public void OnGUI()
        {
            GUI.skin.label.wordWrap = true;
            GUILayout.BeginVertical();

            GUIStyle link = new GUIStyle(GUI.skin.label);

            link.normal.textColor = new Color(0f, 0f, 1f);

            GUILayout.Space(10);
            GUILayout.Label(GPGSStrings.AndroidSetup.Blurb);
            if (GUILayout.Button("Open Play Games Console", link, GUILayout.ExpandWidth(false)))
            {
                Application.OpenURL("https://play.google.com/apps/publish");
            }

            Rect last = GUILayoutUtility.GetLastRect();

            last.y     += last.height - 2;
            last.x     += 3;
            last.width -= 6;
            last.height = 2;

            GUI.Box(last, string.Empty);

            GUILayout.Space(15);
            GUILayout.Label("Constants class name", EditorStyles.boldLabel);
            GUILayout.Label("Enter the fully qualified name of the class to create containing the constants");
            GUILayout.Space(10);

            mConstantDirectory = EditorGUILayout.TextField(
                "Directory to save constants",
                mConstantDirectory,
                GUILayout.Width(480));

            mClassName = EditorGUILayout.TextField(
                "Constants class name",
                mClassName,
                GUILayout.Width(480));

            GUILayout.Label("Resources Definition", EditorStyles.boldLabel);
            GUILayout.Label("Paste in the Android Resources from the Play Console");
            GUILayout.Space(10);

            scroll      = GUILayout.BeginScrollView(scroll);
            mConfigData = EditorGUILayout.TextArea(
                mConfigData,
                GUILayout.Width(475),
                GUILayout.Height(Screen.height));
            GUILayout.EndScrollView();
            GUILayout.Space(10);

            // Requires G+ field
            GUILayout.BeginHorizontal();
            GUILayout.Label(GPGSStrings.Setup.RequiresGPlusTitle, EditorStyles.boldLabel);
            mRequiresGooglePlus = EditorGUILayout.Toggle(mRequiresGooglePlus);
            GUILayout.EndHorizontal();
            GUILayout.Label(GPGSStrings.Setup.RequiresGPlusBlurb);

            // Client ID field
            GUILayout.Label(GPGSStrings.Setup.WebClientIdTitle, EditorStyles.boldLabel);
            GUILayout.Label(GPGSStrings.AndroidSetup.WebClientIdBlurb);

            mWebClientId = EditorGUILayout.TextField(
                GPGSStrings.Setup.ClientId,
                mWebClientId,
                GUILayout.Width(450));

            GUILayout.Space(10);

            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GPGSStrings.Setup.SetupButton, GUILayout.Width(100)))
            {
                // check that the classname entered is valid
                try
                {
                    if (GPGSUtil.LooksLikeValidPackageName(mClassName))
                    {
                        DoSetup();
                    }
                }
                catch (Exception e)
                {
                    GPGSUtil.Alert(
                        GPGSStrings.Error,
                        "Invalid classname: " + e.Message);
                }
            }

            if (GUILayout.Button("Cancel", GUILayout.Width(100)))
            {
                Close();
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(20);
            GUILayout.EndVertical();
        }
Esempio n. 7
0
        /// <summary>
        /// Provide static access to setup for facilitating automated builds.
        /// </summary>
        /// <param name="webClientId">The oauth2 client id for the game.  This is only
        /// needed if the ID Token or access token are needed.</param>
        /// <param name="appId">App identifier.</param>
        /// <param name="nearbySvcId">Optional nearby connection serviceId</param>
        /// <param name="requiresGooglePlus">Indicates that GooglePlus should be enabled</param>
        /// <returns>true if successful</returns>
        public static bool PerformSetup(string webClientId, string appId,
                                        string nearbySvcId,
                                        bool requiresGooglePlus)
        {
            if (!string.IsNullOrEmpty(webClientId))
            {
                if (!GPGSUtil.LooksLikeValidClientId(webClientId))
                {
                    GPGSUtil.Alert(GPGSStrings.Setup.ClientIdError);
                    return(false);
                }

                string serverAppId = webClientId.Split('-')[0];
                if (!serverAppId.Equals(appId))
                {
                    GPGSUtil.Alert(GPGSStrings.Setup.AppIdMismatch);
                    return(false);
                }
            }

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

            if (nearbySvcId != null)
            {
                if (!NearbyConnectionUI.PerformSetup(nearbySvcId, true))
                {
                    return(false);
                }
            }

            GPGSProjectSettings.Instance.Set(GPGSUtil.APPIDKEY, appId);
            GPGSProjectSettings.Instance.Set(GPGSUtil.WEBCLIENTIDKEY, webClientId);
            GPGSProjectSettings.Instance.Set(GPGSUtil.REQUIREGOOGLEPLUSKEY, requiresGooglePlus);
            GPGSProjectSettings.Instance.Save();
            GPGSUtil.UpdateGameInfo();

            // 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(false);
            }

            // Generate AndroidManifest.xml
            GPGSUtil.GenerateAndroidManifest();

            // refresh assets, and we're done
            AssetDatabase.Refresh();
            GPGSProjectSettings.Instance.Set(GPGSUtil.ANDROIDSETUPDONEKEY, true);
            GPGSProjectSettings.Instance.Save();

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes static members of the <see cref="GooglePlayGames.GPGSUpgrader"/> class.
        /// </summary>
        static GPGSUpgrader()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }
            Debug.Log("GPGSUpgrader start");
            string initialVer = GPGSProjectSettings.Instance.Get(GPGSUtil.LASTUPGRADEKEY, "00000");

            if (!initialVer.Equals(PluginVersion.VersionKey))
            {
                Debug.Log("Upgrading from format version " + initialVer + " to " + PluginVersion.VersionKey);
                string prevVer = initialVer;
                prevVer = Upgrade911(prevVer);
                prevVer = Upgrade915(prevVer);
                prevVer = Upgrade927Patch(prevVer);

                // Upgrade to remove gpg version of jar resolver
                prevVer = Upgrade928(prevVer);
                prevVer = Upgrade930(prevVer);
                prevVer = Upgrade931(prevVer);
                prevVer = Upgrade935(prevVer);
                prevVer = Upgrade941(prevVer);
                prevVer = Upgrade942(prevVer);

                Debug.Log("Done all upgrades to " + PluginVersion.VersionKey);

                string msg = GPGSStrings.PostInstall.Text.Replace(
                    "$VERSION",
                    PluginVersion.VersionString);
                EditorUtility.DisplayDialog(GPGSStrings.PostInstall.Title, msg, "OK");
            }

            GPGSProjectSettings.Instance.Set(GPGSUtil.LASTUPGRADEKEY, PluginVersion.VersionKey);
            GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY,
                                             PluginVersion.VersionString);
            GPGSProjectSettings.Instance.Save();

            // clean up duplicate scripts if Unity 5+
            int ver = GPGSUtil.GetUnityMajorVersion();

            if (ver >= 5)
            {
                string[] paths =
                {
                    GPGSUtil.RootPath,
                    "Assets/Plugins/Android",
                    "Assets/PlayServicesResolver"
                };
                foreach (string p in paths)
                {
                    CleanDuplicates(p);
                }

                // remove support lib from old location.
                string jarFile =
                    "Assets/Plugins/Android/libs/android-support-v4.jar";
                if (File.Exists(jarFile))
                {
                    File.Delete(jarFile);
                }

                // remove the massive play services client lib
                string clientDir = "Assets/Plugins/Android/google-play-services_lib";
                GPGSUtil.DeleteDirIfExists(clientDir);
            }

            // Check that there is a AndroidManifest.xml file
            if (!GPGSUtil.AndroidManifestExists())
            {
                GPGSUtil.GenerateAndroidManifest();
            }

            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                AssetDatabase.Refresh();
            }
            Debug.Log("GPGSUpgrader done");
        }
        /// <summary>
        /// Checks for the android manifest file exsistance.
        /// </summary>
        /// <returns><c>true</c>, if the file exists <c>false</c> otherwise.</returns>
        public static bool AndroidManifestExists()
        {
            string destFilename = GPGSUtil.SlashesToPlatformSeparator(ManifestPath);

            return(File.Exists(destFilename));
        }
        private static bool ParseResources(string classDirectory, string className, string res)
        {
            // parse the resources, they keys are in the form of
            // #define <KEY> @"<VALUE>"

            // transform the string to make it easier to parse
            string input = res.Replace("#define ", string.Empty);

            input = input.Replace("@\"", string.Empty);
            input = input.Replace("\"", string.Empty);

            // now input is name value, one per line
            StringReader reader = new StringReader(input);
            string       line   = reader.ReadLine();
            string       key;
            string       value;
            string       clientId     = null;
            Hashtable    resourceKeys = new Hashtable();

            while (line != null)
            {
                string[] parts = line.Split(' ');
                key = parts[0];
                if (parts.Length > 1)
                {
                    value = parts[1];
                }
                else
                {
                    value = null;
                }

                if (!string.IsNullOrEmpty(value))
                {
                    if (key == "CLIENT_ID")
                    {
                        clientId = value;
                        GPGSProjectSettings.Instance.Set(GPGSUtil.IOSCLIENTIDKEY, clientId);
                    }
                    else if (key == "BUNDLE_ID")
                    {
                        GPGSProjectSettings.Instance.Set(GPGSUtil.IOSBUNDLEIDKEY, value);
                    }
                    else if (key.StartsWith("ACH_"))
                    {
                        string prop = "achievement_" + key.Substring(4).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else if (key.StartsWith("LEAD_"))
                    {
                        string prop = "leaderboard_" + key.Substring(5).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else if (key.StartsWith("EVENT_"))
                    {
                        string prop = "event_" + key.Substring(6).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else if (key.StartsWith("QUEST_"))
                    {
                        string prop = "quest_" + key.Substring(6).ToLower();
                        resourceKeys[prop] = value;
                    }
                    else
                    {
                        resourceKeys[key] = value;
                    }
                }

                line = reader.ReadLine();
            }

            reader.Close();
            if (resourceKeys.Count > 0)
            {
                GPGSUtil.WriteResourceIds(classDirectory, className, resourceKeys);
            }

            GPGSProjectSettings.Instance.Save();
            return(!string.IsNullOrEmpty(clientId));
        }