Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Tama on June 04, 2014, 07:14:25 AM

Title: Scrollview with slider
Post by: Tama on June 04, 2014, 07:14:25 AM
The example page for NGUI scrollviews http://www.tasharen.com/?page_id=4444 (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 (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?
Title: Re: Scrollview example page out of date
Post by: ArenMook 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
Title: Re: Scrollview example page out of date
Post by: Tama 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)
Title: Re: Scrollview example page out of date
Post by: ArenMook 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.
Title: Re: Scrollview example page out of date
Post by: Tama 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.
Title: Re: Scrollview with slider
Post by: Tama 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.