Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Paul1 on August 17, 2014, 09:07:12 PM

Title: How to Refresh UIGrid via code?
Post by: Paul1 on August 17, 2014, 09:07:12 PM
I have a function in a script that loops over a List, based on the contents decides whether to .SetActive (true)  or   .SetActive (false) icons in my UIGrid hiding the ones that should not be displayed and revealing others.

When the loop finishes I'd like to trigger the alphabetical sorting of the Grid to remove the blank spaces left behind by the inactive icons

Is there a function I can call in code to trigger this  (like right clicking on the UIGrid Script component in the inspector and selecting execute)

Thanks in advance!  :)
Title: Re: How to Refresh UIGrid via code?
Post by: ArenMook on August 18, 2014, 11:41:05 AM
UIGrid.Reposition
Title: Re: How to Refresh UIGrid via code?
Post by: Paul1 on August 19, 2014, 08:34:16 AM
I love you!   ;D
Title: Re: How to Refresh UIGrid via code?
Post by: hansthered on September 18, 2014, 10:02:01 PM
I am having a similar issue. I am calling:

  1. theGrid = GetComponent<UIGrid>();
  2. theGrid.Reposition();

However, the grid does not seem to change.

I add labels like this:

  1.                 GameObject clone = (GameObject) Instantiate(playerFoodStuffsLabelPrefab, new Vector3 (0, 0, 0), Quaternion.identity);
  2.                 theGrid.AddChild(clone.transform);
  3.                 clone.transform.localScale = new Vector3 (1, 1, 1);
  4.                 newLabel = clone.gameObject.GetComponent<UILabel>();

I remove labels like this:

  1.                 kidCount = theGrid.GetChildList ().Count;
  2.  
  3.                 for(int i=1; i< kidCount; i++){
  4.                         Destroy (theGrid.GetChild(i).gameObject);
  5.                 }

The new label does seem to spawn, the foodstuffs do update, but there is a gap in the grid where it looks like another label should be.

The reason I set i=1 instead of 0 is because the first child of the grid is the original prefab object. If i set that to 0 the prefab gets deleted (which I don't want).

Please advise,
Title: Re: How to Refresh UIGrid via code?
Post by: ArenMook on September 19, 2014, 08:21:00 PM
http://www.tasharen.com/forum/index.php?topic=11208.0