예제 #1
0
    public void ImportSavedGeneralData()
    {
        Debug.Log("ImportSavedGeneralData...");
        if (File.Exists(Application.persistentDataPath + "/" + savedGeneralDataFileName + gameSaveFileExtension))
        {
            // saves.sav exist
            Debug.Log("general.sav exist. Loading general data...");

            // Reading existing files
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/" + savedGeneralDataFileName + gameSaveFileExtension, FileMode.Open);

            savedGeneralData = bf.Deserialize(stream) as SavedGeneralData;
            highScore        = savedGeneralData.highScore;

            stream.Close();
        }
        else
        {
            // saves.sav doesn't exist
            Debug.Log("general.sav file doesn't exist. Creating...");

            // Binary Formatter + Stream
            BinaryFormatter bf       = new BinaryFormatter();
            string          fileName = (savedGeneralDataFileName + gameSaveFileExtension); // general.sav
            Debug.Log("File Name: " + fileName);
            FileStream stream = new FileStream(Application.persistentDataPath + "/" + fileName, FileMode.Create);

            savedGeneralData = new SavedGeneralData(0);

            bf.Serialize(stream, savedGeneralData);
            stream.Close();
        }
    }
예제 #2
0
    public void SaveGeneralData()
    {
        SavedGeneralData newSavedGeneralData = GatherGeneralData();

        Debug.Log("SaveGeneralData | HighScore [" + newSavedGeneralData.highScore + "]");

        // Binary Formatter + Stream
        BinaryFormatter bf       = new BinaryFormatter();
        string          fileName = (savedGeneralDataFileName + gameSaveFileExtension);

        Debug.Log("File Name: " + fileName);
        FileStream stream = new FileStream(Application.persistentDataPath + "/" + fileName, FileMode.Create);

        // Write file
        bf.Serialize(stream, newSavedGeneralData);
        stream.Close();
    }