Tanoda
VRInputModule.cs
Go to the documentation of this file.
1
4
7{
8 [AddComponentMenu("Event/VR Input Module")]
9 public class VRInputModule : BaseInputModule
10 {
11 public static GameObject targetObject;
12
13 static VRInputModule _singleton;
14
15 private static bool mouseClicked;
16 public static Vector3 cursorPosition;
17
18 protected override void Awake()
19 {
20 _singleton = this;
21 }
22
23 public override void Process()
24 {
25 if (targetObject == null)
26 {
27 mouseClicked = false;
28 return;
29 }
30 }
31
32 public static void PointerSubmit(GameObject obj)
33 {
34 targetObject = obj;
35 mouseClicked = true;
36 if (mouseClicked)
37 {
38 //BaseEventData data = GetBaseEventData(); //Original from Process(). Can't be called here so is replaced by the next line:
39 BaseEventData data = new BaseEventData(_singleton.eventSystem)
40 {
41 selectedObject = targetObject
42 };
43 ExecuteEvents.Execute(targetObject, data, ExecuteEvents.submitHandler);
44 print("clicked " + targetObject.name);
45 mouseClicked = false;
46 }
47 }
48
49 public static void PointerExit(GameObject obj)
50 {
51 print("PointerExit " + obj.name);
52 PointerEventData pEvent = new PointerEventData(_singleton.eventSystem);
53 ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.pointerExitHandler);
54 ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.deselectHandler); //This fixes the problem
55 }
56
57 public static void PointerEnter(GameObject obj)
58 {
59 print("PointerEnter " + obj.name);
60 PointerEventData pEvent = new PointerEventData(_singleton.eventSystem)
61 {
62 pointerEnter = obj
63 };
64 RaycastResult rcr = new RaycastResult() { worldPosition = cursorPosition };
65 pEvent.pointerCurrentRaycast = rcr;
66 ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.pointerEnterHandler);
67 }
68 }
69}
static void PointerSubmit(GameObject obj)
static void PointerEnter(GameObject obj)
static void PointerExit(GameObject obj)
Credit Erdener Gonenc - @PixelEnvision.