//Init map and hook up buttons. private void InitMap(int height, int width, StreamReader reader = null) { //Wipe the old one first if (m_map != null) { m_map.Destroy(); } m_map = new Map(); for (int y = 0; y < height; y++) { m_map.Rows.Add(new MapRow()); MapRow currentRow = m_map.Rows[y]; for (int x = 0; x < width; x++) { EditorTileButton tile = GameObject.Instantiate(m_tilePrefab).GetComponent <EditorTileButton>(); currentRow.Tiles.Add(tile); SetTilePosition(tile, x, y); tile.transform.parent = m_tileContainer.transform; if (reader != null) { int index = int.Parse(reader.ReadLine()); tile.SetTile(index, m_tileTextures[index]); } else { tile.SetTile((int)EditorDrawMode.DrawEmpty, m_tileTextures[(int)EditorDrawMode.DrawEmpty]); } tile.onClick.AddListener(delegate { TileButtonClicked(); }); } } }
//If you press a tile in our map we cache via unity eventsystem. Then we set the tile to current drawed tile. private void TileButtonClicked() { m_lastClickedTile = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.GetComponent<EditorTileButton>(); m_lastClickedTile.SetTile(m_tileDropDown.value, m_tileTextures[m_tileDropDown.value]); }
//If you press a tile in our map we cache via unity eventsystem. Then we set the tile to current drawed tile. private void TileButtonClicked() { m_lastClickedTile = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.GetComponent <EditorTileButton>(); m_lastClickedTile.SetTile(m_tileDropDown.value, m_tileTextures[m_tileDropDown.value]); }