Support => NGUI 3 Support => Topic started by: jason0202 on December 04, 2012, 12:13:11 PM
Title: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: jason0202 on December 04, 2012, 12:13:11 PM
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.
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
Title: Re: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: ArenMook on December 05, 2012, 04:51:23 AM
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.
Title: Re: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: jason0202 on December 15, 2012, 02:16:04 PM
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.
Title: Re: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: ArenMook on December 15, 2012, 03:44:25 PM
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.
Title: Re: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: jason0202 on December 16, 2012, 11:10:06 AM
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
Title: Re: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: Nicki on December 16, 2012, 06:46:56 PM
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.
Title: Re: Setting UIDraggable panel scroll position BUT focus within its bound constrains
Post by: ArenMook on December 16, 2012, 10:29:25 PM
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.