コード例 #1
0
        public static void LoadBinaryData <T>(string p_fileName, LoadBinaryDataCallback <T> p_callback) where T : class
        {
            T      result   = null;
            string filePath = Application.persistentDataPath + p_fileName;

            try
            {
                if (File.Exists(filePath))
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();

                    FileStream fileStream = File.OpenRead(filePath);

                    if (fileStream.CanRead)
                    {
                        result = (T)binaryFormatter.Deserialize(fileStream);
                    }
                }
            }
            catch (Exception exception)
            {
                Ch3Logger.DebugLogError(exception.Message);
            }

            p_callback(result != null, result);
        }
コード例 #2
0
        public static void PersistBinaryData <T>(T p_data, string p_fileName, PersistBinaryDataCallback p_callback) where T : class
        {
            bool   success  = false;
            string filePath = Application.persistentDataPath + p_fileName;

            try
            {
                FileStream fileStream = File.OpenWrite(filePath);

                if (fileStream.CanWrite)
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();

                    binaryFormatter.Serialize(fileStream, p_data);

                    if (Application.platform == RuntimePlatform.WebGLPlayer)
                    {
                        SyncFiles();
                    }

                    success = true;
                }

                fileStream.Close();
            }
            catch (Exception exception)
            {
                Ch3Logger.DebugLogError(exception.Message);
            }

            p_callback(success);
        }