InputModule.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. using UnityEngine;
  7. using System.Collections;
  8. using UnityEngine.EventSystems;
  9. namespace Valve.VR.InteractionSystem
  10. {
  11. //-------------------------------------------------------------------------
  12. public class InputModule : BaseInputModule
  13. {
  14. private GameObject submitObject;
  15. //-------------------------------------------------
  16. private static InputModule _instance;
  17. public static InputModule instance
  18. {
  19. get
  20. {
  21. if ( _instance == null )
  22. _instance = GameObject.FindObjectOfType<InputModule>();
  23. return _instance;
  24. }
  25. }
  26. //-------------------------------------------------
  27. public override bool ShouldActivateModule()
  28. {
  29. if ( !base.ShouldActivateModule() )
  30. return false;
  31. return submitObject != null;
  32. }
  33. //-------------------------------------------------
  34. public void HoverBegin( GameObject gameObject )
  35. {
  36. PointerEventData pointerEventData = new PointerEventData( eventSystem );
  37. ExecuteEvents.Execute( gameObject, pointerEventData, ExecuteEvents.pointerEnterHandler );
  38. }
  39. //-------------------------------------------------
  40. public void HoverEnd( GameObject gameObject )
  41. {
  42. PointerEventData pointerEventData = new PointerEventData( eventSystem );
  43. pointerEventData.selectedObject = null;
  44. ExecuteEvents.Execute( gameObject, pointerEventData, ExecuteEvents.pointerExitHandler );
  45. }
  46. //-------------------------------------------------
  47. public void Submit( GameObject gameObject )
  48. {
  49. submitObject = gameObject;
  50. }
  51. //-------------------------------------------------
  52. public override void Process()
  53. {
  54. if ( submitObject )
  55. {
  56. BaseEventData data = GetBaseEventData();
  57. data.selectedObject = submitObject;
  58. ExecuteEvents.Execute( submitObject, data, ExecuteEvents.submitHandler );
  59. submitObject = null;
  60. }
  61. }
  62. }
  63. }