コード例 #1
0
    void Start()
    {
        mover           = new PhysicsMover();
        mover.transform = transform;

        float s = 0.35f;
        // .7 wide 1.4 tall
        // so 2 blocks wide, 3 tall
        AABB shape;

        shape.minX  = -s;
        shape.minZ  = -s;
        shape.maxX  = s;
        shape.maxZ  = s;
        shape.minY  = -1.0f;
        shape.maxY  = 0.4f;
        mover.shape = shape;

        BlonkPhysics.AddMover(mover);

        ToggleFlyMode();
    }
コード例 #2
0
    void Update()
    {
        // scroll to select blocks (create mesh as you switch)
        float scroll  = Input.GetAxis("Mouse ScrollWheel");
        bool  changed = true;

        if (scroll > 0.0f)
        {
            blockIndex--;
        }
        else if (scroll < 0.0f)     // scroll down will progress list forward
        {
            blockIndex++;
        }
        else
        {
            changed = false;
        }
        blockIndex = Mth.Mod(blockIndex, blocks.Length);
        if (changed)
        {
            MeshBuilder.GetBlockMesh(blocks[blockIndex], blockMeshFilter);
        }

        // show square around block aiming at
        // todo: have option to show 2x2 for hammering!
        //bool mainRaycast = Physics.Raycast(transform.position, transform.forward, out hit, 1000);
        drawer.Clear();

        RaycastVoxelHit vhit;
        bool            success = BlonkPhysics.RaycastVoxel(world, transform.position, transform.forward, out vhit);

        if (success)
        {
            // move cube towards camera direction a little so it looks better when intersecting with other blocks
            Vector3 center = (vhit.bpos.ToVector3() + Vector3.one * placementSize * 0.5f) / Chunk.BPU;
            drawer.AddBounds(new Bounds(center - transform.forward * 0.01f, Vector3.one * placementSize / Chunk.BPU), Color.white);
        }

        // left click delete
        if (Input.GetMouseButtonDown(0) && success)
        {
            lastPos = transform.position;
            lastHit = vhit;

            //todo: add some better directional intuitions on where to place edit shape
            for (int y = 0; y < placementSize; ++y)
            {
                for (int z = 0; z < placementSize; ++z)
                {
                    for (int x = 0; x < placementSize; ++x)
                    {
                        world.SetBlock(vhit.bpos + new Vector3i(x, y, z), Blocks.AIR);
                    }
                }
            }
        }

        // right click place
        if (Input.GetMouseButtonDown(1) && success)
        {
            lastPos = transform.position;
            lastHit = vhit;

            for (int y = 0; y < placementSize; ++y)
            {
                for (int z = 0; z < placementSize; ++z)
                {
                    for (int x = 0; x < placementSize; ++x)
                    {
                        world.SetBlock(vhit.bpos + Dirs.GetNormal(vhit.dir) + new Vector3i(x, y, z), blocks[blockIndex]);
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            placementSize++;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            placementSize--;
        }
        if (placementSize < 1)
        {
            placementSize = 1;
        }

        if (Input.GetKeyDown(KeyCode.F1))
        {
            flyCam.ToggleFlyMode();
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            drawChunkBorders = !drawChunkBorders;
        }
        if (Input.GetKeyDown(KeyCode.F3))
        {
            ToggleDebugDay();
        }
        if (Input.GetKeyDown(KeyCode.F4))
        {
            LoadChunks.drawDebug = !LoadChunks.drawDebug;
        }
        if (Input.GetKeyDown(KeyCode.F5))
        {
            LoadChunks.updateChunks = !LoadChunks.updateChunks;
        }
        if (drawChunkBorders)
        {
            DrawChunkBorders();
        }
    }