Ejemplo n.º 1
0
    void OnApplicationPause()
    {
        LevelFileData lfd = new LevelFileData();

        lfd.saveList.AddRange(openLevels);
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(Application.persistentDataPath + "/levelData.dat", FileMode.Open);

        bf.Serialize(file, lfd);
        file.Close();
    }
Ejemplo n.º 2
0
    void Start()
    {
        DontDestroyOnLoad(gameObject);
        print("Data Path: " + Application.persistentDataPath);

        //Level File Setup

        if (!File.Exists(Application.persistentDataPath + "/levelData.dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(Application.persistentDataPath + "/levelData.dat");
            LevelFileData   lfd  = new LevelFileData();
            lfd.saveList.Add(new KeyValuePair <string, int>("L_1", 0));
            bf.Serialize(file, lfd);
            file.Close();
            foreach (KeyValuePair <string, int> thing in lfd.saveList)
            {
                openLevels.Add(thing.Key, thing.Value);
            }
        }
        else if (File.Exists(Application.persistentDataPath + "/levelData.dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/levelData.dat", FileMode.Open);
            LevelFileData   lfd  = (LevelFileData)bf.Deserialize(file);
            file.Close();
            foreach (KeyValuePair <string, int> thing in lfd.saveList)
            {
                openLevels.Add(thing.Key, thing.Value);
            }
        }
        else
        {
            print("Internal Error: Cannot find levelData.dat");
        }
        backgroundMusic = GetComponent <AudioSource>();
    }