Author Topic: Scrollview with slider  (Read 5430 times)

Tama

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Scrollview with slider
« on: June 04, 2014, 07:14:25 AM »
The example page for NGUI scrollviews http://www.tasharen.com/?page_id=4444
refers to some components that don't seem to exist, such as "UIDraggablePanel".

I found a tutorial made in 2013 that addresses this. http://funcodegames.blogspot.nl/2013/08/creating-ngui-scroll-view-with-clipped.html
Sadly, this one also refers to missing component "Draggable Panel"

Could someone show how to make a draggable panel? Preferably demonstrating how buttons work within it as well?
« Last Edit: June 10, 2014, 03:03:25 AM by Tama »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollview example page out of date
« Reply #1 on: June 05, 2014, 12:10:08 AM »
That's very old documentation. NGUI's up-to-date documentation can be found here: http://www.tasharen.com/forum/index.php?topic=6754.0

Tama

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Scrollview example page out of date
« Reply #2 on: June 06, 2014, 09:43:09 AM »
Thanks. However all I could find in there was a simple scrollview example, without any kind of interactive component within.
I'm actually trying to make a scrollview with sliders in it, so that you can move either or both at the same time. (they are restricted to orthogonal directions of course)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollview example page out of date
« Reply #3 on: June 06, 2014, 09:27:07 PM »
Everything inside the scroll view that has a collider needs to have UIDragScrollView attached, not just the background widget. That's all you need to do to have interactable elements and dragging working. Example the drag & drop example -- it lets you drag & drop, and scroll at the same time.

Tama

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Scrollview example page out of date
« Reply #4 on: June 10, 2014, 03:03:09 AM »
I solved my problem with the ugliest code I've ever written. I didn't want to change code in NGUI because it would be overwritten when we update, and because UISlider:OnDragBackground() is not virtual, that meant I had to copy and rename that whole class to override the one function. This allowed me to implement it so that it passes on the value if it is more vertical than horizontal:

protected void OnDragBackground (GameObject go, Vector2 delta)
   {
      if (UICamera.currentScheme == UICamera.ControlScheme.Controller) return;
      mCam = UICamera.currentCamera;
      if ( Math.Abs(delta.y) > Math.Abs(delta.x) ) {
         parentScroller.currentMomentum = new Vector3(0.0f, delta.y*0.003f, 0.0f);

         return;
      }
      value = ScreenToValue(UICamera.lastTouchPosition);
   }

parentScroller is a UIScrollView. It works, but it's a really ugly solution.

Tama

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Scrollview with slider
« Reply #5 on: June 10, 2014, 03:10:17 AM »
The worst part about it is that the OnValueChanged event is no longer triggered. Even without changing the code, if you make a copy of UISlider, rename it, put it into the scene with an event listener on value changed, it will not fire.

So I've solved this issue for now in the ugliest way possible; by changing UISlider itself... *shudder*
I hope you can help me figure out how to do this properly.
« Last Edit: June 10, 2014, 04:17:57 AM by Tama »