FPSConfigView.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Experimental.StreammingCast
  10. {
  11. using UnityEngine;
  12. using UnityEngine.UI;
  13. public class FPSConfigView : MonoBehaviour
  14. {
  15. public SettingRegionTrigger m_TriggerRegion;
  16. public delegate void OnButtonClick(FirstPersonStreammingCast.OnResponse response);
  17. public event OnButtonClick OnStreamBtnClicked;
  18. public event OnButtonClick OnRecordBtnClicked;
  19. public Button m_StreamBtn;
  20. public Button m_RecordBtn;
  21. public Transform m_PanelRoot;
  22. public Color NormalColor;
  23. public Color ActiveColor;
  24. void Start()
  25. {
  26. m_StreamBtn.onClick.AddListener(() =>
  27. {
  28. OnStreamBtnClicked?.Invoke(OnStreamButtonResponse);
  29. });
  30. m_RecordBtn.onClick.AddListener(() =>
  31. {
  32. OnRecordBtnClicked?.Invoke(OnRecordButtonResponse);
  33. });
  34. m_TriggerRegion.onPointerEnter.AddListener(ShowPanel);
  35. m_TriggerRegion.onPointerOut.AddListener(HidePanel);
  36. HidePanel();
  37. }
  38. private bool m_IsRecordButtonActive = false;
  39. private void OnRecordButtonResponse(bool result)
  40. {
  41. if (!result)
  42. {
  43. return;
  44. }
  45. m_IsRecordButtonActive = !m_IsRecordButtonActive;
  46. m_RecordBtn.GetComponent<Image>().color = m_IsRecordButtonActive ? ActiveColor : NormalColor;
  47. m_StreamBtn.gameObject.SetActive(!m_IsRecordButtonActive);
  48. HidePanel();
  49. }
  50. private bool m_IsStreamButtonActive = false;
  51. private void OnStreamButtonResponse(bool result)
  52. {
  53. if (!result)
  54. {
  55. return;
  56. }
  57. m_IsStreamButtonActive = !m_IsStreamButtonActive;
  58. m_StreamBtn.GetComponent<Image>().color = m_IsStreamButtonActive ? ActiveColor : NormalColor;
  59. m_RecordBtn.gameObject.SetActive(!m_IsStreamButtonActive);
  60. HidePanel();
  61. }
  62. /// <summary> Shows the panel. </summary>
  63. private void ShowPanel()
  64. {
  65. m_PanelRoot.gameObject.SetActive(true);
  66. }
  67. /// <summary> Hides the panel. </summary>
  68. private void HidePanel()
  69. {
  70. // m_PanelRoot.gameObject.SetActive(false);
  71. }
  72. }
  73. }