/// <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> public static void PerformSetup(string clientId, string bundleId) { if (!GPGSUtil.LooksLikeValidClientId(clientId)) { GPGSUtil.Alert(GPGSStrings.IOSSetup.ClientIdError); return; } if (!GPGSUtil.LooksLikeValidBundleId(bundleId)) { GPGSUtil.Alert(GPGSStrings.IOSSetup.BundleIdError); return; } Save(clientId, bundleId); GPGSUtil.UpdateGameInfo(); FillInAppData(GameInfoPath, GameInfoPath, clientId, bundleId); // Finished! GPGSProjectSettings.Instance.Set("ios.SetupDone", true); GPGSProjectSettings.Instance.Save(); AssetDatabase.Refresh(); GPGSUtil.Alert(GPGSStrings.Success, GPGSStrings.IOSSetup.SetupComplete); }
//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); }
public void OnGUI() { GUIStyle link = new GUIStyle(GUI.skin.label); link.normal.textColor = new Color(.7f, .7f, 1f); // Title GUILayout.BeginVertical(); GUILayout.Space(10); GUILayout.Label(GPGSStrings.IOSSetup.Blurb); GUILayout.Space(10); 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); // Bundle ID field GUILayout.Label(GPGSStrings.IOSSetup.BundleIdTitle, EditorStyles.boldLabel); GUILayout.Label(GPGSStrings.IOSSetup.BundleIdBlurb, EditorStyles.wordWrappedLabel); mBundleId = EditorGUILayout.TextField(GPGSStrings.IOSSetup.BundleId, mBundleId, GUILayout.Width(450)); GUILayout.Space(30); // Client ID field GUILayout.Label(GPGSStrings.Setup.WebClientIdTitle, EditorStyles.boldLabel); GUILayout.Label(GPGSStrings.AndroidSetup.WebClientIdBlurb, EditorStyles.wordWrappedLabel); GUILayout.Space(10); mWebClientId = EditorGUILayout.TextField(GPGSStrings.Setup.ClientId, mWebClientId, GUILayout.Width(450)); GUILayout.Space(10); GUILayout.FlexibleSpace(); 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); mClassDirectory = EditorGUILayout.TextField("Directory to save constants", mClassDirectory, GUILayout.Width(480)); mClassName = EditorGUILayout.TextField("Constants class name", mClassName, GUILayout.Width(480)); GUILayout.Label("Resources Definition", EditorStyles.boldLabel); GUILayout.Label("Paste in the Objective-C 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); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Setup button if (GUILayout.Button(GPGSStrings.Setup.SetupButton)) { // 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(GPGSStrings.Cancel)) { this.Close(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(20); GUILayout.EndVertical(); }
public static void CopySupportLibs() { string sdkPath = GetAndroidSdkPath(); string supportJarPath = sdkPath + GPGSUtil.SlashesToPlatformSeparator( "/extras/android/support/v4/android-support-v4.jar"); string supportJarDest = GPGSUtil.SlashesToPlatformSeparator("Assets/Plugins/Android/libs/android-support-v4.jar"); 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"); // 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; } // check version int version = GetGPSVersion(libProjPath); if (version < 0) { Debug.LogError("Google Play Services lib version cannot be found!"); } if (version < PluginVersion.MinGmsCoreVersionCode) { if (!EditorUtility.DisplayDialog(string.Format( GPGSStrings.AndroidSetup.LibProjVerTooOld, version, PluginVersion.MinGmsCoreVersionCode), GPGSStrings.Ok, GPGSStrings.Cancel)) { Debug.LogError("Google Play Services lib is too old! " + " Found version " + version + " require at least version " + PluginVersion.MinGmsCoreVersionCode); return; } Debug.Log("Ignoring the version mismatch and continuing the build."); } // clear out the destination library project GPGSUtil.DeleteDirIfExists(libProjDestDir); // Copy Google Play Services library FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir); 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 GPGSUtil.EnsureDirExists("Assets/Plugins"); GPGSUtil.EnsureDirExists("Assets/Plugins/Android"); // Clear out any stale version of the support jar. File.Delete(supportJarDest); // Copy Android Support Library FileUtil.CopyFileOrDirectory(supportJarPath, supportJarDest); }
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.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); } return(!string.IsNullOrEmpty(clientId)); }
/// <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> /// <returns>true if successful</returns> public static bool PerformSetup(string webClientId, string appId, string nearbySvcId) { bool needTokenPermissions = false; 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); } needTokenPermissions = true; } else { needTokenPermissions = 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.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); } GPGSUtil.CopySupportLibs(); // Generate AndroidManifest.xml GPGSUtil.GenerateAndroidManifest(needTokenPermissions); // refresh assets, and we're done AssetDatabase.Refresh(); GPGSProjectSettings.Instance.Set(GPGSUtil.ANDROIDSETUPDONEKEY, true); GPGSProjectSettings.Instance.Save(); return(true); }
public void OnGUI() { // Title GUILayout.BeginVertical(); GUILayout.Space(10); GUILayout.Label(GPGSStrings.IOSSetup.Blurb); GUILayout.Space(10); // Bundle ID field GUILayout.Label(GPGSStrings.IOSSetup.BundleIdTitle, EditorStyles.boldLabel); GUILayout.Label(GPGSStrings.IOSSetup.BundleIdBlurb, EditorStyles.wordWrappedLabel); mBundleId = EditorGUILayout.TextField(GPGSStrings.IOSSetup.BundleId, mBundleId, GUILayout.Width(450)); GUILayout.Space(30); // Client ID field GUILayout.Label(GPGSStrings.Setup.WebClientIdTitle, EditorStyles.boldLabel); GUILayout.Label(GPGSStrings.AndroidSetup.WebClientIdBlurb, EditorStyles.wordWrappedLabel); GUILayout.Space(10); mWebClientId = EditorGUILayout.TextField(GPGSStrings.Setup.ClientId, mWebClientId, GUILayout.Width(450)); GUILayout.Space(10); GUILayout.FlexibleSpace(); 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); mClassName = EditorGUILayout.TextField("Constants class name", mClassName, GUILayout.Width(480)); GUILayout.Label("Resources Definition", EditorStyles.boldLabel); GUILayout.Label("Paste in the Objective-C 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); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Setup button if (GUILayout.Button(GPGSStrings.Setup.SetupButton)) { // 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(GPGSStrings.Cancel)) { this.Close(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(20); GUILayout.EndVertical(); }
/// <summary> /// Initializes static members of the <see cref="GooglePlayGames.GPGSUpgrader"/> class. /// </summary> static GPGSUpgrader() { string prevVer = GPGSProjectSettings.Instance.Get(GPGSUtil.LASTUPGRADEKEY, "00000"); if (prevVer != PluginVersion.VersionKey) { // if this is a really old version, upgrade to 911 first, then 915 if (prevVer != PluginVersion.VersionKeyCPP) { prevVer = Upgrade911(prevVer); } prevVer = Upgrade915(prevVer); prevVer = Upgrade927Patch(prevVer); // there is no migration needed to 920+ 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.Save(); // clean up duplicate scripts if Unity 5+ int ver = GPGSUtil.GetUnityMajorVersion(); if (ver >= 5) { string[] paths = { "Assets/GooglePlayGames", "Assets/Plugins/Android" }; 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(false); } AssetDatabase.Refresh(); }
/// <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); }