Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: rayfung on July 26, 2017, 12:00:11 AM

Title: UIGrid.ResetPosition() bug?
Post by: rayfung on July 26, 2017, 12:00:11 AM
The children of myTrans may contain inactive elements. Maybe loop through "list" is better?
What happens if change the last loop statement to loop through "list"?

  1. protected virtual void ResetPosition (List<Transform> list)
  2. {
  3.         //Ignore some code here
  4.         //.........................
  5.  
  6.         // Apply the origin offset
  7.         if (pivot != UIWidget.Pivot.TopLeft)
  8.         {
  9.                 Vector2 po = NGUIMath.GetPivotOffset(pivot);
  10.  
  11.                 float fx, fy;
  12.  
  13.                 if (arrangement == Arrangement.Horizontal)
  14.                 {
  15.                         fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
  16.                         fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
  17.                 }
  18.                 else
  19.                 {
  20.                         fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
  21.                         fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
  22.                 }
  23.  
  24.                 for (int i = 0; i < myTrans.childCount; ++i)    //Question: why loop through children of myTrans instead of list?
  25.                 {
  26.                         Transform t = myTrans.GetChild(i);
  27.                         SpringPosition sp = t.GetComponent<SpringPosition>();
  28.  
  29.                         if (sp != null)
  30.                         {
  31.                                 sp.target.x -= fx;
  32.                                 sp.target.y -= fy;
  33.                         }
  34.                         else
  35.                         {
  36.                                 Vector3 pos = t.localPosition;
  37.                                 pos.x -= fx;
  38.                                 pos.y -= fy;
  39.                                 t.localPosition = pos;
  40.                         }
  41.                 }
  42.         }
  43. }
  44.  
Title: Re: UIGrid.ResetPosition() bug?
Post by: ArenMook on August 03, 2017, 03:39:27 AM
Change it and find out :)

To be honest this code is ~6 years old, so I don't remember why it was the way it was, or if there was even a reason. I'll also change it on my end just to see if it breaks.