Esempio n. 1
0
        /// <summary>Reads a file and parses the data as a JSON object instance.</summary>
        public static void ReadJSONFile <T>(string path, ReadJSONFileCallback <T> onComplete)
        {
            Debug.Assert(onComplete != null);

            DataStorage.PLATFORM_IO.ReadFile(path, (p, success, data) =>
            {
                T jsonObject;

                if (success)
                {
                    success = IOUtilities.TryParseUTF8JSONData <T>(data, out jsonObject);

                    if (!success)
                    {
                        Debug.LogWarning("[mod.io] Failed parse file content as JSON Object."
                                         + "\nFile: " + path + "\n\n");
                    }
                }
                else
                {
                    jsonObject = default(T);
                }

                if (onComplete != null)
                {
                    onComplete.Invoke(path, success, jsonObject);
                }
            });
        }
Esempio n. 2
0
        /// <summary>Function used to read a user data file.</summary>
        public static void ReadJSONFile <T>(string relativePath, ReadJSONFileCallback <T> callback)
        {
            UserDataStorage.ReadFile(relativePath, (p, success, fileData) =>
            {
                T jsonObject;

                if (success)
                {
                    success = IOUtilities.TryParseUTF8JSONData(fileData, out jsonObject);
                }
                else
                {
                    jsonObject = default(T);
                }

                callback.Invoke(relativePath, success, jsonObject);
            });
        }