Unity VR Controller UI Interaction

蓝咒 提交于 2019-12-08 03:33:36

问题


I'm currently at the verge of a mental breakdown. I spent hours building my own laser pointer, making it shoot raycasts on everything and try to make it work with my UI. But it won't. At least not correctly.

What works: Raycast and draw line.

Where I struggle: Right now I have two options. A) Standard UI button and cube without mesh renderer to it. This makes the button fade thru its animations according to its button script. BUT it won't resolve the On button click events! So I added an event trigger onto the button - which... will indeed trigger the "pointer enter" events! But not its "pointer click" events :(

So what I thought: my click must be implemented wrong! To test this: B) Added an event trigger to the cube, that's the buttons collider. Set it to "pointer click". And tada! it works! BUUUUT this kills the animation of the button! Why?

Thankful for any ideas! I'd also take new startpoints into consideration, if you have a good hint!

Next issue are sliders. Any tipps on how to make them work?

Thanks for any help!!

Cheers Flo

Edit: current code:

        {//Record this data and tell the object that we are pointing at them (OnPointerEnter)
        eventData.pointerEnter = rayHit.transform.gameObject;
        ExecuteEvents.ExecuteHierarchy(eventData.pointerEnter, eventData, ExecuteEvents.pointerEnterHandler);


        //If trigger becomes state down ...
        if (SteamVR_Actions._default.GrabPinch.GetStateDown(handType) && eventData.pointerEnter != null)
        {
            //...tell the object that we have pressed it (OnPointerDown)
            eventData.pointerPressRaycast = eventData.pointerCurrentRaycast;
            eventData.pointerPress = ExecuteEvents.ExecuteHierarchy(eventData.pointerEnter, eventData, ExecuteEvents.pointerDownHandler);
        }
        //Otherwise, if we just released the primary input axis...
        else if (SteamVR_Actions._default.GrabPinch.GetStateUp(handType))
        {
            //...tell the object than we have stopped pressing it (OnPointerUp)
            if (eventData.pointerPress != null)
                ExecuteEvents.ExecuteHierarchy(eventData.pointerPress, eventData, ExecuteEvents.pointerUpHandler);

            //...finally, if we pressed and released the same object, then we have clicked it (OnPointerClick)
            if (eventData.pointerPress == eventData.pointerEnter)
                ExecuteEvents.ExecuteHierarchy(eventData.pointerEnter, eventData, ExecuteEvents.pointerClickHandler);

            eventData.pointerPress = null;
        }
    }

回答1:


Without code it's hard to tell, but I think you are overriding the pointer click events with your own? That would explain why the animations are gone. You could resolve it by calling the event on the base class. base.OnPointerClick() or something like that.



来源:https://stackoverflow.com/questions/54900322/unity-vr-controller-ui-interaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!