Author Topic: Setting UIDraggable panel scroll position BUT focus within its bound constrains  (Read 4514 times)

jason0202

  • Guest
Hi,

I bought NGUI 5 months ago, and I'm really happy with your continuous support and keep updating the plugin.
I'm developing a mobile game. I wonder is there any ready-made function in NGUI that will focusing on child item within the UIPanel
BUT limiting within its UIPanel clipping boundary.

What I mean, if the child is already at the end bottom of the UIPanel boundary, the focusing animation will only move the panel in X-coordinate ONLY.

I search across this forum and found this code
  1. Vector3 newPos = mPanel.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);
  2. SpringPanel.Begin(mPanel.gameObject, -newPos, 13f);
  3.  

but the problem is, this code will makes the UIDraggable panel not staying within its boundary while focusing its child item

Is there any solution for this?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Ready-made? Nope. You need to code your own logic of where to move to using SpringPanel.

There is no need to send me PMs to look at your posts. I get notified of all posts, it may just take me a bit to answer all of them.

jason0202

  • Guest
Sorry for the PM, because my project is quite tight with its schedule.  :(
Do you have any example on how to restricts the springpanel focus within the UIdraggablePanel boundary?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Since you will activate SpringPanel via SpringPanel.Begin, you can write logic to check -- is the widget within panel's bounds? If yes, restrict it in some way -- for example by making it move only along X, but using the same Y.

jason0202

  • Guest
Thanks for your quick reply.

But, I'm really have no idea on how to check whether the widget is within panel's bound.

Here's my current code:
Vector3 newPos = -1 * myPanel.transform.worldToLocalMatrix.MultiplyPoint3x4(TargetPos);
SpringPanel.Begin(myPanel.gameObject, newPos, magnitude);

Could you show me how to do it. Thanks


Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
I don't have time to do the work for you, but you can look close at UICenterOnChild.cs and how it figures out a position and do something similar to that.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Panel's bounds = UIPanel.clipRect. They're in screen space (pixels), assuming the panel is at the center of the screen and UIRoot is 'automatic'. If not, you will need to account for that (more math). Bounds of any widget or group of widgets relative to the panel can be calculated via NGUIMath.CalculateRelativeWidgetBounds.