Author Topic: Set anchor type advanced in code? [SOLVED]  (Read 4612 times)

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 93
    • View Profile
Set anchor type advanced in code? [SOLVED]
« on: April 22, 2014, 04:19:32 PM »
Hi I need to set anchor just on left and right with value 0, and on bottom and top to null, all this in code but I don't know how to setup correctly.

I check UIRect.SetAnchor() but this set the anchor of type unified, how can I set it on advance?

Also I'm using this code:
  1. for(int i = 0; i<= 10; i++)
  2. {
  3.      GameObject row = NGUITools.AddChild(Grid, prefabRow);
  4.      row.GetComponent<UISprite>().leftAnchor.target = ScrollView.transform;
  5.      row.GetComponent<UISprite>().leftAnchor.absolute = 0;
  6.      row.GetComponent<UISprite>().rightAnchor.target = ScrollView.transform;
  7.      row.GetComponent<UISprite>().rightAnchor.absolute = 0;
  8.      row.GetComponent<UISprite>().ResetAnchors();              /////////////The line that was missing to work correctly
  9. }
  10. Grid.getComponent<UIGrid>().Reposition();
  11. ScrollView.ResetPosition();
  12.  

And this correctly set the anchor, the problem that I have with the last one is when I instantiate a new row tje width of the sprite is set to small like 2 pixels. But if I disable the gameObject (row) and enable it again the anchor updates the sprite width correctly, something that didn't happen on previous version of ngui, but now happens when I update to last version.


SOLUTION
I need to call ResetAnchors() before I set the anchors
« Last Edit: April 22, 2014, 07:37:55 PM by Darkmax »