PlaylistSelectionNavigationController.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using VRUI;
  5. namespace SongBrowserPlugin.UI
  6. {
  7. class PlaylistSelectionNavigationController : VRUINavigationController
  8. {
  9. public const String Name = "PlaylistSelectionMasterViewController";
  10. public Action didDismissEvent;
  11. private Button _dismissButton;
  12. private Logger _log = new Logger(Name);
  13. /// <summary>
  14. /// Override DidActivate to inject our UI elements.
  15. /// </summary>
  16. protected override void DidActivate(bool firstActivation, VRUIViewController.ActivationType activationType)
  17. {
  18. _log.Debug("DidActivate()");
  19. base.DidActivate(firstActivation, activationType);
  20. if (firstActivation)
  21. {
  22. }
  23. if (activationType == VRUIViewController.ActivationType.AddedToHierarchy)
  24. {
  25. _log.Debug("Adding Dismiss Button");
  26. _dismissButton = UIBuilder.CreateBackButton(this.rectTransform);
  27. _dismissButton.onClick.AddListener(HandleDismissButton);
  28. }
  29. }
  30. /// <summary>
  31. ///
  32. /// </summary>
  33. private void HandleDismissButton()
  34. {
  35. try
  36. {
  37. _log.Debug("Dismissing...");
  38. didDismissEvent.Invoke();
  39. }
  40. catch (Exception e)
  41. {
  42. _log.Exception("HandleDismissButton Exception: ", e);
  43. }
  44. }
  45. /// <summary>
  46. ///
  47. /// </summary>
  48. private void CheckDebugUserInput()
  49. {
  50. // leave
  51. if (Input.GetKeyDown(KeyCode.Escape))
  52. {
  53. _dismissButton.onClick.Invoke();
  54. }
  55. }
  56. /// <summary>
  57. ///
  58. /// </summary>
  59. private void LateUpdate()
  60. {
  61. if (!this.isActiveAndEnabled) return;
  62. CheckDebugUserInput();
  63. }
  64. }
  65. }