Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: viqtor on August 10, 2014, 01:36:40 PM

Title: Grid dimensions
Post by: viqtor 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.
Title: Re: Grid dimensions
Post by: ArenMook 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. }
Title: Re: Grid dimensions
Post by: viqtor on August 11, 2014, 06:36:30 AM
Thanks, I will write a complete script and get back to you.