Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates a static script that provides acces 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(c_leaderboardsPath)))
            {
                string newLeaderboardsScript;
                string idPropertyTemplate;
                using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(c_leaderboardsTemplatePath)))
                {
                    newLeaderboardsScript = reader.ReadToEnd();
                }

                using (TextReader reader = File.OpenText(GPGSUtil.SlashesToPlatformSeparator(c_leaderboardsPropertyTemplatePath)))
                {
                    idPropertyTemplate = reader.ReadToEnd();
                }

                var builder = 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);
                    propertyString = propertyString.Replace("AMAZONID", cloudConfig.LeaderboardIDs[i].AmazonId);
                    builder.AppendLine(propertyString);
                    if (i != cloudConfig.LeaderboardIDs.Count - 1)
                    {
                        builder.AppendLine();
                    }
                }

                newLeaderboardsScript = newLeaderboardsScript.Replace("// LEADERBOARD_IDS", builder.ToString());

                writer.Write(newLeaderboardsScript);
            }

            try
            {
                AssetDatabase.ImportAsset(GPGSUtil.SlashesToPlatformSeparator(c_leaderboardsPath));
            }
            catch (Exception)
            {
                Debug.LogError("Can't import asset: " + GPGSUtil.SlashesToPlatformSeparator(c_leaderboardsPath));
            }
        }
Ejemplo n.º 5
0
        /// <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));
            }
        }