Author Topic: UITable and column direction ... bug?  (Read 11031 times)

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
UITable and column direction ... bug?
« on: August 29, 2012, 12:07:58 PM »
Hi,

I have dynamicaly created content inside UITable organized in direction=Down and sort is OFF.
This works well on Desktop, but on Android are columns organized from UP, instead DOWN (ignored setup from inspector?).

Attached Images show result. FromPC + UnityEditor result is same and correct, but from android device looks wrong.

  1. void Start ()
  2.         {
  3.                 GlobalEditorData.cells = new TSourceCell[this.cellWidth,this.cellHeight];
  4.                
  5.                 this.table = NGUITools.FindInParents<UITable>(this.gameObject);
  6.                 this.panel = NGUITools.FindInParents<UIDraggablePanel>(table.gameObject);
  7.                 table.sorted = false;
  8.                 this.table.columns = this.cellWidth;
  9.                
  10.                 // create and rename objects to standard matrix direction from left -> right and from top -> down
  11.                
  12.                 for (int y=this.cellHeight;y>0;y--)                    
  13.                 for (int x=this.cellWidth;x>0;x--)
  14.                 {
  15.                        
  16.                         int cx = x-1;
  17.                         int cy = y-1;
  18.                         GlobalEditorData.cells[cx,cy] = new TSourceCell();                     
  19.                          
  20.                         GameObject cell = NGUITools.AddChild(this.gameObject,this.itemPrefab);
  21.                        
  22.                         GlobalEditorData.cells[cx,cy].name = "Cell_"+cx.ToString()+"x"+cy.ToString();
  23.                         GlobalEditorData.cells[cx,cy].item = cell;
  24.                         GlobalEditorData.cells[cx,cy].item.name = "Cell_"+cx.ToString()+"x"+cy.ToString();
  25.                        
  26.                         string path = "/UI Root (2D)/Camera/Anchor/Source_Window/SourcePanelEmpty/SourceTable/"+GlobalEditorData.cells[cx,cy].item.name+"/ButtonEmpty_CMD";
  27.                        
  28.                         GameObject o = GameObject.Find(path);
  29.                        
  30.                         GlobalEditorData.cells[cx,cy]._cmd = (OnClick_SourceCell)o.GetComponent<OnClick_SourceCell>();                         
  31.                         GlobalEditorData.cells[cx,cy]._cmd.parentName = GlobalEditorData.cells[cx,cy].item.name;
  32.                         GlobalEditorData.cells[cx,cy].icon = (UISlicedSprite)GlobalEditorData.cells[cx,cy]._cmd.GetComponentInChildren<UISlicedSprite>();
  33.                        
  34.                        
  35.                 }
  36.                
  37.                
  38.                 this.table.Reposition();
  39.                 this.panel.ResetPosition();
  40.                
  41.         }
  42.  


EDIT: Added 2 new screenshots (DesktopRelease and AndroidRelease). Same code, same method and different rersult. Now all cells are with desc. Column x Row.
Android rel. has table aligned = columns: from right -> left / rows: from botom -> up
PC rel. has table aligned  = columns: from left -> right / rows: from top -> down


« Last Edit: August 29, 2012, 03:28:53 PM by AndyGFX »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable and column direction ... bug?
« Reply #1 on: August 29, 2012, 04:32:16 PM »
Looks like it didn't actually sort them. Instead of calling "Reposition", set "repositionNow = true".

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: UITable and column direction ... bug?
« Reply #2 on: August 29, 2012, 04:35:21 PM »
Ok. I will look on it tommorrow and i will report result to you.

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: UITable and column direction ... bug?
« Reply #3 on: August 30, 2012, 09:00:55 AM »
with

  1. this.table.repositionNow = true;
  2.  

