void MakeTileMap() { if (tilePrefab == null) { Debug.LogError("failed to MakeTileMap. null tilePrefab."); return; } // clear curTileMap = null; ClearAboutPathTest(); // new root gameobject const string tileMapRootGameObjectName = "_TileMapRoot"; GameObject tileMapRootGameObj = new GameObject(tileMapRootGameObjectName); tileMapRootGameObj.transform.position = Vector3.zero; TileMapRoot tileMapRootCompo = tileMapRootGameObj.AddComponent <TileMapRoot>() as TileMapRoot; Vector2 tileSize = Vector2.one; if (tilePrefab) { SquareTileMapNode nodeCompo = tilePrefab.GetComponent <SquareTileMapNode>(); tileSize = nodeCompo.squareSize; } tileMapRootCompo.InitFromEditor(screen2D, tileWidthCount, tileHeightCount, tileSize); curTileMap = tileMapRootCompo; Selection.activeObject = curTileMap.gameObject; // new tilenode group gameobject GameObject tileMapNodeGroup = tileMapRootCompo.NodeGroup; // create tile-map-nodes Dictionary <int, SquareTileMapNode> nodeMap = new Dictionary <int, SquareTileMapNode>(); int nodeIndex = 0; for (int y = 0; y < tileHeightCount; ++y) { for (int x = 0; x < tileWidthCount; ++x, ++nodeIndex) { SquareTileMapNode squareTileMapNode = MakeTileMapOneTile(nodeIndex, x, y, tilePrefab, tileMapNodeGroup); nodeMap[nodeIndex] = squareTileMapNode; } } // connect eachother nodes MakeConnectionEachOtherNodes(); }
void RemakeTileMap() { if (curTileMap == null) { return; } if (tilePrefab == null) { Debug.LogError("failed to MakeTileMap. null tilePrefab."); return; } // clear ClearAboutPathTest(); Vector2 tileSize = Vector2.one; if (tilePrefab) { SquareTileMapNode nodeCompo = tilePrefab.GetComponent <SquareTileMapNode>(); tileSize = nodeCompo.squareSize; } curTileMap.InitFromEditor(screen2D, tileWidthCount, tileHeightCount, tileSize); // new tilenode group gameobject GameObject tileMapNodeGroup = curTileMap.NodeGroup; // create tile-map-nodes Dictionary <int, SquareTileMapNode> nodeMap = new Dictionary <int, SquareTileMapNode>(); int nodeIndex = 0; for (int y = 0; y < tileHeightCount; ++y) { for (int x = 0; x < tileWidthCount; ++x, ++nodeIndex) { SquareTileMapNode squareTileMapNode = MakeTileMapOneTile(nodeIndex, x, y, tilePrefab, tileMapNodeGroup); nodeMap[nodeIndex] = squareTileMapNode; } } // connect eachother nodes MakeConnectionEachOtherNodes(); }