コード例 #1
0
    public GameObject CreateBrickGameObject(Brick source)
    {
        GameObject brickGameobject = Instantiate(ShapePrefabs[(int)source.Shape]); // get correct shape prefab using enum index

        brickGameobject.name  = source.Name;
        brickGameobject.layer = 9;
        source.gameObject     = brickGameobject;

        // Set up for BrickGO
        BrickGO bg = brickGameobject.GetComponent <BrickGO>();

        bg.brick       = source;
        source.brickGO = bg;

        // Set up the BrickShape
        BrickShape bs = brickGameobject.GetComponent <BrickShape>();

        source.brickShape = bs;

        // Set transform info
        brickGameobject.transform.position    = source.Position;
        brickGameobject.transform.eulerAngles = new Vector3(0, source.Rotation, 0);

        // Set Material
        for (int i = 0; i < bs.elements.Length; i++)
        {
            MeshFilter mf = bs.elements[i].GetComponent <MeshFilter>();
            if (mf == null)
            {
                continue;             // skip iteration, this element doesn't have a mesh
            }
            int          submeshCount   = mf.mesh.subMeshCount;
            MeshRenderer renderer       = bs.elements[i].GetComponent <MeshRenderer>();
            Material[]   brickMaterials = new Material[submeshCount];
            brickMaterials[0] = MaterialCache.instance.GetMaterial((source.BrickColor, source.Transparency, MaterialCache.FaceType.Smooth, Vector2.one, BrickShader));
            if (submeshCount > 1)
            {
                if (source.Shape == Brick.ShapeType.spawnpoint)
                {
                    brickMaterials[1] = MaterialCache.instance.GetMaterial((source.BrickColor, source.Transparency, MaterialCache.FaceType.Spawnpoint, new Vector2(source.Scale.x, source.Scale.z), BrickShader));
                }
                else
                {
                    brickMaterials[1] = MaterialCache.instance.GetMaterial((source.BrickColor, source.Transparency, MaterialCache.FaceType.Stud, new Vector2(source.Scale.x, source.Scale.z), BrickShader));
                }
            }
            if (submeshCount > 2)
            {
                brickMaterials[2] = MaterialCache.instance.GetMaterial((source.BrickColor, source.Transparency, MaterialCache.FaceType.Inlet, new Vector2(source.Scale.x, source.Scale.z), BrickShader));
            }
            renderer.materials = brickMaterials;
        }

        bs.UpdateShape();     // updates the shape
        source.UpdateModel(); // sets the model

        return(brickGameobject);
    }
コード例 #2
0
 // call this when scale is changed
 public void UpdateShape()
 {
     brickShape.UpdateShape();
 }