コード例 #1
0
        private void DisplayContent(TilesLayoutContent content)
        {
            content.Measure();

            var fullWidth = content.Width + PaddingLeft + PaddingRight;

            AdjustCamera(fullWidth);

            for (int column = 0; column < Columns; column++)
            {
                float startX;
                if (column == 0)
                {
                    startX = -fullWidth / 2 + PaddingLeft;
                }
                else
                {
                    TilesLayoutCell previousCell = content.Items[column - 1, 0];
                    startX = previousCell.GameObject.transform.localPosition.x + previousCell.MeasuredWidth / 2;
                }

                // TODO - Think of a better way to adjust the starting Y position.
                var startY = -content.Height / 2f - 1;
                for (int row = 0; row < Rows; row++)
                {
                    var item = content.Items[column, row];
                    var x    = (float)Math.Round(startX + item.MeasuredWidth / 2, 2);
                    var y    = (float)Math.Round(startY + item.MeasuredHeight / 2, 2);

                    if (item.GameObject != null)
                    {
                        item.GameObject = Instantiate(item.GameObject, new Vector3(x, y, 0), item.GameObject.transform.rotation);
                        if (item.GameObject.GetComponent(typeof(IClickableProvider)) is IClickableProvider iClickableProvider)
                        {
                            iClickableProvider.GetIClickable().OnGameObjectClick += OnItemClick;
                        }
                    }

                    startY += item.MeasuredHeight;
                }
            }
        }
コード例 #2
0
 public void SetCell(TilesLayoutCell cell, int x, int y)
 {
     Items[x, y] = cell;
 }