コード例 #1
0
 protected void SaveStatusJSON(string statusFileName, StatusSaver statusSaver)
 {
     using (StreamWriter stream = new StreamWriter(statusFileName))
     {
         stream.Write(JsonUtility.ToJson(statusSaver));
     }
 }
コード例 #2
0
 protected void SaveStatusBinary(string statusFileName, StatusSaver statusSaver)
 {
     using (FileStream fs = new FileStream(statusFileName, FileMode.Create))
     {
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(fs, statusSaver);
     }
 }
コード例 #3
0
        protected StatusSaver LoadStatusBinary(string statusFileName)
        {
            StatusSaver statusSaver = null;

            using (FileStream fs = new FileStream(statusFileName, FileMode.Open))
            {
                BinaryFormatter bf = new BinaryFormatter();
                statusSaver = (StatusSaver)bf.Deserialize(fs);
            }
            return(statusSaver);
        }
コード例 #4
0
        protected StatusSaver LoadStatusJSON(string statusFileName)
        {
            StatusSaver statusSaver = null;

            using (StreamReader stream = new StreamReader(statusFileName))
            {
                string filedata = stream.ReadToEnd();
                if (filedata != null)
                {
                    statusSaver = JsonUtility.FromJson <StatusSaver>(filedata);
                }
            }
            return(statusSaver);
        }
コード例 #5
0
        // real save procedure
        protected void RealSave()
        {
            string statusFileName = StatusFileName;

            try
            {
                StatusSaver status = new StatusSaver
                {
                    statusList = new List <StatusChunk>()
                };
                foreach (KeyValuePair <int, List <GenericManager> > list in managers)
                {
                    foreach (GenericManager manager in list.Value)
                    {
                        string signature = manager.SaveSignature();
                        if (!string.IsNullOrEmpty(signature))
                        {
                            object prototype = manager.Save();
                            if (prototype != null)
                            {
                                status.statusList.Add(new StatusChunk {
                                    signature = signature, prototype = prototype
                                });
                            }
                        }
                    }
                }
                if (status.statusList.Count > 0)
                {
                    // choose either save procedure
                    //Debug.Log("Saving managers status to " + statusFileName);
                    SaveStatusBinary(statusFileName, status);
                    //SaveStatusJSON(statusFileName, status);
                }
            }
            catch (System.Exception e)
            {
                Debug.Log("GlobalManager.Save failed: " + e.ToString());
                //throw;
            }
            saveStatus = SaveStatus.Unchanged;
        }
コード例 #6
0
        void Load()
        {
            StatusSaver status = LoadStatus();

            if (status != null)
            {
                foreach (StatusChunk chunk in status.statusList)
                {
                    foreach (KeyValuePair <int, List <GenericManager> > list in managers)
                    {
                        foreach (GenericManager manager in list.Value)
                        {
                            if (manager.CheckSignature(chunk.signature))
                            {
                                manager.Load(chunk.prototype);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
        protected StatusSaver LoadStatus()
        {
            string      statusFileName = StatusFileName;
            StatusSaver statusSaver    = null;

            try
            {
                if (File.Exists(statusFileName))
                {
                    //choose either loading procedure
                    //Debug.Log("Loading managers status from " + statusFileName);
                    statusSaver = LoadStatusBinary(statusFileName);
                    //statusSaver = LoadStatusJSON(statusFileName);
                }
            }
            catch (System.Exception e)
            {
                Debug.Log("Exception: GlobalManager.Load failed: " + e.ToString());
                //throw;
            }
            return(statusSaver);
        }