Esempio n. 1
0
    public BlockController SetBlock(Vector3Int pos, BlockShape shape, BlockType material)
    {
        BlockController block = SetBlock(pos, shape);

        if (block == null)
        {
            return(null);
        }
        block.SetType(material);
        Material     mat = Manager.GetBlockMaterial(material);
        MeshRenderer mr  = block.GetComponent <MeshRenderer>();

        if (mr == null)
        {
            foreach (MeshRenderer mrchild in block.GetComponentsInChildren <MeshRenderer>())
            {
                if (mrchild != null)
                {
                    mrchild.material = mat;
                }
            }
        }
        else
        {
            mr.material = mat;
        }
        return(block);
    }
Esempio n. 2
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();
    }