Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: dnglu on August 13, 2015, 05:00:55 PM

Title: Assigning a panel's anchors at runtime in C# does not cause resize.
Post by: dnglu on August 13, 2015, 05:00:55 PM
Hello.

I have a Panel containing a scrolling list.  I am attempting to anchor its clipping region to be between two other UI objects. We'll call them TopBar and BottomBar, they are UISprites.

However, the Panel, TopBar, and BottomBar are all part of different prefabs and are arranged at runtime.  I have tried setting Panel's anchor targets and relative offsets in code.  However, while the anchor values change the clipping values do not.  Only by altering the values manually via the inspector causes the clipping plane to move.

The code looks like this:
  1. UIPanel panel = this.GetComponent<UIPanel>();
  2.  
  3. Debug.Log("Resizing Panel");
  4.  
  5. panel.bottomAnchor.target = BottomBarBackground.transform;
  6. panel.bottomAnchor.Set(1,0);
  7.  
  8. panel.topAnchor.target = TopBar.transform;
  9. panel.topAnchor.Set(0, 1);
  10.  
  11. panel.RebuildAllDrawCalls();
  12.  

I feel as though there is some command I am missing to make the clipping area re-size itself based on the new anchor values.

Currently, when I run this code the Panel's clipping area stats do not change, staying at prefab values.
Title: Re: Assigning a panel's anchors at runtime in C# does not cause resize.
Post by: dnglu on August 13, 2015, 05:23:17 PM
After checking elsewhere on the forum, it seems that I must call the following methods after altering the panels:

panel.ResetAnchors()
panel.UpdateAnchors()

The problem is now solved.