Author Topic: NGUI ScrollView - Items disappear when scrolling  (Read 6768 times)

whitebox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
NGUI ScrollView - Items disappear when scrolling
« on: June 05, 2013, 12:26:24 PM »
Hi All,

I use ButtonImage is item in grid of scrollview . I add button dynamically to scrollview and when I scroll to down/up everything is ok but when I scroll to left/right , buttons are not showed, the clipping is alpha clip, clipping size is smaller than the grid total size . Here is my code :
  1. UIGrid _uiGrid;
  2. GameObject prefab = (GameObject) Instantiate(  Resources.Load("Prefabs/Floor_Img", typeof(GameObject) ) );
  3.                
  4. for(int row=0; row< 20 ; ++row){
  5.                        
  6.         for(int col=0; col<20; ++col ){
  7.                 posX = 50 * col;
  8.                 GameObject floor = NGUITools.AddChild(_uiGrid.gameObject, prefab );
  9.                 floor.transform.localScale = new Vector3(1,1,1);
  10.                 floor.transform.localPosition = new Vector3(posX, posY, -1.0f);
  11.                                
  12.         }
  13.         posY = posY + sizeFloor;
  14. }

Can someone here help me ? I'm appreciated.
Thanks for reading .

BlueByLiquid

  • Guest
Re: NGUI ScrollView - Items disappear when scrolling
« Reply #1 on: June 05, 2013, 03:25:08 PM »
A couple of things. Are you calling "UIGrid.Reposition()" when you are done adding the items? Also you need to add "UIDragPanelContents" script to each of the items in the grid
« Last Edit: June 05, 2013, 07:25:07 PM by BlueByLiquid »

whitebox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI ScrollView - Items disappear when scrolling
« Reply #2 on: June 06, 2013, 12:56:32 PM »
I add "UIDragPanelContents" script to each of the items in the grid and calling "UIGrid.Reposition()" like you said but it is the same , including the items in the grid are in 1 row , not 20 rows like before . When I remove "UIGrid.Reposition()" , items are in 20 rows . Here is my ScrollView hierarchy :

UI Root (2D)
--Camera
----Anchor
------Panel
--------Scroll Bar Horizontal (UIScrollBar Script)
--------Scroll Bar Vertical (UIScrollBar Script)
--------ScrollView (UIPanel , UIDraggable Panel)
-----------Grid ( UIGrid )
--------------Item ( UIImage Button, UIDrag Panel Content )

whitebox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI ScrollView - Items disappear when scrolling
« Reply #3 on: June 06, 2013, 01:41:43 PM »
... after change clipping from "alpha clip" to "none" , everything work fine , I can see items when scrolling left to right , and don't know why  :-\

BlueByLiquid

  • Guest
Re: NGUI ScrollView - Items disappear when scrolling
« Reply #4 on: June 06, 2013, 05:31:32 PM »
I add "UIDragPanelContents" script to each of the items in the grid and calling "UIGrid.Reposition()" like you said but it is the same , including the items in the grid are in 1 row , not 20 rows like before . When I remove "UIGrid.Reposition()" , items are in 20 rows .

My mistake I got confused with UITable (Which will position your prefabs on a 2D table without you having to set the position. You could do this very quickly to see if it is what you want. Just remove your two lines of code modifying the transform and change UIGrid to UITable and set the width of the UITable to 20.

When you call reposition it is doing all the spacing and layout for you but it thinks you want to do a 1D grid. If you want to use UIGrid you need to make a Vertical grid containing a number of horizontal grids or you will need to create a prefab for one row. I think you will find UITable to be easier. :)