:( no, same bad result on android device.


New important info: Correct table content position is only in UNITY editor / run. All released platforms (WEB /  FLASH / ANDROID / Win EXE) are with swapper orientation.
« Last Edit: August 30, 2012, 09:06:59 AM by AndyGFX »

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: UITable and column direction ... bug?
« Reply #4 on: August 30, 2012, 12:18:35 PM »
so i'm found where is problem.


UITable.cs

  1. public void Reposition ()
  2.         {
  3.                
  4.                 if (mStarted)
  5.                 {
  6.                         Transform myTrans = transform;
  7.                         mChildren.Clear();
  8.                         List<Transform> ch = children;
  9.                        
  10.                         ch.Reverse();  <-------------------------- my experiment - swap list items:)
  11.                        
  12.                         if (ch.Count > 0) RepositionVariableSize(ch);
  13.  
  14.                         if (mDrag != null)
  15.                         {
  16.                                 mDrag.UpdateScrollbars(true);
  17.                                 mDrag.RestrictWithinBounds(true);
  18.                         }
  19.                         else if (mPanel != null)
  20.                         {
  21.                                 mPanel.ConstrainTargetToBounds(myTrans, true);
  22.                         }
  23.                         if (onReposition != null) onReposition();
  24.                 }
  25.                 else repositionNow = true;
  26.         }
  27.  

Now is list wrong organized in editor, but correct on all devices.
But now is main question, where is problem: Unity (3.5.5) or UITable?.
« Last Edit: August 30, 2012, 12:20:27 PM by AndyGFX »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable and column direction ... bug?
« Reply #5 on: August 30, 2012, 04:46:42 PM »
I just re-read the original post and noticed that you mentioned that the sorting is off.

Well if it's off, I'm not sure what you expect Reposition() to do here. Of course it's not sorting them if the sorting is off.

The fact that they're added in a different order is just a platform discrepancy, a difference between editor and other platforms. If you want it to be in a specific order, turn sorting back on, and name them something like 001, 002, 003, etc.

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: UITable and column direction ... bug?
« Reply #6 on: August 30, 2012, 04:52:06 PM »
Good point. Thank.

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: UITable and column direction ... bug?
« Reply #7 on: August 31, 2012, 07:23:24 AM »
Works!. Thx.

Fixed code:
  1.         // Use this for initialization
  2.         void Start ()
  3.         {
  4.                 GlobalEditorData.cells = new TSourceCell[this.cellWidth,this.cellHeight];
  5.                
  6.                 this.table = NGUITools.FindInParents<UITable>(this.gameObject);
  7.                 this.panel = NGUITools.FindInParents<UIDraggablePanel>(table.gameObject);
  8.                 table.sorted = true;
  9.                 this.table.columns = this.cellWidth;
  10.                
  11.                 // rename objects to standard matrix direction from left -> right and from top -> down
  12.                 int idx = 0;
  13.                 for (int y=0;y<this.cellHeight;y++)                    
  14.                 for (int x=0;x<this.cellWidth;x++)
  15.                 {
  16.                        
  17.                         int cx = x;
  18.                         int cy = y;
  19.                         GlobalEditorData.cells[cx,cy] = new TSourceCell();                     
  20.                          
  21.                         GameObject cell = NGUITools.AddChild(this.gameObject,this.itemPrefab);
  22.                        
  23.                         string name_cell = string.Format("{0:0000}",idx);
  24.                        
  25.                         GlobalEditorData.cells[cx,cy].name = name_cell;
  26.                         GlobalEditorData.cells[cx,cy].item = cell;
  27.                         GlobalEditorData.cells[cx,cy].item.name = name_cell;
  28.                        
  29.                         string path = "/UI Root (2D)/Camera/Anchor/Source_Window/SourcePanelEmpty/SourceTable/"+GlobalEditorData.cells[cx,cy].item.name+"/ButtonEmpty_CMD";
  30.                        
  31.                         GameObject o = GameObject.Find(path);
  32.                        
  33.                         GlobalEditorData.cells[cx,cy]._cmd = (OnClick_SourceCell)o.GetComponent<OnClick_SourceCell>();                         
  34.                         GlobalEditorData.cells[cx,cy]._cmd.parentName = GlobalEditorData.cells[cx,cy].item.name;
  35.                         GlobalEditorData.cells[cx,cy]._cmd.label.text = cx.ToString()+"x"+cy.ToString();
  36.                         GlobalEditorData.cells[cx,cy].icon = (UISlicedSprite)GlobalEditorData.cells[cx,cy]._cmd.GetComponentInChildren<UISlicedSprite>();
  37.                        
  38.                         idx++;
  39.                        
  40.                 }
  41.                
  42.                
  43.                 this.table.Reposition();
  44.                 this.panel.ResetPosition();
  45.                
  46.         }
  47.