Esempio n. 1
0
    /// <summary>
    /// Given two voxel pices and a side, returns if they connect by that side
    /// </summary>
    /// <param name="a">Voxel Piece to take side into account.</param>
    /// <param name="b">Voxel Piece to check if connection is possible.</param>
    /// <param name="s">Side to consider in Voxel a.</param>
    /// <returns>True if connection is possible by the given side. Otherwise, false.</returns>
    public static bool IsConnected(VoxelPiece a, VoxelPiece b, Side s)
    {
        switch (s)
        {
        case Side.back:
            return(a[(int)Side.back] == b[(int)Side.front]);

        case Side.down:
            return(a[(int)Side.down] == b[(int)Side.up]);

        case Side.front:
            return(a[(int)Side.front] == b[(int)Side.back]);

        case Side.left:
            return(a[(int)Side.left] == b[(int)Side.right]);

        case Side.right:
            return(a[(int)Side.right] == b[(int)Side.left]);

        case Side.up:
            return(a[(int)Side.up] == b[(int)Side.down]);
        }

        return(false);
    }
Esempio n. 2
0
    /// <summary>
    /// Creates the GO associated with the given map a pieces.
    /// </summary>
    /// <param name="map">Map to represent.</param>
    /// <param name="pieces">Pieces to use to build the map.</param>
    public override void CreateGO(int[,,] map, List <VoxelPiece> pieces)
    {
        Clean();

        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                for (int k = 0; k < map.GetLength(2); k++)
                {
                    if (map[i, j, k] < 1)
                    {
                        continue;
                    }

                    VoxelPiece cPiece = pieces[map[i, j, k]];
                    GameObject go     = new GameObject(i + "|" + j + "|" + k);
                    go.transform.parent                       = _rootGO;
                    go.transform.localPosition                = new Vector3(i, j, k);
                    go.transform.localEulerAngles             = cPiece.RotOfftset;
                    go.transform.localScale                   = cPiece.ScaleOffset;
                    go.AddComponent <MeshFilter>().mesh       = cPiece.Mesh;
                    go.AddComponent <MeshRenderer>().material = _dfltMat;
                }
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Creates a text visualization GO for a given map and pieces.
    /// </summary>
    public override void CreateGO(int[,,] map, List <VoxelPiece> pieces)
    {
        Clean();

        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                for (int k = 0; k < map.GetLength(2); k++)
                {
                    if (map[i, j, k] < 0)
                    {
                        continue;
                    }

                    VoxelPiece cPiece = pieces[map[i, j, k]];
                    GameObject go     = new GameObject(i + "|" + j + "|" + k);
                    go.transform.parent               = _rootGO;
                    go.transform.localPosition        = new Vector3(i, j + .5f, k);
                    go.transform.localScale           = Vector3.one * .2f;
                    go.AddComponent <TextMesh>().text = map[i, j, k].ToString();

                    // Borders visualizaion
                    for (int side = 0; side < 6; side++)
                    {
                        GameObject gos = new GameObject(i + "|" + j + "|" + k + "|Side" + side);
                        gos.transform.parent                = go.transform;
                        gos.transform.localScale            = Vector3.one * .5f;
                        gos.AddComponent <TextMesh>().text  = (pieces[map[i, j, k]][side]).ToString();
                        gos.GetComponent <TextMesh>().color = Color.red;
                        switch (side)
                        {
                        case 0:
                            gos.transform.localPosition = new Vector3(2.25f, 0, 0);
                            break;

                        case 1:
                            gos.transform.localPosition = new Vector3(0, 0, 2.25f);
                            break;

                        case 2:
                            gos.transform.localPosition = new Vector3(-2.25f, 0, 0);
                            break;

                        case 3:
                            gos.transform.localPosition = new Vector3(0, 0, -2.25f);
                            break;

                        case 4:
                            gos.transform.localPosition = new Vector3(0, 2.25f, 0);
                            break;

                        case 5:
                            gos.transform.localPosition = new Vector3(0, -2.25f, 0);
                            break;
                        }
                    }
                }
            }
        }
    }