예제 #1
0
    public override void DoLoad(int _version, BinaryReader _stream)
    {
        //Clear Existing Chunks
        foreach (WorldChunk chunk in worldChunks)
        {
            for (int x = 0; x < chunk.gridData.GetLength(0); x++)
            {
                for (int y = 0; y < chunk.gridData.GetLength(1); y++)
                {
                    for (int z = 0; z < chunk.gridData.GetLength(2); z++)
                    {
                        if (chunk.gridObjects[x, y, z] != null)
                        {
                            Destroy(chunk.gridObjects[x, y, z]);
                        }
                    }
                }
            }
        }

        worldChunks = new List <WorldChunk>();

        //Get Components
        PlayerMovement playerMovement = player.GetComponent <PlayerMovement>();
        CameraSwap     cameraSwap     = GetComponent <CameraSwap>();

        //Load Player Stats
        Vector3 playerPosition = SaveDataManager.LoadVector3(_stream);

        player.transform.position = playerPosition;

        Vector3 playerRotation = SaveDataManager.LoadVector3(_stream);

        player.transform.rotation = Quaternion.Euler(playerRotation);

        Vector3 lastDirection  = SaveDataManager.LoadVector3(_stream);
        Vector3 pointDirection = SaveDataManager.LoadVector3(_stream);
        Vector3 lastCameraQuat = SaveDataManager.LoadVector3(_stream);
        float   expectedSpeed  = _stream.ReadSingle();

        playerMovement.GetFromLoad(lastDirection, pointDirection, expectedSpeed, lastCameraQuat);

        //Load Camera Stats
        cameraSwap.SetCameraState(_stream.ReadBoolean());
        cameraSwap.SetInvertHorizontal(_stream.ReadBoolean());
        cameraSwap.SetInvertVertical(_stream.ReadBoolean());

        //Load World Chunks
        int worldChunkCount = _stream.ReadInt32();

        for (int i = 0; i < worldChunkCount; i++)
        {
            worldChunks.Add(new WorldChunk(i, SaveDataManager.LoadVector3(_stream)));

            WorldChunk chunk = worldChunks[worldChunks.Count - 1];

            //Load the Data
            for (int x = 0; x < chunk.gridData.GetLength(0); x++)
            {
                for (int y = 0; y < chunk.gridData.GetLength(1); y++)
                {
                    for (int z = 0; z < chunk.gridData.GetLength(2); z++)
                    {
                        int   _id       = _stream.ReadInt32();
                        float _rotation = _stream.ReadSingle();

                        //-1 is used to fill space for big items, 0 is empty, >0 is an item
                        if (_id > 0)
                        {
                            chunk.gridData[x, y, z]           = _id;
                            chunk.gridRotationAngles[x, y, z] = _rotation;
                        }
                    }
                }
            }
        }

        StartCoroutine(DoAnimatedLoad(playerMovement));
    }