Interactable.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: This object will get hover events and can be attached to the hands
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using System.Collections;
  9. namespace Valve.VR.InteractionSystem
  10. {
  11. //-------------------------------------------------------------------------
  12. public class Interactable : MonoBehaviour
  13. {
  14. public delegate void OnAttachedToHandDelegate( Hand hand );
  15. public delegate void OnDetachedFromHandDelegate( Hand hand );
  16. [HideInInspector]
  17. public event OnAttachedToHandDelegate onAttachedToHand;
  18. [HideInInspector]
  19. public event OnDetachedFromHandDelegate onDetachedFromHand;
  20. //-------------------------------------------------
  21. private void OnAttachedToHand( Hand hand )
  22. {
  23. if ( onAttachedToHand != null )
  24. {
  25. onAttachedToHand.Invoke( hand );
  26. }
  27. }
  28. //-------------------------------------------------
  29. private void OnDetachedFromHand( Hand hand )
  30. {
  31. if ( onDetachedFromHand != null )
  32. {
  33. onDetachedFromHand.Invoke( hand );
  34. }
  35. }
  36. }
  37. }