Ejemplo n.º 1
0
    private void CalcEdgeHexes(int checkDistance)
    {
        Hex        hex;
        RaycastHit hit;

        for (int x = 0; x < gridX; x++)
        {
            for (int z = 0; z < gridZ; z++)
            {
                hex = GetHex(x, z);
                if (hex != null)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        int ind = i;
                        if (z % 2 == 0)
                        {
                            ind += 6;
                        }
                        if (GetHex(x + MyMath.hexOffSetGrid[ind].x, z + MyMath.hexOffSetGrid[ind].z) == null)
                        {
                            hex.edge = EdgeType.inner;
                            if (!edgeHexes.Contains(new Vector2Int(x, z)))
                            {
                                edgeHexes.Add(new Vector2Int(x, z));
                            }
                            Vector3 cubePos    = ConvertToCubicPosition(new Vector2Int(x, z));
                            Vector3 cubeTarget = cubePos + (MyMath.cubeHexDirections[i] * checkDistance);

                            List <Vector2Int> hexes = TerrainGen.GetHexesInLine(cubePos, cubeTarget);

                            if (hexes != null && hexes.Count > 0)
                            {
                                hexes.RemoveAt(0);
                                if (hexes.Count > 0)
                                {
                                    bool hasHex = false;
                                    foreach (Vector2Int hexPos in hexes)
                                    {
                                        if (TerrainGen.GetHex(hexPos.x, hexPos.y) != null)
                                        {
                                            hasHex = true;
                                        }
                                    }
                                    if (!hasHex)
                                    {
                                        hex.edge = EdgeType.outter;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }