Example #1
0
    public static void Load()
    {
        print("LOADINGDATANOW");

        if (saveLocation == null)
        {
            saveLocation = string.Format("{0}/AlmostTimeSavedData.dat", Application.persistentDataPath);
        }

        try
        {
            if (File.Exists(saveLocation))
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                FileStream      fileStream      = File.Open(saveLocation, FileMode.Open);

                VariablesToSave savedData = (VariablesToSave)binaryFormatter.Deserialize(fileStream);
                fileStream.Close();

                SaveManager.m_level = savedData.m_level;
                //SaveManager.m_controlPreset = savedData.m_controlPreset;
            }
        }

        catch (Exception e)
        {
            PlatformSafeMessage("Failed to Load: " + e.Message);
        }
    }
Example #2
0
    public static void Save()
    {
        print("SAVINGDATANOW");

        BinaryFormatter binaryFormatter = new BinaryFormatter();
        FileStream      fileStream;

        if (saveLocation == null)
        {
            saveLocation = string.Format("{0}/AlmostTimeSavedData.dat", Application.persistentDataPath);
        }

        try
        {
            if (File.Exists(saveLocation))
            {
                File.WriteAllText(saveLocation, string.Empty);
                fileStream = File.Open(saveLocation, FileMode.Open);
                print("File exists and saved");
            }

            else
            {
                fileStream = File.Create(saveLocation);
                print("Creating file");
            }

            VariablesToSave savedData = new VariablesToSave();

            savedData.m_level = SaveManager.m_level;
            //savedData.m_controlPreset = SaveManager.m_controlPreset;


            binaryFormatter.Serialize(fileStream, savedData);
            fileStream.Close();

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

        catch (Exception e)
        {
            PlatformSafeMessage("Failed to Save: " + e.Message);
        }
    }