コード例 #1
0
ファイル: Hex.cs プロジェクト: Papiertig0r/Hexominos
    public bool CheckNeighbors()
    {
        int     isPopulated  = 0;
        int     isValid      = 0;
        Vector3 cubePosition = HexMath.AxialToCube(HexMath.PixelToHex(transform.position));

        RaycastHit hit;
        int        direction;

        for (int i = 0; i < 6; i++)
        {
            if (Physics.Raycast(HexMath.HexToPixel(HexMath.CubeToAxial(cubePosition + HexMath.direction[i])) + Vector3.forward, Vector3.back, out hit))
            {
                Hex hex = hit.collider.GetComponent <Hex>();
                if (hex != null)
                {
                    isPopulated++;

                    direction = i + 3;
                    if (direction > 5)
                    {
                        direction -= 6;
                    }

                    if (hex.CheckValidity(direction, fieldType[i]))
                    {
                        isValid++;
                    }
                }
            }
        }

        return((isPopulated != 0) && (isPopulated == isValid));
    }