コード例 #1
0
ファイル: TileGenerator.cs プロジェクト: giapnx/TKM-Map
    void create(Vector2i coordinate, Vector3 pos)
    {
        //StartCoroutine(CheckURLValid(coordinate, pos));
        NormalTerrainTile terrainTile = CreateNormalTerrainTile(pos, coordinate);
        int zoomLevel = int.Parse(zoomLevelIF.text);

        terrainTile.CreateMesh(zoomLevel, isUseToggle);
    }
コード例 #2
0
ファイル: TileGenerator.cs プロジェクト: giapnx/TKM-Map
    public void CheckNeighBour(Vector2i coordinate)
    {
        lock (LoadedNormalTiles)
        {
            NormalTerrainTile terrainTile;
            if (!LoadedNormalTiles.TryGetValue(coordinate, out terrainTile))
            {
                return;
            }

            NormalTerrainTile otherTerrain = null;
            Vector2i          neightbourCoor;

            //Get Terran Left
            neightbourCoor = new Vector2i(coordinate.x - 1, coordinate.y);
            NeighBoursDirection direction = NeighBoursDirection.LEFT;
            if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain))
            {
                direction = NeighBoursDirection.LEFT;
                //Create edge tile map
                EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position);
                neighbour.CreateMesh(terrainTile, direction, otherTerrain);
            }

            //Get Terran Top
            neightbourCoor = new Vector2i(coordinate.x, coordinate.y - 1);

            if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain))
            {
                direction = NeighBoursDirection.TOP;
                //Create edge tile map
                EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position);
                neighbour.CreateMesh(terrainTile, direction, otherTerrain);
            }

            //Get Terran Right
            neightbourCoor = new Vector2i(coordinate.x + 1, coordinate.y);

            if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain))
            {
                direction = NeighBoursDirection.RIGHT;
                //Create edge tile map
                EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position);
                neighbour.CreateMesh(terrainTile, direction, otherTerrain);
            }

            //Get Terran Bottom
            neightbourCoor = new Vector2i(coordinate.x, coordinate.y + 1);

            if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain))
            {
                direction = NeighBoursDirection.BOTTOM;
                //Create edge tile map
                EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position);
                neighbour.CreateMesh(terrainTile, direction, otherTerrain);
            }
        }
    }
コード例 #3
0
ファイル: TileGenerator.cs プロジェクト: giapnx/TKM-Map
 public void AddNewLoadedTerrainTile(Vector2i coordinate, NormalTerrainTile terrainTile)
 {
     lock (LoadedNormalTiles)
     {
         if (coordinate != null)
         {
             LoadedNormalTiles.Add(coordinate, terrainTile);
         }
     }
 }
コード例 #4
0
ファイル: TileGenerator.cs プロジェクト: giapnx/TKM-Map
    public NormalTerrainTile CreateNormalTerrainTile(Vector3 position, Vector2i coordinate)
    {
        GameObject aTerrain = Instantiate(tilePref, position, Quaternion.identity);

        aTerrain.transform.SetParent(transform, false);
        NormalTerrainTile terrainTile = aTerrain.AddComponent <NormalTerrainTile>();

        terrainTile.TileGenerator = this;
        terrainTile.Coordinate    = coordinate;
        terrainTile.Size          = TerrainSize;
        return(terrainTile);
    }
コード例 #5
0
ファイル: EdgeTerrainTile.cs プロジェクト: giapnx/TKM-Map
    public void CreateMesh(NormalTerrainTile thisTerrainTile, NeighBoursDirection direction, NormalTerrainTile otherTerrainTile)
    {
        int minX = 0, maxX = 0, minY = 0, maxY = 0;

        int maxIndexX = thisTerrainTile.HeightMap.GetLength(0) - 1;
        int maxIndexY = thisTerrainTile.HeightMap.GetLength(1) - 1;

        switch (direction)
        {
        case NeighBoursDirection.BOTTOM:
            minX = 0;
            maxX = maxIndexX;
            minY = maxY = 0;
            break;

        case NeighBoursDirection.LEFT:
            minX = maxX = maxIndexX;
            minY = 0;
            maxY = maxIndexY;
            break;

        case NeighBoursDirection.RIGHT:
            minX = maxX = 0;
            minY = 0;
            maxY = maxIndexY;
            break;

        case NeighBoursDirection.TOP:
            minX = 0;
            maxX = maxIndexX;
            minY = maxY = maxIndexY;
            break;

        default:
            return;
        }
        int thisX, thisY;

        Vector3[] otherVertices = null, thisVertices = null;
        Vector3[,] vertices = null;
        Vector2[] otherUVS = null, thisUVS = null;
        Vector2[,] uvs = null;
        int currentIndex = 0;

        if (maxX - minX > maxY - minY)
        {
            vertices      = new Vector3[2, maxX - minX + 1];
            uvs           = new Vector2[2, maxX - minX + 1];
            otherVertices = new Vector3[maxX - minX + 1];
            thisVertices  = new Vector3[maxX - minX + 1];
            otherUVS      = new Vector2[maxX - minX + 1];
            thisUVS       = new Vector2[maxX - minX + 1];
        }
        else
        {
            vertices      = new Vector3[2, maxY - minY + 1];
            uvs           = new Vector2[2, maxY - minY + 1];
            otherVertices = new Vector3[maxY - minY + 1];
            thisVertices  = new Vector3[maxY - minY + 1];
            thisUVS       = new Vector2[maxY - minY + 1];
            otherUVS      = new Vector2[maxY - minY + 1];
        }
        for (int otherY = minY; otherY <= maxY; ++otherY)
        {
            for (int otherX = minX; otherX <= maxX; ++otherX)
            {
                thisX = otherX;
                thisY = otherY;

                if (minX == maxX)
                {
                    thisX = maxIndexX - otherX;
                }
                if (minY == maxY)
                {
                    thisY = maxIndexY - otherY;
                }

                thisVertices[currentIndex] = thisTerrainTile.MeshData.Vertices[thisY * (maxIndexX + 1) + thisX];
                thisUVS[currentIndex]      = thisTerrainTile.MeshData.Vertices[thisY * (maxIndexX + 1) + thisX];

                otherVertices[currentIndex] = otherTerrainTile.GetRelativeVertex(thisTerrainTile.transform.position, otherY * (maxIndexX + 1) + otherX);
                otherUVS[currentIndex]      = otherTerrainTile.GetRelativeUV(thisTerrainTile.transform.position, otherY * (maxIndexX + 1) + otherX);
                ++currentIndex;
            }
        }

        for (currentIndex = 0; currentIndex < thisVertices.Length; ++currentIndex)
        {
            vertices[0, currentIndex] = thisVertices[currentIndex];
            uvs[0, currentIndex]      = thisUVS[currentIndex];
        }

        for (currentIndex = 0; currentIndex < otherVertices.Length; ++currentIndex)
        {
            vertices[1, currentIndex] = otherVertices[currentIndex];
            uvs[1, currentIndex]      = otherUVS[currentIndex];
        }

        CreateMesh(vertices, uvs, direction);
    }