Author Topic: Working with UI drag panel ... Resetting an item position in the panel  (Read 17101 times)

sk1989

  • Guest
Hi i just wanna how to do something with UI Drag panel.

I created a UI drag panel and I added some items which are buttons to it. so far everything works great, the panel is scrolling fine with the buttons loaded.
Now my question is, I want to make each button in the panel to reset to the position where the panel originally loads the buttons at the beginning  of the game, and I want it so that this action should only happen when any button is selected. The button that is selected, i want it to re position it anywhere in the panel I want. How can I achieve this behavior? 

I hope you guys understand what I am looking for here.

Anyone know how to do this can please help him and thanks in advance to all the help. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Honestly -- no, I am not entirely sure what you're trying to do. Resetting to the beginning of a dragged panel can be achieved via UIDraggablePanel.ResetPosition(), however moving a widget inside that panel will change the bounds of that panel, so that may have adverse effects on the dragging process to begin with.

sk1989

  • Guest
Sorry, I will clarify what I am trying to do and hopefully someone can help me.

I have created a Drag Panel, which consists of a column of different buttons. All of the buttons are connected within the Drag Panel, so if I were to drag one button upwards, the rest of the buttons will follow. What I am trying to do, is when I select a particular button from that column, therefore setting it to active, it will snap to the center of the Drag Panel.

For Example: If I have 4 buttons which are dragged to the top of the screen, if I were to select the second button of that column, it would automatically center that button, having that selected button at the Drag Panel's local position of (0,0,0) , assuming that is the center. Once it is at the center location, label information will be generated to the left of that centered button, displaying additional information about what is selected.

I hope this clears it up, thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Pictures would be helpful. Why do you need a drag panel for this?

sk1989

  • Guest
Hope that helps understand my situation
« Last Edit: July 18, 2012, 12:57:34 PM by sk1989 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Skyrim style UI. All you had to say.

When you get OnPress(false) on your button (can also try OnClick), use SpringPanel to move the panel so that your button is centered. I can't tell you what offset to use here as it's math-related at this point, and you'll have to experiment.

sk1989

  • Guest
how do i change the button position using spring panel in terms code wise.

sk1989

  • Guest
right now I have

if(onSelect = false)

i have SpringPanel.Begin(btton.gameobj,what is the position for, so as the strength)

PhilipC

  • Guest
the position is the position you wish the object to spring to.
the strength is how strong of a pull you want. i.e. higher the value faster it will move.

sk1989

  • Guest
Oh okay that makes sense, but the thing is, i don't want just that object to spring to a position, i want the whole panel to to move with it.

Because rite now the object that I am springing, it overlaps with the other buttons in the panel.

How do i get it so that the whole panel moves as the object springs to a position.

so that there is no overlapping


and thanks 4 the quick replies

sk1989

  • Guest
At this point, I am springing the drag panel.

When I set the position in the spring.begin(), what part of the drag panel goes to that position that I have set.

Right now, I am stuck with calculating the position for any button that is selected. Because the way I want this behavior to work is if select any button, the drag panel will spring so that the button that iv selected will be in the position that I set.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I made a video explaining how to do this: http://www.youtube.com/watch?v=GZy-uPm42T8

Here is the script from the video.

  1. using UnityEngine;
  2.  
  3. public class CenterOnObject : MonoBehaviour
  4. {
  5.         public UIDraggablePanel dragPanel;
  6.  
  7.         void OnClick ()
  8.         {
  9.                 Vector3 newPos = dragPanel.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position);
  10.                 SpringPanel.Begin(dragPanel.gameObject, -newPos, 8f);
  11.         }
  12. }

tinyutopia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
I guess my question is semi-related to this. I simply want a drag panel to reset to it's own starting position when another button is pressed.

I'm using one panel for different categories populated by arrays, but when one panel is down at the bottom, and the other does not have the same number of objects, you can't see the new arrays items.

If I could just use UIDraggablePanel.ResetPosition it might solve this. But I've tried getting the reference to the script by using:

public UIDraggablePanel  panel;
panel = GetComponent<UIDraggablePanel>();

then

panel.ResetPosition ();


but I get a null exception when trying it this way.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
If the value is public, then you should set it via drag & dropping in inspector. GetComponent will attempt to find it only on the object you attached this script to.

sk1989

  • Guest
That is exactly what i wanted and It works now. 

thanks alot for putting the video together and appreciate the fast reply.