#Controlling a Scrollbar with a custom cursor
1 messages · Page 1 of 1 (latest)
I'll create a thread for this since it's quite important
This is the relevant chunk of code that isn't giving me results https://hatebin.com/ayywicjuoz
Seems like a lot of work for this cursor thing
Why not just render a sprite in screen space and raycast through it
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
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
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?
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
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?
Are there any other UI elements giving you trouble with dragging?
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
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
https://hatebin.com/lzuhwessrw here's the code that works only with the scrollview
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
I'm sorry, could you elaborate a bit? Do you mean using the scrollview to replace the scrollbar?
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.
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?
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.
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
Yeah, thats what the Scrollview seems to use. I was just looking through the class right now
GetComponent<ScrollRect>().content.anchoredPosition += scrollDelta;```
Try that idea
other than that, I'm not too sure
That would be for a dummy scrollbar that uses a scrollrect, right?
That's a method on the scrollrect itself
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
Few things too is you do have IScrollHandler
and you can change the event system data as so: eventData.scrollDelta
Yes, I think thats the reason the scrollrect works. Neither the slider nor the scrollbar have that interface
Yeah, this where your own custom controller comes into play
and just implement it yourself
Do you mean implementing it into the controller or into the UI elements themselves?
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 ^^
Sounds like a plan. I'll go in that direction. Thank you very much for the brainstorming help and the ideas :)
Yeah np