Example #1
0
    public Mesh GenerateFloorMesh(VesselChunk t, VesselChunk l, VesselChunk r, VesselChunk b, VesselChunk br)
    {
        List<Vector3> vertices = new List<Vector3>();
        List<Vector2> uv = new List<Vector2>();
        List<int> indices = new List<int>();

        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++) {

                VesselTile tile = TileAt(i, j);

                if (tile != null) {

                    if (tile.floor0 != FloorType.None || tile.floor1 != FloorType.None) {

                        Vector3 offset = new Vector3(i, j, 0.0f);

                        //VesselTile tTile = (j == SIZE-1) ? (t != null) ? t.TileAt(i,0) : null : TileAt(i,j+1);
                        VesselTile lTile = (i == 0) ? (l != null) ? l.TileAt(SIZE-1,j) : null : TileAt(i-1,j);
                        VesselTile rTile = (i == SIZE-1) ? (r != null) ? r.TileAt(0,j) : null : TileAt(i+1,j);
                        VesselTile r2Tile = (i >= SIZE-2) ? (r != null) ? r.TileAt(i-(SIZE-2),j) : null : TileAt(i+2,j);
                        VesselTile bTile = (j == 0) ? (b != null) ? b.TileAt(i,SIZE-1) : null : TileAt(i,j-1);
                        VesselTile brTile = null;
                        if (j == 0) {
                            if (i < SIZE-1) {
                                brTile = (b != null) ? b.TileAt(i+1,SIZE-1) : null;
                            } else {
                                brTile = (br != null) ? br.TileAt(0,SIZE-1) : null;
                            }
                        } else {
                            if (i != SIZE-1) {
                                brTile = TileAt(i+1,j-1);
                            } else {
                                brTile = (r != null) ? r.TileAt(0,j-1) : null;
                            }
                        }

                        if (tile.floor0 == tile.floor1) {
                            Sprites.AppendMeshData(Sprites.FloorMeshes[(byte)tile.floor0][(byte)FloorType.None][(byte)WallType.None][0],vertices,uv,indices,offset);
                        } else {
                            FloorMesh[][] floorCombMeshes = Sprites.FloorMeshes[(byte)tile.floor0][(byte)tile.floor1];

                            if (tile.Contains(WallTypeMask.TwoByOne)) { //this tile contains a TwoByOne
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.TwoByOne][0],vertices,uv,indices,offset);
                            } else if (tile.Contains(WallTypeMask.OneByTwo)) { //this tile contains a OneByTwo
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.OneByTwo][0],vertices,uv,indices,offset);
                            } else if (tile.Contains(WallTypeMask.OneByOne)) { //this tile contains a OneByOne
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.OneByOne][0],vertices,uv,indices,offset);
                            }
                            else if (lTile != null && lTile.Contains(WallTypeMask.TwoByOne)) { //left tile contains a TwoByOne
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.TwoByOne][1],vertices,uv,indices,offset);
                            } else if (bTile != null && bTile.Contains(WallTypeMask.OneByTwo)) { //bottom tile contains a OneByTwo
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.OneByTwo][1],vertices,uv,indices,offset);
                            } else if (brTile != null && brTile.Contains(WallTypeMask.OneByTwoFlipped)) { //br tile contains a OneByTwoFlipped
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.OneByTwoFlipped][1],vertices,uv,indices,offset);
                            } else if (rTile != null && rTile.Contains(WallTypeMask.TwoByOneFlipped)) { //r tile contains a TwoByOneFlipped
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.TwoByOneFlipped][0],vertices,uv,indices,offset);
                            } else if (rTile != null && rTile.Contains(WallTypeMask.OneByOneFlipped)) { //r tile contains a OneByOneFlipped
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.OneByOneFlipped][0],vertices,uv,indices,offset);
                            } else if (rTile != null && rTile.Contains(WallTypeMask.OneByTwoFlipped)) { //r tile contains a OneByTwoFlipped
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.OneByTwoFlipped][0],vertices,uv,indices,offset);
                            } else if (r2Tile != null && r2Tile.Contains(WallTypeMask.TwoByOneFlipped)) { //r2 tile contains a TwoByOneFlipped
                                Sprites.AppendMeshData(floorCombMeshes[(byte)WallType.TwoByOneFlipped][1],vertices,uv,indices,offset);
                            } else {
                                //no walls cut this tile
                                Sprites.AppendMeshData(Sprites.FloorMeshes[(byte)tile.floor0][(byte)FloorType.None][(byte)WallType.None][0],vertices,uv,indices,offset);
                            }
                        }
                    }
                }
            }
        }

        Mesh output = new Mesh();

        output.vertices = vertices.ToArray();
        output.uv = uv.ToArray();
        output.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0);

        return output;
    }
Example #2
0
    public virtual void Instantiate(VesselChunk t, VesselChunk l, VesselChunk r, VesselChunk b, VesselChunk br, Vector2 position)
    {
        instance = GameObject.Instantiate(GameManager.Instance.chunkPrefab, (Vector3)position, Quaternion.identity) as GameObject;
        instance.name = "Chunk" + Index.ToString();

        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++) {

                VesselTile tile = TileAt(i,j);

                if (tile != null && tile.wallNode) {

                    Vector2 offset = TileIToOffset(new Vec2i(i,j));

                    GameObject tileGO;

                    tileGO = GameObject.Instantiate(GameManager.Instance.wallNodePrefab, (Vector3)offset, Quaternion.identity) as GameObject;

                    tileGO.name = "Tile" + new Vec2i(i,j).ToString();
                    tileGO.transform.SetParent(instance.transform, false);

                    WallType wall0;
                    WallType wall1;
                    int wallCount = tile.GetWalls(out wall0, out wall1);

                    if (wallCount > 0) {
                        GameObject wall0GO = VesselTile.GetWall(wall0);
                        wall0GO.transform.SetParent(tileGO.transform, false);
                        if (wallCount > 1) {
                            GameObject wall1GO = VesselTile.GetWall(wall1);
                            wall1GO.transform.SetParent(tileGO.transform, false);
                        }
                    }
                }
            }
        }
    }
Example #3
0
    public override void Instantiate(VesselChunk t, VesselChunk l, VesselChunk r, VesselChunk b, VesselChunk br, Vector2 position)
    {
        base.Instantiate(t, l, r, b, br, position);

        MeshFilter mf = instance.GetComponent<MeshFilter>();
        mf.mesh = GenerateFloorMesh(t, l, r, b, br);

        instance.transform.position = (Vector3)position;
    }
Example #4
0
 protected void InstantiateChunk(VesselChunk chunk)
 {
     Vector2 chunkOffset = ChunkIToLocal(chunk.Index);
     chunk.Instantiate(
         Top(chunk),
         Left(chunk),
         Right(chunk),
         Bottom(chunk),
         BottomRight(chunk),
         chunkOffset + interiorPosition);
 }
Example #5
0
 public VesselChunk TopRight(VesselChunk chunk)
 {
     return chunks.TryGet(chunk.Index.x+1, chunk.Index.y+1);
 }
Example #6
0
 public VesselChunk TopLeft(VesselChunk chunk)
 {
     return chunks.TryGet(chunk.Index.x-1, chunk.Index.y+1);
 }
Example #7
0
 public VesselChunk BottomRight(VesselChunk chunk)
 {
     return chunks.TryGet(chunk.Index.x+1, chunk.Index.y-1);
 }
Example #8
0
 public VesselChunk BottomLeft(VesselChunk chunk)
 {
     return chunks.TryGet(chunk.Index.x-1, chunk.Index.y-1);
 }