Author Topic: UIGrid  (Read 76632 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #30 on: June 13, 2014, 06:15:21 AM »
Grid's pivot point controls where the origin point will lie. TopRight means the content's top-right-most element will have the local position of (0, 0, 0).

Fractalbase

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: UIGrid
« Reply #31 on: June 30, 2014, 04:57:53 PM »
I haven't attempted this yet, but is nesting UIGrids possible/advised?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #32 on: July 01, 2014, 05:05:03 AM »
Sure, it's fine. Grids don't use their bounds in any way. They simply reposition their immediate children.

ddub

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIGrid
« Reply #33 on: July 26, 2014, 03:26:58 PM »
Hey Aren,

I have a UIGrid set up in a scrollbar. The children (my game icons in the grid) are active initially but on start, I have a script that removes some dynamically, based on some previous user-based input. However, because the children are all active initially, the UIGrid isn't repositioning the ones left active immediately. It will update them when I click inside of the scrollview though.

Do I just need to set some check in the update, or delay the grid's positioning for the repositioning to work correctly?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #34 on: July 27, 2014, 03:02:44 AM »
You should call the Reposition() function yourself after modifying the child list in any way, or enabling/disabling items there. Same goes for calling scroll view's ResetPosition().

ddub

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UIGrid
« Reply #35 on: July 28, 2014, 05:28:59 PM »
Ah gotcha, that makes sense. Thanks Aren!

FDMP

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIGrid
« Reply #36 on: July 31, 2014, 06:33:26 PM »
Hello I'm using nested UI Grid to create a Scroll View that shows multiple (pages) matrices of 3x3 elements.
Here is the Hierarchy:

ScrollView
--Grid                      //Main grid
----Grid                   //First page
--------Element1
--------Element2
--------Element3
--------Element4
--------Element5
--------Element6
--------Element7
--------Element8
--------Element9
----Grid                   //Second page
--------Element10
--------Element12
--------Element13
--------Element14
--------Element15
--------Element16
--------Element17
--------Element18
--------Element19

I can successfully generate pages. I parent the the elements to the page grid and then in the page grid, call:
  1. UIGrid.Reposition();
So far so good. The problem lies when y call UIGrid.Reposition() in the main grid, I also call:
  1. ScrollView.ResetPosition();
but the pages are stack one on top of another. I noticed that if I call ScrollView.ResetPosition() and UIGrid.Reposition() in the frame after I fill the elements, it works well.

It's a bug or I'm missing something? I'm using NGUI 3.6.8

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #37 on: August 01, 2014, 09:37:32 PM »
You're basically trying to reset position of the scroll view before widgets are actually there. If I understand what you're doing correctly, this is what you're doing:

- Create Element1
--- Element1 Awake()
--- Element1 OnEnable()
- Create Element2
--- Element2 Awake()
--- Element2 OnEnable()
...
- Reposition()
- ResetPosition()

The widgets aren't going to be added to the panel until after their Start() executes, which happens later. If you want it to be immediate, call the widget's CreatePanel() function.

brianmyrick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIGrid
« Reply #38 on: October 22, 2014, 03:18:06 PM »
How would I go about limiting a grid so that I can't drag more than X number of children into it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #39 on: October 23, 2014, 03:46:10 PM »
ExampleDragDropItem.OnDragDropRelease has the code for what happens when you drop something. Write your own item class that will do some logic checking for whether its possible to drop the item there or not.

cartman412

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIGrid
« Reply #40 on: December 02, 2014, 02:16:09 PM »
Haven't seen this asked so I hope it's not repeated.

Is there any way to create a grid with non-uniform elements and make them stick to one after the other?

To expand a bit on the question:

I have a vertical grid, with elements of different heights and I want them to appear one right after the other. This would be extremely simple if all the elements had the same height but it seems that a the ngui grid cannot deal with elements of different sizes?

Would I have to customize the script in order to achieve this?

« Last Edit: December 02, 2014, 02:30:52 PM by cartman412 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #41 on: December 04, 2014, 04:25:19 AM »
No, grid is always uniform. What you are thinking of is UITable.

cartman412

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIGrid
« Reply #42 on: December 04, 2014, 08:00:13 AM »
You are right ^^ Thank you :)

crust

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIGrid
« Reply #43 on: December 08, 2014, 02:44:20 PM »
Hi I think I might have found an odd little bug.

What I'm doing is moving a transform from one UIGrid to another UIGrid and I'm using the smooth tween option.  When I move the first transform, it tweens into place correctly -- however, once it is in place, its spring position component is never activated again and it gets stuck in the 0,0,0 position.

The problematic code is this if statement:
  1. if (animateSmoothly && Application.isPlaying && Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f)
  2. {
  3.         SpringPosition sp = SpringPosition.Begin(t.gameObject, pos, 15f);
  4.         sp.updateScrollView = true;
  5.         sp.ignoreTimeScale = true;
  6. }
  7. else t.localPosition = pos;
  8.  

Specifically this little bit that doesn't turn on the spring position component when the distance needed to travel is very small:
  1. Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f
  2.  

The result is that its position is always stuck at 0,0,0 -- because the x and y always start at 0,0 in the for loop and the second half of reset position (apply origin offset) will do its lerp on the spring position component (which never gets turned on)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid
« Reply #44 on: December 09, 2014, 02:04:17 PM »
Hmm... interesting. Well, just change that part to:
  1.                         if (animateSmoothly && Application.isPlaying)
  2.                         {
  3.                                 SpringPosition sp = SpringPosition.Begin(t.gameObject, pos, 15f);
  4.                                 sp.updateScrollView = true;
  5.                                 sp.ignoreTimeScale = true;
  6.                         }
  7.                         else t.localPosition = pos;