コード例 #1
0
    public void SaveTime(decimal time)
    {
        /* 3 When saving a time, you fetch existing times first with the LoadPreviousTimes() method. */
        var times = LoadPreviousTimes();

        /* 4 You create an instance of the new PlayerTimeEntry object. Then you store the
         * current date and runtime, as passed to the method, in the entryDate and time
         * property fields. */
        var newTime = new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;
        newTime.time      = time;

        /* 5 You create a binary formatter object to do the magic serialization — a.k.a. packing –
         * of the list of player time entries to a file. You create the file path using a
         * combination of the player’s name and the Application.persistentDataPath. Again,
         * the using statement opens the file.
         * However, this time it uses the FileMode.Create option, which lets you create a new
         * file or overwrite existing files in the same path. Finally, you add the new time entry
         * to the list of pre-existing times before saving them all back into the file. */
        var bFormatter = new BinaryFormatter();
        var levelName  = Path.GetFileName(selectedLevel);
        var filePath   = Application.persistentDataPath +
                         "/" + playerName + "_" + levelName + "_times.dat";

        using (var file = File.Open(filePath, FileMode.Create))
        {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #2
0
    public void SaveTime(decimal time)
    {
        // 3
        var times = LoadPreviousTimes();
        // 4
        var newTime =
            new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;
        newTime.time      = time;
        // 5
        var bFormatter =
            new BinaryFormatter();
        var levelName = Path.GetFileName(selectedLevel);
        var filePath  = Application.persistentDataPath +
                        "/" + playerName +
                        "_" + levelName +
                        "_times.dat"
        ;

        using (var file = File.Open(filePath, FileMode.Create)) {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #3
0
    public void SaveTime(decimal time)
    {
        // when saving time, you fetch existing times first with the LoadPrevioursTimes() method.
        var times = LoadPreviousTimes();
        // create an instance of new PlayerTImeEntry object.
        var newTime = new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;
        newTime.time      = time;
        // create a binary formatter object to do the magic serialization
        var bFormatter = new BinaryFormatter();
        var levelName  = Path.GetFileName(selectedLevel);
        var filePath   = Application.persistentDataPath + "/" + playerName + "_" + levelName + "_times.dat";

        using (var file = File.Open(filePath, FileMode.Create))
        {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #4
0
    public void SaveTime(decimal time)
    {
        //when savinf times load the previous time first
        var times = LoadPreviousTimes();
        //create a new p-layer time object
        var newTime = new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;
        newTime.time      = time;

        //create a binary formatter to serialize the player time data
        var bFormatter = new BinaryFormatter();
        var levelName  = Path.GetFileName(selectedLevel);
        var filePath   = Application.persistentDataPath + "/" + playerName + "_" + levelName + "_times.dat";

        using (var file = File.Open(filePath, FileMode.Create))
        {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: Kirucchi/Shaggy-Game
    public void SaveTime(decimal time)
    {
        //refer to note 3
        var times = LoadPreviousTimes();
        //refer to note 4
        var newTime = new PlayerTimeEntry();

        newTime.entryDate  = DateTime.Now;
        newTime.time       = time;
        newTime.PlayerName = playerName;
        newTime.Lives      = ship.GetComponent <CharacterController>().getLife();
        //refer to note 5
        var bFormatter = new BinaryFormatter();
        var filePath   = Application.persistentDataPath +
                         "/2c" + "_times.dat";

        using (var file = File.Open(filePath, FileMode.Create)) {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #6
0
ファイル: GameManager.cs プロジェクト: Keizaak/SuperSoyBoy
    public void SaveTime(decimal time)
    {
        //when saving a time, fetch existing times first
        var times = LoadPreviousTimes();

        var newTime = new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;                                                                    //save the current date
        newTime.time      = time;                                                                            //save the runtime

        var bFormatter = new BinaryFormatter();                                                              //will do the serialization
        var levelName  = Path.GetFileName(selectedLevel);
        var filePath   = Application.persistentDataPath + "/" + playerName + "_" + levelName + "_times.dat"; //creates the file path

        //opens the file (FileMode.Create = create a new file or overwrite existing files)
        using (var file = File.Open(filePath, FileMode.Create))
        {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #7
0
    public void SaveTime(decimal time)
    {
        //saving a time by fetching existing times first
        var times = LoadPreviousTimes();
        //create new instance of player time entry
        var newTime = new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;
        newTime.time      = time;
        //create a binary formatter object to do the packing of the list of player names and times
        var bFormatter = new BinaryFormatter();
        var levelName  = Path.GetFileName(selectedLevel);
        var filePath   = Application.persistentDataPath +
                         "/" + playerName + "_" + levelName + "_times.dat";

        using (var file = File.Open(filePath, FileMode.Create))
        {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }
コード例 #8
0
ファイル: GameManager.cs プロジェクト: 110108/souper-soy-boi
    public void SaveTime(decimal time)
    {
        //Load any old saved times
        var times = LoadPreviousTimes();

        //Create a new entry and update its values to be saved
        var newTime = new PlayerTimeEntry();

        newTime.entryDate = DateTime.Now;
        newTime.time      = time;

        //Save the data to the existing save file or create a new one using a binary formatter
        var bFormatter = new BinaryFormatter();
        var levelName  = Path.GetFileName(selectedLevel);
        var filePath   = Application.persistentDataPath + "/" + playerName + "_" + levelName + "_times.dat";

        using (var file = File.Open(filePath, FileMode.Create))
        {
            times.Add(newTime);
            bFormatter.Serialize(file, times);
        }
    }