Author Topic: Disable Collider on Clipped DraggablePanel items  (Read 5652 times)

soofaloofa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Disable Collider on Clipped DraggablePanel items
« on: April 24, 2012, 01:01:25 PM »
Hi,

I have a scenario involving UIDraggablePanel's that are side by side on screen. Because of the scene layout I'd like to disable colliders on clipped items so that touches do not end up registering in the wrong panel. Is this possible?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #1 on: April 24, 2012, 02:19:49 PM »
Put a collider on top of them that will cover the items that go outside of your area. This way the covering colliders will intercept mouse events.

soofaloofa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #2 on: April 25, 2012, 10:07:43 AM »
Maybe I didn't explain myself properly but the problem is that the UIPanel contents are side by side and therefore overlap each other when the contents are dragged to the extremes. If I put a collider overtop of one panel it will cover the contents of the second panel and stop touches from registering.

Is there a way to know if an object is being clipped? I could disable colliders on clipped objects this way?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #3 on: April 25, 2012, 11:38:58 AM »
Sure, you can check to see if the widget is clipped by checking its bounds against the clipping area, but what about partial clipping, where 1 pixel is within bounds but 299 happen to be outside? There is no way to clip physics colliders during a raycast. Side by side draggable panels is a tricky one, but my original suggestion stands.

Place a collider covering the entire panel. On that collider receive OnHover(true) event. When such event is received, turn off this collider and enable the neighbour. Since you've disabled this collider, all events will now be falling through to your panel. When you move your mouse over to the neighbour's panel (which is currently covered by a collider you enabled), it will also receive OnHover(true), and the process repeats -- disable it, enable the neighbour's cover.

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #4 on: August 26, 2012, 07:52:21 PM »
Quote
you can check to see if the widget is clipped by checking its bounds against the clipping area

Do you have a code sample for how to do this?

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #5 on: August 27, 2012, 08:15:36 AM »
NGUIMath.CalculateRelativeWidgetBounds(panelTransform, widgetTransform) tells you the bounds of the widget (you can also specify a game object, and all the widgets underneath it will be summed up). Knowing this, it's a simple matter of checking against panel's clipRange. UIPanel does this for ConstrainTargetToBounds, for example.

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #6 on: September 08, 2012, 02:23:33 PM »
NGUIMath.CalculateRelativeWidgetBounds(panelTransform, widgetTransform) tells you the bounds of the widget (you can also specify a game object, and all the widgets underneath it will be summed up). Knowing this, it's a simple matter of checking against panel's clipRange. UIPanel does this for ConstrainTargetToBounds, for example.

I need a little more information. I'm using a SpringPanel (standard right?) and I need to do this test after the spring panel is done moving. Is there an event I am missing to do this?

I can make a custom version of SpringPanel with OnSettled delegate, but this seems like such a common behavior that I wanted to post this question before I hack the plugin. E.g.:

  1.         if (mThreshold >= (target - mTrans.localPosition).magnitude)
  2.         {
  3.             enabled = false;
  4.             SpringPanel.OnSettled()
  5.         }
  6.  


Cheers,

« Last Edit: September 08, 2012, 02:25:11 PM by Rafe »

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #7 on: September 08, 2012, 02:48:39 PM »
Nevermind I did it using inheritance to extend SpringPanel. This works fine (SI is just our project's initials):

  1. [AddComponentMenu("NGUI/Internal/Spring Panel (SI)")]
  2. public class SIUISpringPanel : SpringPanel
  3. {
  4.     public delegate void OnSettledDelegate();
  5.     public static OnSettledDelegate OnSettledDelegates;
  6.  
  7.     private void Awake()
  8.     {
  9.         // Force clear delegates in case of level change
  10.         SIUISpringPanel.OnSettledDelegates = null;
  11.     }
  12.  
  13.     private void OnDisable()
  14.     {
  15.         SIUISpringPanel.OnSettledDelegates();
  16.     }
  17. }
« Last Edit: September 21, 2012, 11:30:43 AM by Rafe »

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #8 on: September 08, 2012, 03:12:12 PM »
The bounds don't change as I drag the panel.

I can see gizmos being dropped, so I know you have some code that figures out when things are outside the clipping range. I'm going to hard-code a couple numbers for now. Please share some code when you get a chance.
« Last Edit: September 21, 2012, 11:29:58 AM by Rafe »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disable Collider on Clipped DraggablePanel items
« Reply #9 on: September 08, 2012, 03:14:44 PM »
Bounds aren't supposed to change. Everything is stationary when SpringPanel is used. That's the nature of it, and why it's so fast on mobiles as it doesn't involve rebuilding of geometry. What changes instead is the panel's clipping rect.