Author Topic: Setting Drag position  (Read 3752 times)

sk1989

  • Guest
Setting Drag position
« on: September 22, 2012, 09:38:28 PM »
HI,

I have a dragganle panel with button. I want to set manually the drag delta position of each button manually on start().

I know that on onDrag(delta) the delta give me the drag position of the object. But how do i set the delta position on start.

for example

I wanna do void Start()
{

   here i want to set the drag position of the button in the draggable panel

   delta.x  = -10;//for example. is there a function like to set the drag of a dragpanelContents
}

Thanks

sk1989

  • Guest
Re: Setting Drag position
« Reply #1 on: September 22, 2012, 09:44:37 PM »
What i really want to do is,

In my game, I have a menu with bunch of ngui buttons that are in a draggable panel being able to drag horizontally.

The game is for an iphone. Iphone has a built in compass. I got a plugin that detects the compass as well as returns values. Based on those values
i want to be able to drag the panel left and right controlled by the compass.

Essentially, I want to achieve an action where I can make the panel draggable with the compass without using any touch events.

One approach,that i thought of is if i can drag the panel in code and then with compass reading i can set those values to drag the panel.

« Last Edit: September 22, 2012, 09:46:24 PM by sk1989 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting Drag position
« Reply #2 on: September 23, 2012, 09:28:25 AM »
I'm still not quite clear on what it is you're trying to do. o_O

sk1989

  • Guest
Re: Setting Drag position
« Reply #3 on: September 23, 2012, 07:24:42 PM »
okay Ill explain it again.

Basically all I want is to drag the panel using the compass. How can i do that with NGUI?

How can i manually drag the panel in code, that is my question


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting Drag position
« Reply #4 on: September 24, 2012, 08:12:03 AM »
I see. My suggestion is don't use a draggable panel for this. Draggable panel is for user input, and since you're providing manual input, you don't need it. The slow but simple approach would be to simply move the root object directly underneath the panel. For example if you had this layout:

UIPanel (clipped)
- Root Object <-- move this around
---Widget 1
---Widget 2
---Widget 3

The faster approach would be to adjust the clipping rect of the clipped UIPanel at the same time as its position (by the opposite value), same as UIDraggablePanel does it. This approach doesn't involve rebuilding of geometry, which is why it's faster.

sk1989

  • Guest
Re: Setting Drag position
« Reply #5 on: September 24, 2012, 09:06:48 PM »
I dont understand what you mean by move the root object underneath the panel. The root object in my scene would be the UIGrid.


and in the fas approach how do you adjust clipping rect of the clipped UI panel ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting Drag position
« Reply #6 on: September 25, 2012, 08:04:28 AM »
Everything should still be under UIRoot. Here is the full hierarchy to be clear:

UIRoot
-- UICamera
---- UIAnchor
------ UIPanel
-------- Root Object <-- move this around
---------- Widget 1
---------- Widget 2
---------- Widget 3