Exemplo n.º 1
0
    void RefreshPreview()
    {
        if (preview != null)
        {
            Destroy(preview.gameObject);
        }

        if (editBlocks)
        {
            Transform t = Instantiate(biomeManager.GetBlockShape(shapes[currentShape]), transform);
            previewOffset = t.localPosition;
            t.position    = t.localPosition * Biome.BlockSize;
            t.localScale *= Biome.BlockSize;
            BlockController newBlock = t.gameObject.AddComponent <BlockController>().SetRotation(Vector3.up * currentRotation);
            if (currentType != -1)
            {
                Material     mat = biomeManager.GetBlockMaterial(types[currentType]);
                MeshRenderer mr  = newBlock.GetComponent <MeshRenderer>();
                if (mr == null)
                {
                    foreach (MeshRenderer mrchild in newBlock.GetComponentsInChildren <MeshRenderer>())
                    {
                        if (mrchild != null)
                        {
                            mrchild.material = mat;
                        }
                    }
                }
                else
                {
                    mr.material = mat;
                }
            }
            PreparePreview(newBlock.transform);
            preview = newBlock.transform;
        }
        else
        {
            ItemController newItem = Instantiate(itemManager.Items[items[currentType]], transform);
            if (newItem.GetComponent <Renderer>() != null)
            {
                previewOffset = newItem.GetComponent <Renderer>().bounds.size.y / 2 * Vector3.up;
            }
            else
            {
                previewOffset = Vector3.zero;
            }
            Destroy(newItem.GetComponent <Rigidbody>());
            PreparePreview(newItem.transform);
            preview = newItem.transform;
        }
        MovePreview();
    }
Exemplo n.º 2
0
    public BlockController SetBlock(Vector3Int pos, BlockShape shape)
    {
        if (!CheckCoords(pos))
        {
            return(null);
        }
        blockCount++;

        BlockController existingBlock = GetBlock(pos);

        if (existingBlock != null)
        {
            Destroy(existingBlock.gameObject);
        }

        Transform t = Instantiate(Manager.GetBlockShape(shape), transform);

        t.name          = String.Format("{0}-{1}-{2}", pos.x, pos.y, pos.z);
        t.localPosition = (t.localPosition + pos) * Biome.BlockSize;
        t.localScale   *= Biome.BlockSize;

        return(t.gameObject.AddComponent <BlockController>().SetBiomeCoords(pos).SetShape(shape).SetType(BlockType.Missing));
    }