Exemplo n.º 1
0
    public void LoadGame()
    {
        byte[] bytes = null;
        string path  = Application.persistentDataPath + SAVE_FILE_NAME;

        if (File.Exists(path))
        {
            bytes = File.ReadAllBytes(path);
        }
        else
        {
            string    fileNameWithoutExtension = Path.GetFileNameWithoutExtension(SAVE_FILE_RES_NAME);
            TextAsset saveAsset = Resources.Load(fileNameWithoutExtension) as TextAsset;
            if (saveAsset != null)
            {
                bytes = saveAsset.bytes;
            }
        }

        if (bytes == null)
        {
            return;
        }

        var reader       = new BinaryReader(bytes, 0);
        var initPosition = reader.ReadVector3();
        var yaw          = reader.ReadFloat();
        var cameraPitch  = reader.ReadFloat();

        WorldModel.Deserialize(reader);

        LoadedGame = new LoadedGame(initPosition, yaw, cameraPitch);
    }