Author Topic: UIGrid  (Read 82628 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #15 on: February 08, 2014, 01:27:37 PM »
Grid with 1 column. Each row is a prefab with 2 labels underneath. Instantiate these rows under your grid as many times as you need.

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: UIGrid
« Reply #16 on: February 11, 2014, 01:00:34 PM »
Hi guys! Thanks for a great product. I wanted to ask if its UIGrid i should ask to keep a set of 8 prefabs aligned in a grid, or is it something else? Ive read several things but find it difficult to know what the updated information is. Anyway i get this weird result. It looks like this:
http://i.imgur.com/CHqwhIS.png

This is how i instantiate the prefabs:

  1.                 var grid = GetComponent<UIGrid> ();
  2.                                 for (int i = 0; i < amountOfSlots; i++) {
  3.                                                 //                      GameObject go = Instantiate (ZoneScene.prefab_InventorSlot) as GameObject;
  4.                                                 GameObject go = NGUITools.AddChild (grid.gameObject, ZoneScene.prefab_InventorSlot);
  5.  
  6.                                                 print ("go: " + go);
  7.                                                
  8.  
  9.                                 }
  10.  
  11.                                 grid.Reposition ();

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #17 on: February 11, 2014, 09:10:29 PM »
Yup, that's perfectly fine. I've even used UIGrid to automatically position other things... like 3D game objects.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: UIGrid
« Reply #18 on: March 03, 2014, 04:19:26 PM »
I am really confused by the UIGrid Arrangement option. It seems to be backwards.

I'm trying to make a vertical grid (a column of items with 1 item per row, extending up and down vertically on the screen), but selecting "Vertical" makes a horizontal grid, and selecting "Horizontal" makes a vertical grid.

Is this intentional behavior? Common sense as well as your documentation would seem to indicate otherwise.
« Last Edit: March 03, 2014, 04:27:45 PM by Deozaan »

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: UIGrid
« Reply #19 on: March 03, 2014, 04:37:39 PM »

I'm trying to make a vertical grid (a column of items with 1 item per row, extending up and down vertically on the screen), but selecting "Vertical" makes a horizontal grid, and selecting "Horizontal" makes a vertical grid.


Because you have MAX PER LINE set to 1. :D
Then it makes one column, and then it starts with next. Set it to 8 or whatever and you will see the difference. (havent tried it but i am pretty sure)

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: UIGrid
« Reply #20 on: March 03, 2014, 05:35:50 PM »
Because you have MAX PER LINE set to 1. :D
Then it makes one column, and then it starts with next. Set it to 8 or whatever and you will see the difference. (havent tried it but i am pretty sure)

Thank you. That was indeed the problem. I could have sworn I didn't mess with Max Per Line until after the problems started happening, but changing it back to 0 gives me the intended results.

Thanks again!

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: UIGrid
« Reply #21 on: March 24, 2014, 11:45:52 PM »
Is my current understanding that there is no current way to either align or re-size a UIGrid according to its parent at this time? Any clarification is appreciated.

jimbbq

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: UIGrid
« Reply #22 on: March 25, 2014, 05:06:20 PM »
I have just bought NGUI and began to explore it. it is amazing so far following the tutorial on youtube! thanks a lot for creating such an amazing library!

I have a question on dynamically adding items to the grid and have the grid arrange the item dynamically. I use playmaker, but I am also familiar with c sharp/javascript, so either solutions would be fine.

I have a grid inside scroll view with 3 items which I can scroll vertically. Then I create a button, and when the button is clicked, I want to add a new item into the grid. I learn that (from youtube and this post) to ask the grid to automatically arrange the items, I right click UIGrid script and select execute. But how do I do it when the game is running?

thanks again!

[edit] silly me, as soon as I created this post, I found a solution , which is to call Reposition method...however the newly created items in the grid are not clipped by the scroll view?? also the new items are not draggable despite having UIDragDropItem script. any clue why it is the case?

[edit] I solved it again......now another problem....I have a vertical scroll bar, when the items are added to the grid, the scroll bar display is not updated...how do I resolve it? thanks!
« Last Edit: March 25, 2014, 05:40:30 PM by jimbbq »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #23 on: March 26, 2014, 03:29:56 AM »
@blitzer: No, UIGrid is a simple positioning tool. If you want its number of columns and/or rows to vary, create a custom script to change the UIGrid's properties as needed.

@jimbbq: UIScrollView.UpdateScrollBars function can do that for you.

jimbbq

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: UIGrid
« Reply #24 on: March 26, 2014, 11:49:40 AM »
brilliant!! it works now!

just for future reference, UpdateScrollbars (with small b for bars!) . took me a while to figure out  :-[


aGosh

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIGrid
« Reply #25 on: April 08, 2014, 03:19:07 AM »
Hello!
How can I fix it? I need to remove this indent.
Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #26 on: April 09, 2014, 04:09:40 AM »
Why do you have so many panels in there? It's hard to tell what's going on. What you're doing has nothing to do with the grid. Grid simply positions children. Your issue is with the way you set up your scroll views. Use the support forum rather than the documentation forum.

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIGrid
« Reply #27 on: June 10, 2014, 06:18:45 AM »
Hi,

Just to clarify something: can the UIGrid AddChild(Transform) method be used to dynamically add children to a Grid (and display them automatically) ? I tried to use this method (or GetChildList() and then add children to the list), and the size of the method is changing correctly, but the new elements are not displayed.

For the moment I still get the GameObject containing the UIGrid script, and then use NGUI.addChild(T) , but I'm wondering why the other method is not working.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #28 on: June 11, 2014, 06:08:20 AM »
UIGrid.AddChild is kind of pointless right now. It used to have a point, but due to how Unity stores transform child list it turned out to be not useful at all.

Adding children to the grid's game object is enough. No need to use UIGrid's AddChild.

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIGrid
« Reply #29 on: June 12, 2014, 10:55:08 AM »
Okay, thank you for your answer.

I have another weird behavior. I don't know if it's due to my wrong understanding of the "pivot" settings :



I would think that a Top-Right Pivot would make the grid start in the Top right corner of its parent. (The parent scrollview has a "Top" content origin setting).

I must admit that the Grid was kind of hard to settle correctly. Right now I still have some troubles finding the right parameters to get what I want...

For example, I don't quite understand that my centers are not similar (on the y axis) :



The centers should be on the same vertical line, right ? (with a "top" pivot parameter, which is "top center").
« Last Edit: June 12, 2014, 11:01:21 AM by RDeluxe »