Ejemplo n.º 1
0
        private void DrawChunkAndBlock(Vector2 worldPosition)
        {
            const float yOffset = 0.01f;

            if (IsMapMode())
            {
                var   chunkPos = Chunk.GetPosition(worldPosition);
                Chunk chunk;
                if (_main.Map.Map.TryGetValue(chunkPos, out chunk))
                {
                    //Draw chunk bounds
                    var chunkBounds = (Bounds)Chunk.GetBounds(chunkPos);

                    var r1 = new Vector3(chunkBounds.min.x, chunk.HeightMap[0, 0] + yOffset, chunkBounds.min.z);
                    var r2 = new Vector3(chunkBounds.max.x, chunk.HeightMap[chunk.GridSize - 1, 0] + yOffset, chunkBounds.min.z);
                    var r3 = new Vector3(chunkBounds.min.x, chunk.HeightMap[0, chunk.GridSize - 1] + yOffset, chunkBounds.max.z);
                    var r4 = new Vector3(chunkBounds.max.x, chunk.HeightMap[chunk.GridSize - 1, chunk.GridSize - 1] + yOffset,
                                         chunkBounds.max.z);

                    DrawPolyline.ForGizmo(GetChunkPolyBound(chunk, yOffset), Color.red);

                    //Draw block bounds
                    var blockPos = (Vector2i)worldPosition;
                    var localPos = Chunk.GetLocalPosition(worldPosition);
                    r1 = new Vector3(blockPos.X, chunk.HeightMap[localPos.X, localPos.Z] + yOffset, blockPos.Z);
                    r2 = new Vector3(blockPos.X + 1, chunk.HeightMap[localPos.X + 1, localPos.Z] + yOffset, blockPos.Z);
                    r3 = new Vector3(blockPos.X, chunk.HeightMap[localPos.X, localPos.Z + 1] + yOffset, blockPos.Z + 1);
                    r4 = new Vector3(blockPos.X + 1, chunk.HeightMap[localPos.X + 1, localPos.Z + 1] + yOffset, blockPos.Z + 1);

                    DrawRectangle.ForDebug(r1, r2, r4, r3, Color.red);

                    //Draw block normal
                    var n1          = chunk.NormalMap[localPos.X, localPos.Z];
                    var blockCenter = (r1 + r2 + r3 + r4) / 4;
                    DrawArrow.ForDebug(blockCenter, n1, Color.red);
                }
            }
            else                //Layout mode
            {
                //Draw chunk bounds
                var chunkPos    = Chunk.GetPosition(worldPosition);
                var chunkBounds = Chunk.GetBounds(chunkPos);
                DrawRectangle.ForGizmo(chunkBounds, Color.red);

                //Draw block bounds
                DrawRectangle.ForGizmo(new Bounds2i((Vector2i)worldPosition, 1, 1), Color.red);
            }
        }