ViveSoftware / ViveInputUtility-Unity

A toolkit that helps developing/prototyping VR apps.
http://u3d.as/uF7
Other
352 stars 82 forks source link

HTC vive grab button click on pointer enter. #81

Closed junglee372018 closed 5 years ago

junglee372018 commented 5 years ago

Hi, I want to keep pointer on a particular object and click grab button. Grab button click alone is working. when i want to perform grab button click by placing pointer on gameobject it is not working.

my code is like this public void PointerEnter(PointerEventData eventData) { Debug.Log("pointer enter true"); if (ViveInput.GetPressDownEx (HandRole.RightHand, ControllerButton.Grip)) { Debug.Log ("Grab button pressed true"); } }

Kindly help me in getting this solved.

I am using Unity v2018.1.8f1 and VIU v1.9.0

chengnay commented 5 years ago

My quick suggestion to your problem should be have a flag to set to true when pointer entered, then in Update function, check for grip button pressed and the flag is true.

private bool isPointerEntered = false;

void Update() { if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Grip) && isPointerEntered) { Debug.Log("Grab button pressed true"); } }

public void OnPointerEnter(PointerEventData eventData) { Debug.Log("pointer enter true"); isPointerEntered = true; }

public void OnPointerExit(PointerEventData eventData) { Debug.Log("pointer exit true"); isPointerEntered = false; }

Hope this helps, cheers!

junglee372018 commented 5 years ago

Hi chengnay,

Thank You for your reply. I have tried the above process suggested by you. but it is not working. i am not even getting pointer enter and exit logs. Is there any other way to do this?

chengnay commented 5 years ago

You need to attach the script to the gameobject in the scene. By taking the example UGUI, I attach the script the button, image

TestPointer.zip

junglee372018 commented 5 years ago

Yeah did the same. But, I am trying to do this on gameobjects not UI.

snap1

chengnay commented 5 years ago

Do you mind sending me a sample project that I can test on? Thanks!

junglee372018 commented 5 years ago

I forgot to add "IPointerEnterHandler, IPointerExitHandler"

Now its working.

ThankYou very much