Author Topic: UIDraggablePanel collisions  (Read 4012 times)

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
UIDraggablePanel collisions
« on: November 14, 2013, 09:12:57 AM »
I have multiple UIDraggablePanels.

I'm looking for a good way to stop drag if they touch each other or the edge of the player window?

using OnTriggerEnter or OnCollisionEnter I have to add a Rigidbody to each panel, this seems a little heavy duty? Besides that, I can't think of a nice way to just 'bump' up, stop, but then easily move back off.

Imagine having the panels as blocks of Lego on a tray, you can move them about, up to the edge, and up to each other. But they can't escape the tray, and they won't intersect.

(I'm not using these with scroll bars, just as floating panels)

Thanks for any ideas...
« Last Edit: November 15, 2013, 07:09:05 AM by mtompson »

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIDraggablePanel collisions
« Reply #1 on: November 15, 2013, 01:27:13 AM »
Just a bump

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel collisions
« Reply #2 on: November 15, 2013, 04:36:25 AM »
I would just use math in your case. Knowing the size of your child, the size of your parent, and the dimensions of the window, you can easily do the rest.

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIDraggablePanel collisions
« Reply #3 on: November 15, 2013, 07:08:31 AM »
That's good for the window, do you still think it's ok or normal to use collision physics on the actual panels when they meet?
Also what would you advise I use when I do get to the edge or collide with another panel? I obviously need to get 'un-stuck' again!  ;) not sure of the best method to stop the drag.

Many thanks, I appreciate your help...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel collisions
« Reply #4 on: November 15, 2013, 07:15:44 AM »
Seeing as NGUI uses trigger colliders to detect events, I would not recommend it.

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIDraggablePanel collisions
« Reply #5 on: November 16, 2013, 04:55:49 PM »
Using Maths as you suggest, I need to know if my player window size has changed, ( I'm allowing the end user to resize the window ) ideally not onUpdate?

Ngui obviously does this with the anchors, do you have any methods or variables exposed to help?

I need to know if the window size has changed.

Many thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel collisions
« Reply #6 on: November 16, 2013, 08:31:58 PM »
NGUI's anchors also do this check in Update. I simply check to see if the actual final position has changed before re-assigning it. It's part of the reason why it's often a good idea to only run anchors once.

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIDraggablePanel collisions
« Reply #7 on: November 17, 2013, 06:07:56 AM »
wow, I never paid much attention to the 'Run Only Once' bool, I have a fair few anchors, does Unity itself fire any methods if it's player window is re-sized? It would be nice to toggle your 'Run Only Once' bool? ( I understand you may well have used it if they did  :) )

Anyway one more idea on the UIDraggablePanels. If I enable Clipping ( say Alpha ) then have the 'Restrict Within Panel' ticked, I get the kind of effect I want. However I need the Alpha Clip Center & Size values to match my player window. So basically my draggable panel is trapped nicely inside the window... Can you suggest a way to do that?

many thanks for your help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel collisions
« Reply #8 on: November 18, 2013, 11:38:03 AM »
I made it work like that in 3.0.6 that's coming out soon. In 3.0.5 the anchor component gets destroyed after it executes the first time. The whole anchoring / stretch system is going to go through a re-design in 3.0.7 though.

What you're trying to do should be easier in 3.0.6 as I am actually currently redoing how clipping gets specified. You will basically be able to specify the clip region the same way you specify the widget's width and height -- by dragging handles in the scene view. No more clipping rects, basically.

Until then, sounds like you need a centered clipped panel with the UIStretch on it so that it always stretches itself to assume the screen's dimensions.

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIDraggablePanel collisions
« Reply #9 on: November 19, 2013, 08:43:31 AM »
Thankyou for the feedback, I look forward to your updates :-)