NibiruShutDownBox.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using Nxr.Internal;
  2. using UnityEngine;
  3. public class NibiruShutDownBox : MonoBehaviour
  4. {
  5. public static NibiruShutDownBox Instance;
  6. private GameObject shutDownBox;
  7. private Transform shutDownBoxTrans;
  8. private MeshRenderer[] choiceMeshRenderers;
  9. private MeshRenderer closeMeshRenderer;
  10. private TextMesh[] textMeshes;
  11. private float time, timeEnd;
  12. private bool isShow;
  13. public bool Showing()
  14. {
  15. return isShow;
  16. }
  17. void Start()
  18. {
  19. timeEnd = 4f;
  20. isShow = false;
  21. Instance = this;
  22. choiceMeshRenderers = new MeshRenderer[2];
  23. textMeshes = new TextMesh[2];
  24. }
  25. void CloseBox()
  26. {
  27. if (TouchScreenKeyboard.visible || NxrViewer.Instance.GetDevice().GetEnableSystemDialog()==1) return;
  28. NibiruRemindBox.Instance.ReleaseDestory();
  29. if (!shutDownBox)
  30. {
  31. shutDownBox = Instantiate(Resources.Load<GameObject>("RemindBox/ShutDownBox"));
  32. shutDownBoxTrans = shutDownBox.transform;
  33. for (var i = 0; i < choiceMeshRenderers.Length; i++)
  34. {
  35. choiceMeshRenderers[i] =
  36. shutDownBoxTrans.Find("Choice" + (i + 1) + "/ChoiceBg").GetComponent<MeshRenderer>();
  37. textMeshes[i] = shutDownBoxTrans.Find("Choice" + (i + 1) + "/ChoiceText").GetComponent<TextMesh>();
  38. }
  39. HandleShutDownBox(choiceMeshRenderers[0].gameObject, TurnOff);
  40. HandleShutDownBox(choiceMeshRenderers[1].gameObject, Restart);
  41. closeMeshRenderer = shutDownBoxTrans.Find("Close/CloseBg").GetComponent<MeshRenderer>();
  42. HandleShutDownBox(closeMeshRenderer.gameObject, Close);
  43. textMeshes[0].text = LocalizationManager.GetInstance.GetValue("remindbox_shutdown");
  44. textMeshes[1].text = LocalizationManager.GetInstance.GetValue("remindbox_reboot");
  45. }
  46. else
  47. {
  48. if (!shutDownBox.activeSelf) shutDownBox.gameObject.SetActive(true);
  49. }
  50. var cameraObject = GameObject.Find("MainCamera");
  51. var forward = cameraObject.transform.forward * 3;
  52. shutDownBoxTrans.position = cameraObject.transform.position + forward;
  53. var rotation = cameraObject.transform.rotation;
  54. shutDownBoxTrans.transform.rotation = new Quaternion(rotation.x, rotation.y, 0, rotation.w);
  55. SetAlpha(choiceMeshRenderers[0], 0);
  56. SetAlpha(choiceMeshRenderers[1], 0);
  57. SetAlpha(closeMeshRenderer, 0);
  58. time = 0f;
  59. isShow = true;
  60. }
  61. void HandleShutDownBox(GameObject meshGo, NibiruShutDownBoxEvent.ShutDownBoxEvent action)
  62. {
  63. var nibiruShutDownBoxEvent = meshGo.GetComponent<NibiruShutDownBoxEvent>();
  64. nibiruShutDownBoxEvent.handleShutDownBox = action;
  65. }
  66. void SetAlpha(MeshRenderer meshRenderer, float alpha)
  67. {
  68. var color = meshRenderer.material.color;
  69. meshRenderer.material.color = new Color(color.r, color.g, color.b, alpha);
  70. }
  71. /// <summary>
  72. /// Shutdown
  73. /// </summary>
  74. void TurnOff()
  75. {
  76. NxrViewer.Instance.TurnOff();
  77. ReleaseDestory();
  78. }
  79. /// <summary>
  80. /// Reboot
  81. /// </summary>
  82. void Restart()
  83. {
  84. NxrViewer.Instance.Reboot();
  85. ReleaseDestory();
  86. }
  87. /// <summary>
  88. /// Close page.
  89. /// </summary>
  90. void Close()
  91. {
  92. ReleaseDestory();
  93. }
  94. public void ReleaseDestory()
  95. {
  96. if (shutDownBox)
  97. {
  98. // Destroy(shutDownBox);
  99. shutDownBox.gameObject.SetActive(false);
  100. isShow = false;
  101. }
  102. }
  103. void Update()
  104. {
  105. #if UNITY_EDITOR
  106. if (Input.GetKeyDown(KeyCode.R))
  107. {
  108. CloseBox();
  109. }
  110. #endif
  111. if (isShow)
  112. {
  113. time += Time.deltaTime;
  114. if (time >= timeEnd)
  115. {
  116. ReleaseDestory();
  117. NxrReticle mNxrReticle = NxrViewer.Instance.GetNxrReticle();
  118. if (mNxrReticle) mNxrReticle.OnGazeExit(null, null);
  119. }
  120. }
  121. }
  122. }