Exemple #1
0
    // Start is called before the first frame update
    public void /*Fire emblem */ Initialize/*ning*/ ()
    {
        tilemapReal       = transform.Find("TilemapReal").gameObject.GetComponent <Tilemap>();
        tilemapReal.color = Color.clear;
        boundsFloor       = tilemapReal.cellBounds;
        TileBase[] tilesWorld = tilemapReal.GetTilesBlock(boundsFloor);
        Debug.Log(boundsFloor);


        mapTiles = new MapTile[boundsFloor.size.x / 2, boundsFloor.size.y / 2];
        for (int x = 0; x < boundsFloor.size.x / 2; x++)
        {
            for (int y = 0; y < boundsFloor.size.y / 2; y++)
            {
                mapTiles[x, y]      = new MapTile();
                mapTiles[x, y].tile = parseMapTile(tilesWorld[(y * boundsFloor.size.x + x) * 2]?.name);
            }
        }

        debugTiles  = transform.Find("TilemapDebug").GetComponent <DebugTiles>();
        pathfinding = GetComponent <Pathfinding>();
        int xMin = mapTiles.GetLength(0);
        int yMin = mapTiles.GetLength(0);
        int xMax = -1;
        int yMax = -1;

        for (int x = 0; x < mapTiles.GetLength(0); x++)
        {
            for (int y = 0; y < mapTiles.GetLength(1); y++)
            {
                if (mapTiles[x, y].tile != TileType.NULL)
                {
                    xMin = Math.Min(xMin, x);
                    yMin = Math.Min(yMin, y);
                    xMax = Math.Max(xMax, x);
                    yMax = Math.Max(yMax, y);
                }
            }
        }
        xMax          += 1;
        yMax          += 1;
        mapBounds.xMax = xMax;
        mapBounds.xMin = xMin;
        mapBounds.yMax = yMax;
        mapBounds.yMin = yMin;
    }