Esempio n. 1
0
        public static void Save(HiScoreData data)

        {
            BinaryFormatter formatter = new BinaryFormatter();

            string pathFolder = Application.persistentDataPath + "\\Data";
            string path       = pathFolder + "\\ScoreInformation.hax";

            if (!File.Exists(pathFolder))
            {
                Directory.CreateDirectory(pathFolder);
            }

            FileStream stream = new FileStream(path, FileMode.Create);

            formatter.Serialize(stream, data);

            stream.Close();
        }
Esempio n. 2
0
        public static HiScoreData Load(float defaultValue)
        {
            string path = Application.persistentDataPath + "\\Data\\ScoreInformation.hax";

            if (File.Exists(path))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                FileStream      stream    = new FileStream(path, FileMode.Open);

                HiScoreData data = formatter.Deserialize(stream) as HiScoreData;
                stream.Close();

                return(data);
            }
            else
            {
                Debug.LogError("Save file not found in" + path);
                var data = new HiScoreData(defaultValue);
                return(data);
            }
        }