IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
InputModule.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Makes the hand act as an input module for Unity's event system
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 using UnityEngine.EventSystems;
10 
11 namespace Valve.VR.InteractionSystem
12 {
13  //-------------------------------------------------------------------------
14  public class InputModule : BaseInputModule
15  {
16  private GameObject submitObject;
17 
18  //-------------------------------------------------
19  private static InputModule _instance;
20  public static InputModule instance
21  {
22  get
23  {
24  if ( _instance == null )
25  _instance = GameObject.FindObjectOfType<InputModule>();
26 
27  return _instance;
28  }
29  }
30 
31 
32  //-------------------------------------------------
33  public override bool ShouldActivateModule()
34  {
35  if ( !base.ShouldActivateModule() )
36  return false;
37 
38  return submitObject != null;
39  }
40 
41 
42  //-------------------------------------------------
43  public void HoverBegin( GameObject gameObject )
44  {
45  PointerEventData pointerEventData = new PointerEventData( eventSystem );
46  ExecuteEvents.Execute( gameObject, pointerEventData, ExecuteEvents.pointerEnterHandler );
47  }
48 
49 
50  //-------------------------------------------------
51  public void HoverEnd( GameObject gameObject )
52  {
53  PointerEventData pointerEventData = new PointerEventData( eventSystem );
54  pointerEventData.selectedObject = null;
55  ExecuteEvents.Execute( gameObject, pointerEventData, ExecuteEvents.pointerExitHandler );
56  }
57 
58 
59  //-------------------------------------------------
60  public void Submit( GameObject gameObject )
61  {
62  submitObject = gameObject;
63  }
64 
65 
66  //-------------------------------------------------
67  public override void Process()
68  {
69  if ( submitObject )
70  {
71  BaseEventData data = GetBaseEventData();
72  data.selectedObject = submitObject;
73  ExecuteEvents.Execute( submitObject, data, ExecuteEvents.submitHandler );
74 
75  submitObject = null;
76  }
77  }
78  }
79 }