Exemplo n.º 1
0
    public void RemoveHex()
    {
        if (AimHex.isHexAimedAt)
        {
            HexChunk   hc = GetChunkWithHexCoords(AimHex.hexAimedAt);
            Vector3Int v  = HexCoordsWithinChunk(AimHex.hexAimedAt);

            hc.SetBlocks(v.x, v.y, v.z, 0);
            hc.ReCreateMeshes();
        }
    }
Exemplo n.º 2
0
    public void AddHex()
    {
        bool isHexAimedAt = AimHex.isHexAimedAt;

        int dir = 0;

        if (isHexAimedAt)
        {
            Vector3 hexAimedAt = AimHex.hexAimedAt;
            Vector3 aimNormal  = AimHex.aimNormal;

            if (aimNormal.y == 0)
            {
                if (aimNormal.x > 0 && aimNormal.z > 0)
                {
                    dir = 1;
                }
                if (aimNormal.x > 0 && aimNormal.z == 0)
                {
                    dir = 2;
                }
                if (aimNormal.x > 0 && aimNormal.z < 0)
                {
                    dir = 3;
                }
                if (aimNormal.x < 0 && aimNormal.z < 0)
                {
                    dir = 4;
                }
                if (aimNormal.x < 0 && aimNormal.z == 0)
                {
                    dir = 5;
                }
                if (aimNormal.x < 0 && aimNormal.z > 0)
                {
                    dir = 6;
                }
            }
            else if (aimNormal.y > 0)
            {
                dir = 7;
            }
            else if (aimNormal.y < 0)
            {
                dir = 8;
            }

            Vector3 hexToAdd = hexAimedAt;

            if (hexAimedAt.z % 2 == 0)
            {
                switch (dir)
                {
                case 1:
                    hexToAdd = hexAimedAt + new Vector3(0, 0, 1);
                    break;

                case 2:
                    hexToAdd = hexAimedAt + new Vector3(1, 0, 0);
                    break;

                case 3:
                    hexToAdd = hexAimedAt + new Vector3(0, 0, -1);
                    break;

                case 4:
                    hexToAdd = hexAimedAt + new Vector3(-1, 0, -1);
                    break;

                case 5:
                    hexToAdd = hexAimedAt + new Vector3(-1, 0, 0);
                    break;

                case 6:
                    hexToAdd = hexAimedAt + new Vector3(-1, 0, 1);
                    break;

                case 7:
                    hexToAdd = hexAimedAt + new Vector3(0, 1, 0);
                    break;

                case 8:
                    hexToAdd = hexAimedAt + new Vector3(0, -1, 0);
                    break;
                }
            }
            else
            {
                switch (dir)
                {
                case 1:
                    hexToAdd = hexAimedAt + new Vector3(1, 0, 1);
                    break;

                case 2:
                    hexToAdd = hexAimedAt + new Vector3(1, 0, 0);
                    break;

                case 3:
                    hexToAdd = hexAimedAt + new Vector3(1, 0, -1);
                    break;

                case 4:
                    hexToAdd = hexAimedAt + new Vector3(0, 0, -1);
                    break;

                case 5:
                    hexToAdd = hexAimedAt + new Vector3(-1, 0, 0);
                    break;

                case 6:
                    hexToAdd = hexAimedAt + new Vector3(0, 0, 1);
                    break;

                case 7:
                    hexToAdd = hexAimedAt + new Vector3(0, 1, 0);
                    break;

                case 8:
                    hexToAdd = hexAimedAt + new Vector3(0, -1, 0);
                    break;
                }
            }

            HexChunk   hc = GetChunkWithHexCoords(hexToAdd);
            Vector3Int v  = HexCoordsWithinChunk(hexToAdd);

            hc.SetBlocks(v.x, v.y, v.z, current);
            hc.ReCreateMeshes();
        }
    }