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.

60 lines
1.9 KiB

  1. namespace VRTK.Examples.PanelMenu
  2. {
  3. // Panel Menu UI Slider
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using VRTK;
  7. /// <summary>
  8. /// Demo component for example scene.
  9. /// </summary>
  10. /// <example>
  11. /// See the demo scene for a complete example: [ 040_Controls_Panel_Menu ]
  12. /// </example>
  13. public class PanelMenuUISlider : MonoBehaviour
  14. {
  15. #region Variables
  16. private Slider slider;
  17. #endregion Variables
  18. #region Unity Methods
  19. private void Start()
  20. {
  21. slider = GetComponent<Slider>();
  22. if (slider == null)
  23. {
  24. VRTK_Logger.Warn(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "PanelMenuUISlider", "Slider", "the same"));
  25. return;
  26. }
  27. GetComponentInParent<VRTK_PanelMenuItemController>().PanelMenuItemSwipeLeft += new PanelMenuItemControllerEventHandler(OnPanelMenuItemSwipeLeft);
  28. GetComponentInParent<VRTK_PanelMenuItemController>().PanelMenuItemSwipeRight += new PanelMenuItemControllerEventHandler(OnPanelMenuItemSwipeRight);
  29. }
  30. #endregion Unity Methods
  31. #region UI Events
  32. private void OnPanelMenuItemSwipeLeft(object sender, PanelMenuItemControllerEventArgs e)
  33. {
  34. slider.value -= 1;
  35. SendMessageToInteractableObject(e.interactableObject);
  36. }
  37. private void OnPanelMenuItemSwipeRight(object sender, PanelMenuItemControllerEventArgs e)
  38. {
  39. slider.value += 1;
  40. SendMessageToInteractableObject(e.interactableObject);
  41. }
  42. private void SendMessageToInteractableObject(GameObject interactableObject)
  43. {
  44. interactableObject.SendMessage("UpdateSliderValue", slider.value);
  45. }
  46. #endregion UI Events
  47. }
  48. }