/// <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(c_cloudIDsPath))) { string newCloudIDsScript; string idPropertyTemplate; using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(c_cloudIDsTemplatePath))) { newCloudIDsScript = reader.ReadToEnd(); } using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(c_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("AMAZONID", cloudConfig.AchievementIDs[i].AmazonId); 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("AMAZONID", cloudConfig.LeaderboardIDs[i].AmazonId); 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(c_cloudIDsPath)); } catch (Exception) { Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(c_cloudIDsPath)); } }
/// <summary> /// Generates a static script that provides acces 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(c_cloudVariablesPath))) { string newCloudVariablesScript; string varPropertyTemplate; using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(c_cloudVariablesTemplatePath))) { newCloudVariablesScript = reader.ReadToEnd(); } using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(c_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 = c_defaultVariableTemplate; fieldString = fieldString.Replace("PERSISTENCE_TYPE", GetPersistenceTypeString(cloudConfig.CloudVariables[i].PersistenceType)); break; case CloudVariableType.CurrencyFloat: case CloudVariableType.CurrencyInt: fieldString = c_currencyVariableTemplate; fieldString = fieldString.Replace("ALLOW_NEGATIVE", FirstLetterToLowerCase(cloudConfig.CloudVariables[i].AllowNegative.ToString())); break; case CloudVariableType.DateTime: fieldString = c_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(c_cloudVariablesPath)); } catch (Exception) { Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(c_cloudVariablesPath)); } }