public static bool DoSetup(string appID) { var projAM = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.GooglePlayLib + "/AndroidManifest.xml"); // check for valid app id if (!GPGSUtil.LooksLikeValidAppId(appID)) { GPGSUtil.Alert(GPGSStrings.Setup.AppIdError); return(false); } // Generate AndroidManifest.xml var manifestBody = GPGSUtil.ReadFile(c_manifestTemplate); manifestBody = manifestBody.Replace(c_appIdPlaceholder, appID); #if UNITY_ANDROID manifestBody = manifestBody.Replace(c_pluginVersionPlaceholder, PluginVersion.VersionString); #endif manifestBody = manifestBody.Replace(c_serviceIdPlaceholder, string.Empty); GPGSUtil.WriteFile(projAM, manifestBody); // Resolve dependencies #if UNITY_ANDROID PlayServicesResolver.Resolver.DoResolution( GPGSDependencies.svcSupport, CloudOncePaths.Android, PlayServicesResolver.HandleOverwriteConfirmation); #endif // refresh assets, and we're done AssetDatabase.Refresh(); return(EditorUtility.DisplayDialog(GPGSStrings.Success, GPGSStrings.AndroidSetup.SetupComplete, GPGSStrings.Ok)); }
/// <summary> /// Loads the cloud configuration. /// </summary> /// <returns>Imported CloudConfig instance. Returns an empty instance if cloud config file doesn't exist.</returns> public static CloudConfig LoadCloudConfig() { var cloudConfig = ScriptableObject.CreateInstance <CloudConfig>(); var settingsPath = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.SettingsProjectSettings); var assetsPath = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.SettingsAssets); string settingsJson = null; if (File.Exists(settingsPath)) { var sr = new StreamReader(settingsPath); settingsJson = sr.ReadToEnd(); sr.Close(); } else if (File.Exists(assetsPath)) { var sr = new StreamReader(assetsPath); settingsJson = sr.ReadToEnd(); sr.Close(); } if (!string.IsNullOrEmpty(settingsJson)) { cloudConfig.ImportSettingsFromJSON(new JSONObject(settingsJson)); } return(cloudConfig); }
/// <summary> /// Generates a static script that contains properties for getting achievement- and leaderboard IDs. /// If the CloudIDs.cs script already exists it will be overwritten. /// </summary> /// <param name="cloudConfig">The CloudConfig instance to generate the static script from.</param> private static void CreateCloudIDsScript(CloudConfig cloudConfig) { using (var writer = new StreamWriter(GPGSUtil.SlashesToPlatformSeparator(cloudIDsPath))) { string newCloudIDsScript; string idPropertyTemplate; using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(cloudIDsTemplatePath))) { newCloudIDsScript = reader.ReadToEnd(); } using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(cloudIDsPropertyTemplatePath))) { idPropertyTemplate = reader.ReadToEnd(); } var builder = new StringBuilder(); for (var i = 0; i < cloudConfig.AchievementIDs.Count; i++) { var propertyString = idPropertyTemplate; propertyString = propertyString.Replace("INTERNALID", cloudConfig.AchievementIDs[i].InternalId); propertyString = propertyString.Replace("GOOGLEID", cloudConfig.AchievementIDs[i].GoogleId); propertyString = propertyString.Replace("APPLEID", cloudConfig.AchievementIDs[i].AppleId); builder.AppendLine(propertyString); if (i != cloudConfig.AchievementIDs.Count - 1) { builder.AppendLine(); } } newCloudIDsScript = newCloudIDsScript.Replace("// ACHIEVEMENT_ID_PROPERTIES", builder.ToString()); builder = new StringBuilder(); for (var i = 0; i < cloudConfig.LeaderboardIDs.Count; i++) { var propertyString = idPropertyTemplate; propertyString = propertyString.Replace("INTERNALID", cloudConfig.LeaderboardIDs[i].InternalId); propertyString = propertyString.Replace("GOOGLEID", cloudConfig.LeaderboardIDs[i].GoogleId); propertyString = propertyString.Replace("APPLEID", cloudConfig.LeaderboardIDs[i].AppleId); builder.AppendLine(propertyString); if (i != cloudConfig.LeaderboardIDs.Count - 1) { builder.AppendLine(); } } newCloudIDsScript = newCloudIDsScript.Replace("// LEADERBOARD_ID_PROPERTIES", builder.ToString()); writer.Write(newCloudIDsScript); } try { AssetDatabase.ImportAsset(GPGSUtil.SlashesToPlatformSeparator(cloudIDsPath)); } catch (Exception) { Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(cloudIDsPath)); } }
/// <summary> /// Generates a static script that provides access to all leaderboards created in the CloudOnce Editor. /// If the Leaderboards.cs script already exists it will be overwritten. /// </summary> /// <param name="cloudConfig">The CloudConfig instance to generate the static script from.</param> private static void CreateLeaderboardsScript(CloudConfig cloudConfig) { using (var writer = new StreamWriter(GPGSUtil.SlashesToPlatformSeparator(leaderboardsPath))) { string newLeaderboardsScript; string idPropertyTemplate; using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(leaderboardsTemplatePath))) { newLeaderboardsScript = reader.ReadToEnd(); } using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(leaderboardsPropertyTemplatePath))) { idPropertyTemplate = reader.ReadToEnd(); } var builder = new StringBuilder(); var dictionaryBuilder = new StringBuilder(); for (var i = 0; i < cloudConfig.LeaderboardIDs.Count; i++) { var propertyString = idPropertyTemplate; propertyString = propertyString.Replace("FIELDNAME", "s_" + FirstLetterToLowerCase(cloudConfig.LeaderboardIDs[i].InternalId)); propertyString = propertyString.Replace("INTERNALID", cloudConfig.LeaderboardIDs[i].InternalId); propertyString = propertyString.Replace("APPLEID", cloudConfig.LeaderboardIDs[i].AppleId); propertyString = propertyString.Replace("GOOGLEID", cloudConfig.LeaderboardIDs[i].GoogleId); builder.AppendLine(propertyString); var dictionaryString = " { \"INTERNALID\", FIELDNAME },"; dictionaryString = dictionaryString.Replace("FIELDNAME", "s_" + FirstLetterToLowerCase(cloudConfig.LeaderboardIDs[i].InternalId)); dictionaryString = dictionaryString.Replace("INTERNALID", cloudConfig.LeaderboardIDs[i].InternalId); dictionaryBuilder.AppendLine(dictionaryString); if (i != cloudConfig.LeaderboardIDs.Count - 1) { builder.AppendLine(); } } if (cloudConfig.LeaderboardIDs.Count > 0) { dictionaryBuilder.Remove(dictionaryBuilder.Length - 2, 2); } newLeaderboardsScript = newLeaderboardsScript.Replace("// LEADERBOARD_IDS", builder.ToString()); newLeaderboardsScript = newLeaderboardsScript.Replace("// LEADERBOARD_DICTIONARY", dictionaryBuilder.ToString()); writer.Write(newLeaderboardsScript); } try { AssetDatabase.ImportAsset(GPGSUtil.SlashesToPlatformSeparator(leaderboardsPath)); } catch (Exception) { Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(leaderboardsPath)); } }
/// <summary> /// Generates a static script that provides acces to all achievements created in the CloudOnce Editor. /// If the Achievements.cs script already exists it will be overwritten. /// </summary> /// <param name="cloudConfig">The CloudConfig instance to generate the static script from.</param> private static void CreateAchievementsScript(CloudConfig cloudConfig) { using (var writer = new StreamWriter(GPGSUtil.SlashesToPlatformSeparator(achievementsPath))) { string newAchievementsScript; string idPropertyTemplate; using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(achievementsTemplatePath))) { newAchievementsScript = reader.ReadToEnd(); } using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(achievementsPropertyTemplatePath))) { idPropertyTemplate = reader.ReadToEnd(); } var builder = new StringBuilder(); foreach (var idData in cloudConfig.AchievementIDs) { var propertyString = idPropertyTemplate; propertyString = propertyString.Replace("FIELDNAME", "s_" + FirstLetterToLowerCase(idData.InternalId)); propertyString = propertyString.Replace("INTERNALID", idData.InternalId); propertyString = propertyString.Replace("APPLEID", idData.AppleId); propertyString = propertyString.Replace("GOOGLEID", idData.GoogleId); propertyString = propertyString.Replace("AMAZONID", idData.AmazonId); builder.AppendLine(propertyString).AppendLine(); } builder.AppendLine(allAchievementsTemplate).AppendLine(" {"); foreach (var idData in cloudConfig.AchievementIDs) { builder.AppendLine(" s_" + FirstLetterToLowerCase(idData.InternalId) + ","); } builder.AppendLine(" };"); newAchievementsScript = newAchievementsScript.Replace("// ACHIEVEMENT_IDS", builder.ToString()); writer.Write(newAchievementsScript); } try { AssetDatabase.ImportAsset(GPGSUtil.SlashesToPlatformSeparator(achievementsPath)); } catch (Exception) { Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(achievementsPath)); } }
/// <summary> /// Serializes a CloudConfig instance to a text file and triggers generation of the CloudIDs.cs /// script that contains properties for each achievement- and leaderboard ID. /// </summary> /// <param name="cloudConfig">The CloudConfig instance that will be serialized.</param> /// <param name="onlySettingsFile">If you only want to save the settings file and not generate CloudIDs, Achievements and Leaderboards scripts.</param> public static void SerializeCloudConfig(CloudConfig cloudConfig, bool onlySettingsFile = false) { using (var writer = new StreamWriter(GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.Settings))) { writer.Write(cloudConfig.ToJSONObject().ToString(true)); } if (!onlySettingsFile) { CreateCloudIDsScript(cloudConfig); CreateAchievementsScript(cloudConfig); CreateLeaderboardsScript(cloudConfig); CreateCloudVariablesScript(cloudConfig); } }
/// <summary> /// Loads the cloud configuration. /// </summary> /// <returns>Imported CloudConfig instance. Returns an empty instance if cloud config file doesn't exist.</returns> public static CloudConfig LoadCloudConfig() { var cloudConfig = ScriptableObject.CreateInstance <CloudConfig>(); var settingsFile = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.Settings); if (File.Exists(settingsFile)) { var sr = new StreamReader(settingsFile); var body = sr.ReadToEnd(); sr.Close(); cloudConfig.ImportSettingsFromJSON(new JSONObject(body)); } return(cloudConfig); }
public static bool DoSetup(string appID) { // check for valid app id if (!GPGSUtil.LooksLikeValidAppId(appID)) { GPGSUtil.Alert(GPGSStrings.Setup.AppIdError); return(false); } if (!GPGSUtil.HasAndroidSdk()) { EditorUtility.DisplayDialog( GPGSStrings.AndroidSetup.SdkNotFound, GPGSStrings.AndroidSetup.SdkNotFoundBlurb, GPGSStrings.Ok); return(false); } // Generate AndroidManifest.xml var destination = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.GooglePlayLib + "/AndroidManifest.xml"); var manifestBody = GPGSUtil.ReadFile(manifestTemplate); manifestBody = manifestBody.Replace(appIdPlaceholder, appID); #if UNITY_ANDROID manifestBody = manifestBody.Replace(pluginVersionPlaceholder, PluginVersion.VersionString); #endif manifestBody = manifestBody.Replace(serviceIdPlaceholder, string.Empty); GPGSUtil.WriteFile(destination, manifestBody); // Resolve dependencies Google.VersionHandler.UpdateVersionedAssets(true); Google.VersionHandler.Enabled = true; AssetDatabase.Refresh(); Google.VersionHandler.InvokeStaticMethod( Google.VersionHandler.FindClass("Google.JarResolver", "GooglePlayServices.PlayServicesResolver"), "MenuResolve", null); // refresh assets, and we're done AssetDatabase.Refresh(); return(EditorUtility.DisplayDialog(GPGSStrings.Success, GPGSStrings.AndroidSetup.SetupComplete, GPGSStrings.Ok)); }
/// <summary> /// Serializes a CloudConfig instance to a text file and triggers generation of the CloudIDs.cs /// script that contains properties for each achievement- and leaderboard ID. /// </summary> /// <param name="cloudConfig">The CloudConfig instance that will be serialized.</param> /// <param name="onlySettingsFile">If you only want to save the settings file and not generate CloudIDs, Achievements and Leaderboards scripts.</param> public static void SerializeCloudConfig(CloudConfig cloudConfig, bool onlySettingsFile = false) { var projectSettingsPath = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.SettingsProjectSettings); var assetsPath = GPGSUtil.SlashesToPlatformSeparator(CloudOncePaths.SettingsAssets); string settingsPath; switch (cloudConfig.SettingsLocation) { case SettingsLocation.ProjectSettings: settingsPath = projectSettingsPath; if (File.Exists(assetsPath)) { try { File.Delete(assetsPath); File.Delete(assetsPath + ".meta"); AssetDatabase.Refresh(); } catch { Debug.LogWarning("Failed to delete settings file: " + assetsPath + "\nIt should be deleted to avoid confusing CloudOnce."); } } break; case SettingsLocation.Assets: settingsPath = assetsPath; if (File.Exists(projectSettingsPath)) { try { File.Delete(projectSettingsPath); } catch { Debug.LogWarning("Failed to delete settings file: " + projectSettingsPath + "\nIt should be deleted to avoid confusing CloudOnce."); } } break; default: throw new ArgumentOutOfRangeException(); } using (var writer = new StreamWriter(settingsPath)) { writer.Write(cloudConfig.ToJSONObject().ToString(true)); } if (cloudConfig.SettingsLocation == SettingsLocation.Assets) { AssetDatabase.Refresh(); } if (!onlySettingsFile) { CreateCloudIDsScript(cloudConfig); CreateAchievementsScript(cloudConfig); CreateLeaderboardsScript(cloudConfig); CreateCloudVariablesScript(cloudConfig); } }
/// <summary> /// Generates a static script that provides access to all cloud variables created in the CloudOnce Editor. /// If the CloudVariables.cs script already exists it will be overwritten. /// </summary> /// <param name="cloudConfig">The CloudConfig instance to generate the static script from.</param> private static void CreateCloudVariablesScript(CloudConfig cloudConfig) { using (var writer = new StreamWriter(GPGSUtil.SlashesToPlatformSeparator(cloudVariablesPath))) { string newCloudVariablesScript; string varPropertyTemplate; using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(cloudVariablesTemplatePath))) { newCloudVariablesScript = reader.ReadToEnd(); } using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(cloudVariablesPropertyTemplatePath))) { varPropertyTemplate = reader.ReadToEnd(); } var builder = new StringBuilder(); for (var i = 0; i < cloudConfig.CloudVariables.Count; i++) { string fieldString; switch (cloudConfig.CloudVariables[i].Type) { case CloudVariableType.Int: case CloudVariableType.Float: case CloudVariableType.Bool: case CloudVariableType.String: case CloudVariableType.Double: case CloudVariableType.UInt: case CloudVariableType.Long: case CloudVariableType.Decimal: fieldString = defaultVariableTemplate; fieldString = fieldString.Replace("PERSISTENCE_TYPE", GetPersistenceTypeString(cloudConfig.CloudVariables[i].PersistenceType)); break; case CloudVariableType.CurrencyFloat: case CloudVariableType.CurrencyInt: fieldString = currencyVariableTemplate; fieldString = fieldString.Replace("ALLOW_NEGATIVE", FirstLetterToLowerCase(cloudConfig.CloudVariables[i].AllowNegative.ToString())); break; case CloudVariableType.DateTime: fieldString = dateTimeVariableTemplate; fieldString = fieldString.Replace("PERSISTENCE_TYPE", GetPersistenceTypeString(cloudConfig.CloudVariables[i].PersistenceType)); break; default: throw new ArgumentOutOfRangeException(); } fieldString = fieldString.Replace("VAR_TYPE", GetClassNameString(cloudConfig.CloudVariables[i].Type)); var fieldName = "s_" + FirstLetterToLowerCase(cloudConfig.CloudVariables[i].Key); fieldString = fieldString.Replace("FIELDNAME", fieldName); fieldString = fieldString.Replace("VAR_ID", cloudConfig.CloudVariables[i].Key); fieldString = fieldString.Replace("VAR_DEFAULT_VALUE", GetDefaultValueString(cloudConfig.CloudVariables[i].DefaultValueString, cloudConfig.CloudVariables[i].Type)); var propertyString = varPropertyTemplate; propertyString = propertyString.Replace("VAR_SIMPLE", GetSimpleVariableTypeString(cloudConfig.CloudVariables[i].Type)); propertyString = propertyString.Replace("VAR_ID", cloudConfig.CloudVariables[i].Key); propertyString = propertyString.Replace("FIELDNAME", fieldName); builder.AppendLine(fieldString).AppendLine(); builder.AppendLine(propertyString); if (i != cloudConfig.CloudVariables.Count - 1) { builder.AppendLine(); } } newCloudVariablesScript = newCloudVariablesScript.Replace("// CLOUD_VARIABLES", builder.ToString()); writer.Write(newCloudVariablesScript); } try { AssetDatabase.ImportAsset(GPGSUtil.SlashesToPlatformSeparator(cloudVariablesPath)); } catch (Exception) { Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(cloudVariablesPath)); } }