public static void SavePlayer(JB_PlayerUnit player)
    {
        BinaryFormatter formatter = new BinaryFormatter();

        // finds a directory on any operating system the game is running on
        string path = Application.persistentDataPath + "/player.dat";

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

        JB_PlayerData data = new JB_PlayerData(player);

        // writing data to our file
        formatter.Serialize(stream, data);
        stream.Close();
    }
Esempio n. 2
0
    public JB_PlayerData(JB_PlayerUnit player)
    {
        heroType = (int)player.heroType;
        movable  = player.canMove;

        // initialising arrays
        position = new float[2];
        //levers.Clear();
        //waterMovables.Clear();
        //waterToggles.Clear();
        //itemsPickedUp.Clear();

        //levers = new bool[player.bLevers.Count];
        //waterMovables = new bool[player.waterMovable.Count];
        //waterToggles = new bool[player.waterToggle.Count];
        //itemsPickedUp = new bool[player.itemsPickedUp.Length];


        position[0] = player.transform.position.x;
        position[1] = player.transform.position.y;

        for (int i = 0; i < player.bLevers.Count; ++i)
        {
            levers.Add(player.bLevers[i]);
        }

        for (int i = 0; i < player.itemsPickedUp.Length; ++i)
        {
            itemsPickedUp.Add(player.itemsPickedUp[i]);
        }

        for (int i = 0; i < player.waterMovable.Count; ++i)
        {
            waterMovables.Add(player.waterMovable[i]);
            waterToggles.Add(player.waterToggle[i]);
        }
    }