Author Topic: Wrap around draggable panel  (Read 4542 times)

subliminalman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Wrap around draggable panel
« on: February 22, 2013, 02:25:46 PM »
So I hope the title makes sense.

Essentially what I am trying to do is have a draggable panel much like the one in the example except that when you get to the end it wraps to the beginning. It must center on the first (or last) object.

Currently I have my gui set up with a grid with 3 objects that center and it does wrap around. The problem is that it does not center on the first (or last) item and goes directly to the middle item.

Here is the script that I am currently using for this (C#)

  1. public UIScrollBar scrollBar;
  2.         public float sliderValue, sliderSize;
  3.         public UIDraggablePanel dragPanel;
  4.         public GameObject springPanel;
  5.         SpringPanel spring;
  6.         public UICenterOnChild center;
  7.         public UIGrid grid;
  8.         void Start()
  9.         {
  10.                 spring = (SpringPanel)springPanel.GetComponent<SpringPanel>();
  11.                 Debug.Log ((spring != null));
  12.                
  13.         }
  14.         public void Update()
  15.         {
  16.                 sliderValue = scrollBar.scrollValue;
  17.                 sliderSize = scrollBar.barSize;
  18.                
  19.                 if(sliderValue == 1 && sliderSize < 0.15) //check if we're all the way to the right
  20.                 {
  21.                         center.enabled = false; //Disable to try to get the closest object on re-enable
  22.                         dragPanel.relativePositionOnReset = Vector2.zero;//position to beginning
  23.                         dragPanel.ResetPosition();
  24.                         spring.target = new Vector3(0, 78, - 1);//try to
  25.                         spring.enabled = true;
  26.                         center.enabled = true;
  27.                        
  28.                 }
  29.                 else if(sliderValue == 0 && sliderSize < 0.15)//check if we're all the way to the left
  30.                 {
  31.                         center.enabled = false;
  32.                         dragPanel.relativePositionOnReset = new Vector2(1, 0);//position to end
  33.                         dragPanel.ResetPosition();     
  34.                         spring.target = new Vector3(-600, 78, - 1);
  35.                         spring.enabled = true;
  36.                         center.enabled = true;
  37.                 }      
  38.         }


Any help would be greatly appreciated