示例#1
0
    //Calculates the tile buttons position and width/height based on sceensize.
    private void SetTilePosition(EditorTileButton tile, int x, int y)
    {
        float   size           = Screen.width / m_rowWidth;
        Vector2 textureLengths = new Vector2(size, size);

        tile.transform.position = new Vector3((size / 2f) + tile.transform.localPosition.x + (textureLengths.x * x), (size / 2f) + tile.transform.localPosition.y + (textureLengths.y * y), 0);
        tile.GetComponent <RectTransform>().sizeDelta = textureLengths;
    }
示例#2
0
    //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(); });
            }
        }
    }
示例#3
0
 //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]);
 }
示例#4
0
 //Calculates the tile buttons position and width/height based on sceensize.
 private void SetTilePosition(EditorTileButton tile, int x, int y)
 {
     float size = Screen.width / m_rowWidth;
     Vector2 textureLengths = new Vector2(size, size);
     tile.transform.position = new Vector3((size / 2f) + tile.transform.localPosition.x + (textureLengths.x * x), (size / 2f) + tile.transform.localPosition.y + (textureLengths.y * y), 0);
     tile.GetComponent<RectTransform>().sizeDelta = textureLengths;
 }
示例#5
0
 //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]);
 }