Exemplo n.º 1
0
 private void AssertGridSize(TilesLayoutContent content)
 {
     if (content.Columns != Columns || content.Rows != Rows)
     {
         throw new System.InvalidOperationException($"Attempt to set content with {content.Rows} rows and {content.Columns} columns while the layout requires {Rows} rows and  {Columns} columns.");
     }
 }
Exemplo n.º 2
0
        private void InvalidateContent()
        {
            if (Content != null && Content.Items != null)
            {
                foreach (TilesLayoutCell cell in Content.Items)
                {
                    Destroy(cell.GameObject);
                }

                Content = null;
            }
        }
Exemplo n.º 3
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;
                }
            }
        }