Author Topic: Grid dimensions  (Read 5161 times)

viqtor

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Grid dimensions
« on: August 10, 2014, 01:36:40 PM »
Hello

I want to combine a grid/table and a widget together, the widget can be aligned relative to other objects and the grid/table updates the cell dimensions according to the widget. What is the easiest way to do it? I wonder why nobody asked that before.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Grid dimensions
« Reply #1 on: August 10, 2014, 06:09:03 PM »
You'll need to write a script for that. Knowing the width and height of the widget, set the grid's cell width accordingly. For example:
  1. using UnityEngine;
  2.  
  3. public class ResizeMyGrid : MonoBehaviour
  4. {
  5.     public UIGrid grid;
  6.     public UIWidget widget;
  7.  
  8.     void Start () { widget.onChange = ChangeMyGrid; }
  9.  
  10.     void ChangeMyGrid ()
  11.     {
  12.         grid.cellSize = widget.width / 4;
  13.         grid.Reposition();
  14.     }
  15. }

viqtor

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Grid dimensions
« Reply #2 on: August 11, 2014, 06:36:30 AM »
Thanks, I will write a complete script and get back to you.