コード例 #1
0
    public bool Apply(VoxelStencil stencil)
    {
        var xStart = stencil.XStart;

        if (xStart < 0)
        {
            xStart = 0;
        }

        var xEnd = stencil.XEnd;

        if (xEnd >= resolution)
        {
            xEnd = resolution - 1;
        }

        var yStart = stencil.YStart;

        if (yStart < 0)
        {
            yStart = 0;
        }

        var yEnd = stencil.YEnd;

        if (yEnd >= resolution)
        {
            yEnd = resolution - 1;
        }

        var didUpdate = false;

        for (var y = yStart; y <= yEnd; y++)
        {
            var i = VoxelIndexFromLocalPos(xStart, y);
            for (var x = xStart; x <= xEnd; x++, i++)
            {
                if (voxels[i].state != stencil.fillType)
                {
                    // Deleting
                    if (stencil.fillType == 0)
                    {
                        var deletingBlock = blockCollection.blocks[voxels[i].state];
                        var tempState     = stencil.Apply(x, y, voxels[i].state);

                        if (tempState == stencil.fillType)
                        {
                            voxels[i].state = tempState;

                            var itemType = deletingBlock.itemType;
                            var amount   = deletingBlock.amount;
                            var item     = new Item {
                                itemType = itemType, amount = amount
                            };

                            var worldMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                            WorldItem.SpawnWorldItem(new Vector2(worldMousePos.x, worldMousePos.y), item);
                            didUpdate = true;
                        }
                    }
                    // Placing
                    if (stencil.fillType != 0 && voxels[i].state == 0)
                    {
                        var placingItemType = BlockManager.Read().blocks[stencil.fillType].itemType;
                        voxels[i].state = stencil.Apply(x, y, voxels[i].state);

                        uiHotBar.Place();

                        didUpdate = true;
                    }
                }
            }
        }

        Refresh();
        if (didUpdate)
        {
            shouldUpdateCollider = true;
        }

        return(didUpdate);
    }
コード例 #2
0
 private void Start()
 {
     WorldItem.SpawnWorldItem(transform.position, item);
     Destroy(gameObject);
 }