InstructionsHandler.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using UnityEngine;
  2. using UnityEngine.Assertions;
  3. using UnityEngine.UI;
  4. namespace Google.Maps.Examples.Shared {
  5. /// <summary>
  6. /// This class controls the behavior of the instructions panel.
  7. /// It also adjusts the instructions displayed on screen based on the platform where
  8. /// the example is running.
  9. ///
  10. /// The Instructions component has two states controlled by the help button.
  11. /// When the button is clicked on, the instruction dialog is displayed,
  12. /// and The help button is disabled.
  13. /// When the dialog is closed, we re-activate the help button.
  14. ///
  15. /// This approach optimizes the UI real estate for the example.
  16. ///
  17. /// </summary>
  18. public class InstructionsHandler : MonoBehaviour {
  19. /// <summary>
  20. /// Information text adjusted depending on deployed platform.
  21. /// </summary>
  22. public Text InstructionsText;
  23. /// <summary>
  24. /// Dialog box controlled by the help button.
  25. /// </summary>
  26. public GameObject InstructionsDialog;
  27. /// <summary>
  28. /// Reference to Help button.
  29. /// </summary>
  30. public GameObject HelpButton;
  31. /// <summary>
  32. /// Glass panel used to block events when dialog is on.
  33. /// </summary>
  34. public GameObject GlassPanel;
  35. [Multiline]
  36. public string InstructionsContent =
  37. "Arrow keys for pitch and yaw.\nWSAD to move.\nQE for height." +
  38. "\n\nClick anywhere to close.";
  39. /// <summary>
  40. /// At start, update the instructions text based on the target platform,
  41. /// and hide the Instructions Dialog.
  42. /// </summary>
  43. private void Start() {
  44. Assert.IsNotNull(InstructionsText, "Instructions Text is not set!");
  45. Assert.IsNotNull(InstructionsDialog, "Instructions Dialog is not set!");
  46. Assert.IsNotNull(HelpButton, "Help button is not set!");
  47. Assert.IsNotNull(GlassPanel, "GlassPanel is not set!");
  48. InstructionsText.text = InstructionsContent;
  49. #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
  50. InstructionsText.text =
  51. "Drag knob to move and rotate.\nUp and Down buttons for elevation." +
  52. "\nGyroscope for pitch. \nPinch screen to zoom.\n\nTap anywhere to close.";
  53. #endif
  54. ShowHideDialog(false);
  55. }
  56. /// <summary>
  57. /// Event triggered when the help button is clicked on.
  58. /// </summary>
  59. public void OnClick() {
  60. ShowHideDialog(true);
  61. }
  62. /// <summary>
  63. /// Event triggered by any click/touch on the glass panel.
  64. /// </summary>
  65. public void OnClose() {
  66. ShowHideDialog(false);
  67. }
  68. /// <summary>
  69. /// Helper function to hide or show the dialog panel and its associated elements.
  70. /// </summary>
  71. /// <param name="isVisible">Indicates if dialog should be visible or hidden.</param>
  72. private void ShowHideDialog(bool isVisible) {
  73. HelpButton.SetActive(!isVisible);
  74. InstructionsDialog.SetActive(isVisible);
  75. GlassPanel.SetActive(isVisible);
  76. }
  77. }
  78. }