#Controlling a Scrollbar with a custom cursor

1 messages · Page 1 of 1 (latest)

bitter tapir
#

I'll create a thread for this since it's quite important

snow bear
#

Seems like a lot of work for this cursor thing

#

Why not just render a sprite in screen space and raycast through it

bitter tapir
#

It is a lot of work, but its for an assignment and we have been told to control unity UI elements

#

It's for hand tracking and gesture based control with a kinect

snow bear
#

You got this middle man basically thats checking components instead of just getting the info from the event system so you have to access these elements through the script. The behaviour for the scroll probably requires some additional navigational logic I'd assume.

#

If you can't figure how to do it with how youre tracking, probably look into changing the step of the scroll yourself

#

Instead of the attended way if you know what I mean

bitter tapir
#

I'm not entirely sure of what you mean. Do you mean looking to change the value of the slider/scrollbar in a different way to what is used with a normal input?

snow bear
#

Yeah, through the methods of the scrollrect itself. For some reason I can't seem to find non-legacy docs for the damn thing rofl

bitter tapir
#

Yeah, there's not much documentation. I guess it's just not something thats usually done or very efficient to do at all. Do you think changing the value of the slider itself would be a solution?

snow bear
#

Are there any other UI elements giving you trouble with dragging?

bitter tapir
#

Actually, the scrollview works perfectly, but with a different implementation. Would it be useful to show you?

#

The scrollbar and slider don't work with that process for whatever reason though

snow bear
#

Yeah, strange

#

another idea is use the scrollview idea here too

#

and make a dummy scroll bar

#

that's not selectable

#

but tie the progress to the viewport

bitter tapir
snow bear
#
pointer.scrollDelta = (_inputData[i].TempHandPosition - _inputData[i].HandPosition) * _scrollSpeed;```
#

So yeah, that's the idea here with the scroll

#

you'd move it through the script similar to this

bitter tapir
snow bear
#

You're moving the scrollview with the delta here with some custom speed which makes sense since you're not using a mouse. I've not really touched 3D stuff, but that tells me already that using the UI scroll bar needs a similar approach to be implemented.

bitter tapir
#

Right, yes. I've considered that. But for some reason, the scrollbar doesn't seem to have a ScrollHandler interface like the scrollview does. Do you think I'd be able to apply the principle behind the scrollDelta to directly modify the value of the scrollbar in steps?

#

Like, give it a direction depending on TempHandPosition and HandPosition and then multiply that by a speed and change the value with that?

snow bear
#

I know you can change the steps of what is shown on the scrollbar, but actually interacting with it normally I'm not too sure of. My bandaid would be to disable the normal way of controling the scroll and just make it a dummy that's then handled by own specific controller logic.

bitter tapir
#

Sorry, I may not be explaining myself very well, I'm a novice. What I mean is that you can change the value of the scrollbar, as in the position, through code directly. I'm wondering if I could achieve the sliding I want by modifying that and using an adapted scrollDelta method

snow bear
#

2018 docs

#

but im pretty sure these still exists

bitter tapir
#

Yeah, thats what the Scrollview seems to use. I was just looking through the class right now

snow bear
#
  GetComponent<ScrollRect>().content.anchoredPosition += scrollDelta;```
#

Try that idea

#

other than that, I'm not too sure

bitter tapir
#

That would be for a dummy scrollbar that uses a scrollrect, right?

snow bear
#

That's a method on the scrollrect itself

bitter tapir
#

I think I may have found a bit of a cheat. The scrollview, which works with a scrollrect, has two scrollbars whose values are changed when the scrollrect is moved. I could have an empty scrollrect and use it instead of just a slider

#

it feels really cheaty but it should technically work

snow bear
#

Few things too is you do have IScrollHandler

#

and you can change the event system data as so: eventData.scrollDelta

bitter tapir
#

Yes, I think thats the reason the scrollrect works. Neither the slider nor the scrollbar have that interface

snow bear
#

Yeah, this where your own custom controller comes into play

#

and just implement it yourself

bitter tapir
#

Do you mean implementing it into the controller or into the UI elements themselves?

snow bear
#

script on the same element as the scrollrect

#

and then grab the scrollrect component

#

So yeah, either the eventdata scrolldelta or its own positional method. If they don't work, fall back onto the scrollview with the dummy scroll bar ^^

bitter tapir
#

Sounds like a plan. I'll go in that direction. Thank you very much for the brainstorming help and the ideas :)

snow bear
#

Yeah np