示例#1
0
    int CalcCost(PathType type, Vector2Int pos, Vector2Int destination)
    {
        int   cost = 0;
        float heightDif;
        Hex   posHex  = TerrainGen.GetHex(pos.x, pos.y);
        Hex   destHex = TerrainGen.GetHex(destination.x, destination.y);

        if (type != PathType.flight)
        {
            if (posHex != null && destHex != null)
            {
                heightDif  = posHex.height - destHex.height;
                heightDif /= TerrainGen.hexSize / 2;
                if (heightDif > 0)
                {
                    cost += Mathf.RoundToInt(heightDif);
                }
                cost += destHex.cost;
            }
            else
            {
                cost += 10000;
            }
        }

        return(cost);
    }
示例#2
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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
示例#3
0
    private void CombineMeshes(int xSize, int ySize)
    {
        List <Mesh> blockMeshes = new List <Mesh>();
        GameObject  newBlock;

        CombineInstance[] combine;
        for (int xBlock = 0; xBlock < TerrainGen.gridX; xBlock += xSize)
        {
            for (int yBlock = 0; yBlock < gridZ; yBlock += ySize)
            {
                blockMeshes = new List <Mesh>();
                for (int x = 0; x < xSize; x++)
                {
                    for (int y = 0; y < ySize; y++)
                    {
                        Hex hex = TerrainGen.GetHex(xBlock + x, yBlock + y);
                        if (hex != null)
                        {
                            blockMeshes.Add(hex.mesh);
                        }
                    }
                }
                if (blockMeshes.Count > 0)
                {
                    newBlock      = Instantiate(blockFab, blocks.transform);
                    newBlock.name = "Block: " + xBlock + " , " + yBlock;
                    combine       = new CombineInstance[blockMeshes.Count];
                    int i = 0;
                    foreach (Mesh mesh in blockMeshes)
                    {
                        combine[i].mesh      = mesh;
                        combine[i].transform = newBlock.transform.localToWorldMatrix;
                        i++;
                        //
                    }
                    newBlock.GetComponent <MeshFilter>().mesh = new Mesh();
                    newBlock.GetComponent <MeshFilter>().mesh.CombineMeshes(combine, true);
                    newBlock.GetComponent <MeshCollider>().sharedMesh = newBlock.GetComponent <MeshFilter>().mesh;
                    newBlock.SetActive(true);
                }
            }
        }
    }
示例#4
0
    public void SpawnFromOrb(SpawnOrb orb, float spawnPoints)
    {
        Vector2Int        hex   = TerrainGen.GetGridPosition2D(orb.transform.position);
        List <Vector2Int> hexes = TerrainGen.GetHexInRange(hex, 3);

        string mobType = Mobs.instance.getRandomMob();

        mobType = "slime";
        while (spawnPoints > 0)
        {
            hex = hexes[Random.Range(0, hexes.Count)];
            while (TerrainGen.GetHex(hex.x, hex.y) == null)
            {
                hex = hexes[Random.Range(0, hexes.Count)];
            }
            SpawnMob(ref spawnPoints, hex, mobType);
        }

        KillOrb(orb);
    }