Esempio n. 1
0
    private void AddBlock(RaycastHit hit, Chunk hitc)
    {
        Vector3 hitPos = hit.point + hit.normal * StaticWorld.K / 2.0f;

        Position hitBlock = (Position)Round(hitPos / StaticWorld.K) - hitc.Position;

        Block block = StaticWorld.GetWorldBlock(hitBlock + hitc.Position);


        if (block?.Type == BlockType.AIR)
        {
            Debug.Log($"ADD Chunk {hitc.Position} Block {hitBlock} OLD {block.Type} NEW {this.blockType}");
            StaticWorld.Instance.StartCoroutine(hitc.AddBlock(block, this.blockType));
        }
        else
        {
            Debug.Log("Can not add block here");
        }
    }
Esempio n. 2
0
    private IEnumerator UpdateBlock(Block block, BlockType blockType)
    {
        block.SetType(blockType);

        block.Draw();

        foreach (Position vector3 in SideDirectionVectors)
        {
            Position globalPos = vector3 + block.GlobalPosition;

            if (this.IsInChunk(globalPos))
            {
                Position localPos = globalPos - this.Position;

                this.ChunkData[localPos].Draw();
            }
            else
            {
                Block b = StaticWorld.GetWorldBlock(globalPos);
                if (b != null)
                {
                    b.Draw();

                    // todo do not update for all blocks
                    b.Chunk.ReMeshFilter();
                }
                else
                {
                    Debug.Log("No such block to draw");
                }
            }
        }

        this.ReMeshFilter();

        yield return(null);
    }