Ejemplo n.º 1
0
    void createButton(int y, int x, TileData tileData)
    {
        int        rndNum = match3.get(y, x);
        GameObject newBtn = Instantiate(proto, Vector3.zero, Quaternion.identity);
        var        t      = newBtn.GetComponent <Tile> ();

        t.data = tileData;
        var bc = newBtn.GetComponent <BoxCollider2D> ();

        bc.size = new Vector2(size / 4, size / 4);
        var tile = data [y] [x];

        tile.gameObject = newBtn;
        tile.colour     = rndNum;
        newBtn.GetComponent <Image> ().color = colours [tile.colour];
        var btnObj = newBtn.gameObject;

        btnObj.name = "tile" + x + "," + y;
        btnObj.transform.SetParent(gameObject.transform);
        var trans = newBtn.transform as RectTransform;

        trans.localPosition = pos(x, y);
        trans.sizeDelta     = Vector2.one * scale;

        /*newBtn.onClick.AddListener (() => {
         *      var swipe = SwipeMovement.lastSwipe;
         *      print (y + "," + x + ": " + swipe);
         *      var dy = swipe == "up" ? -1 : swipe == "down" ? 1 : 0;
         *      var dx = swipe == "left" ? -1 : swipe == "right" ? 1 : 0;
         *
         *      OnClick (y, x, dy, dx);
         * });*/
    }