Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. using VRTK.Controllables;
  5. using VRTK.Controllables.PhysicsBased;
  6. using VRTK.Controllables.ArtificialBased;
  7. public class ButtonReactor : MonoBehaviour
  8. {
  9. protected VRTK_PhysicsPusher buttonEvents;
  10. protected VRTK_ArtificialPusher artbuttonEvents;
  11. protected virtual void OnEnable()
  12. {
  13. buttonEvents = GetComponent<VRTK_PhysicsPusher>();
  14. if (buttonEvents != null)
  15. {
  16. buttonEvents.MaxLimitReached += MaxLimitReached;
  17. }
  18. artbuttonEvents = GetComponent<VRTK_ArtificialPusher>();
  19. if (artbuttonEvents != null)
  20. {
  21. artbuttonEvents.MaxLimitReached += MaxLimitReached;
  22. }
  23. }
  24. protected virtual void OnDisable()
  25. {
  26. if (buttonEvents != null)
  27. {
  28. buttonEvents.MaxLimitReached -= MaxLimitReached;
  29. }
  30. if (artbuttonEvents != null)
  31. {
  32. artbuttonEvents.MaxLimitReached -= MaxLimitReached;
  33. }
  34. }
  35. protected virtual void MaxLimitReached(object sender, ControllableEventArgs e)
  36. {
  37. VRTK_BaseControllable senderButton = sender as VRTK_BaseControllable;
  38. VRTK_Logger.Info(senderButton.name + " was pushed");
  39. }
  40. }
  41. }