Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - dnglu

Pages: [1]
1
NGUI 3 Support / Best way to alter the size of a panel through code?
« on: September 15, 2015, 01:40:02 PM »
Hello.

I am attempting to create a component that will allow a clipping panel to be resized at runtime to any arbitrary size.  Should I just assign to the baseClipRegion?  Is there another method?  What if I also want to tween the content inside to scroll to a particular entry?

I am also confused about Center value and an Offset value.  Both affect the position of the clipping area, but why are there two values instead of one?  I ask because I want to be able to change the center or offset value when resizing to ensure an edge or corner of the panel stays in place while the rest expands.

2
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.

3
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.

Pages: [1]