Found a solution!
Hello there,
this is my first post, so im not sure if this is the right category.
Quick Summary
- I have a custom virtual mouse.
- I can interact with unity UI elements with pointerDownHandler events.
- It works perfect for UI Sliders
- It does not work for UI Scrollbars
- except I trigger a dragHandler event after the pointerDownHandler event.
- But the real mouse only needs the pointerDownHandler
- Why?
/--------------Complete Details------------------/
My Goal
I want to create a custom virtual mouse on my own.
So far it works pretty well. I use the pointerDownHandler events and all of its “brothers and sisters” like dragHandler and so on.
I can now interact with my “custom virtual mouse” with all kinds of button, sliders and other UI elements.
I can use different kinds of Input Devices.
All fine, smooth and perfect.
/---------------------------------------/
Normal Unity Mouse behavior
When I click on a Scrollbar UI element with the mouse, the handle will jump to the mouse location as close as possible, it uses steps of 0.2 and moves to the nearest value of the mouse click.
The mouse will trigger the following events
- OnPointerDown —> This one will move the Scrollbar handle.
- OnInitializePotentialDrag
When the left mouse button was released - OnPointerUp
- OnPointerClick
/---------------------------------------/
Problem
When I use my custom virtual mouse, which will execute the same events like a normal mouse in the same order, then it does not work for Scrollbars. Very confusing to my self it works out of the box with UI Sliders…
The Scrollbar value will stay at zero, if i debug the valueChange event of the scrollbar element I receive negative values of -0.2
It only works with a workaround of triggering a “dragHandler Event” after the “pointerDownHandler” event.
void OnPointerDown(){
isPointerDown = true;
isBeginnDropHandler = true;
// pointer.position = gameObject.transform.position;
ExecuteEvents.Execute(target, pointer, ExecuteEvents.pointerDownHandler);
ExecuteEvents.Execute(target, pointer, ExecuteEvents.initializePotentialDrag);
/* Dont know why i have do to this,
* because for the slider it works but the scrollbar always delivers negative values of -2
* and the handle always stays on 0
*/
if(target.GetComponent<Scrollbar>() is not null){
ExecuteEvents.Execute(target, pointer, ExecuteEvents.beginDragHandler);
ExecuteEvents.Execute(target, pointer, ExecuteEvents.dragHandler);
}
Does someone know why?
[/quote]
Hello there,
this is my first post, so im not sure if this is the right category.
Quick Summary
- I have a custom virtual mouse.
- I can interact with unity UI elements with pointerDownHandler events.
- It works perfect for UI Sliders
- It does not work for UI Scrollbars
- except I trigger a dragHandler event after the pointerDownHandler event.
- But the real mouse only needs the pointerDownHandler
- Why?
/--------------Complete Details------------------/
My Goal
I want to create a custom virtual mouse on my own.
So far it works pretty well. I use the pointerDownHandler events and all of its “brothers and sisters” like dragHandler and so on.
I can now interact with my “custom virtual mouse” with all kinds of button, sliders and other UI elements.
I can use different kinds of Input Devices.
All fine, smooth and perfect.
/---------------------------------------/
Normal Unity Mouse behavior
When I click on a Scrollbar UI element with the mouse, the handle will jump to the mouse location as close as possible, it uses steps of 0.2 and moves to the nearest value of the mouse click.
The mouse will trigger the following events
- OnPointerDown —> This one will move the Scrollbar handle.
- OnInitializePotentialDrag
When the left mouse button was released - OnPointerUp
- OnPointerClick
/---------------------------------------/
Problem
When I use my custom virtual mouse, which will execute the same events like a normal mouse in the same order, then it does not work for Scrollbars. Very confusing to my self it works out of the box with UI Sliders…
The Scrollbar value will stay at zero, if i debug the valueChange event of the scrollbar element I receive negative values of -0.2
It only works with a workaround of triggering a “dragHandler Event” after the “pointerDownHandler” event.
void OnPointerDown(){
isPointerDown = true;
isBeginnDropHandler = true;
// pointer.position = gameObject.transform.position;
ExecuteEvents.Execute(target, pointer, ExecuteEvents.pointerDownHandler);
ExecuteEvents.Execute(target, pointer, ExecuteEvents.initializePotentialDrag);
/* Dont know why i have do to this,
* because for the slider it works but the scrollbar always delivers negative values of -2
* and the handle always stays on 0
*/
if(target.GetComponent<Scrollbar>() is not null){
ExecuteEvents.Execute(target, pointer, ExecuteEvents.beginDragHandler);
ExecuteEvents.Execute(target, pointer, ExecuteEvents.dragHandler);
}
Does someone know why?