Пример #1
0
    public void save(int place, string playername, int score)
    {
        Debug.Log("game saved");
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/leaderboard.dat");

        topscorer player = new topscorer();

        for (int i = 9; i > place; i--)
        {
            leadername[i]  = leadername[i - 1];
            leaderscore[i] = leaderscore[i - 1];
        }

        for (int i = 0; i < 9; i++)
        {
            player.name[i]  = leadername[i];
            player.score[i] = leaderscore[i];
        }

        player.name[place]  = playername;
        player.score[place] = score;

        bf.Serialize(file, player);
        file.Close();

        load();
    }
Пример #2
0
    public void load()
    {
        if (File.Exists(Application.persistentDataPath + "/leaderboard.dat"))
        {
            BinaryFormatter bf           = new BinaryFormatter();
            FileStream      file         = File.Open(Application.persistentDataPath + "/leaderboard.dat", FileMode.Open);
            topscorer       currentboard = (topscorer)bf.Deserialize(file);
            file.Close();

            for (int i = 0; i < 10; i++)
            {
                leadername[i]  = currentboard.name[i];
                leaderscore[i] = currentboard.score[i];

                if (leadername[i] == null)
                {
                    nametext[i].text = "null";
                }
                else
                {
                    nametext[i].text = leadername[i];
                }
                scoretext[i].text = leaderscore[i].ToString();
            }
        }
    }