Home.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.SceneManagement;
  5. using Agora.Util;
  6. public class Home : MonoBehaviour
  7. {
  8. public InputField AppIdInupt;
  9. public InputField ChannelInput;
  10. public InputField TokenInput;
  11. public AppIdInput AppInputConfig;
  12. public GameObject CasePanel;
  13. public GameObject CaseScrollerView;
  14. public GameObject EventSystem;
  15. private string _playSceneName = "";
  16. private string[] _baseSceneNameList = {
  17. "BasicAudioCallScene",
  18. "BasicVideoCallScene"
  19. };
  20. private string[] _advancedNameList = {
  21. "AudioMixingScene",
  22. "AudioSpectrumScene",
  23. "ChannelMediaRelayScene",
  24. "ContentInspectScene",
  25. "CustomCaptureAudioScene",
  26. "CustomCaptureVideoScene",
  27. "CustomRenderAudioScene",
  28. "DeviceManagerScene",
  29. "DualCameraScene",
  30. "JoinChannelVideoTokenScene",
  31. "JoinChannelWithUserAccountScene",
  32. "MediaPlayerScene",
  33. "MediaPlayerWithCustomDataProviderScene",
  34. "MediaRecorderScene",
  35. "MetadataScene",
  36. "ProcessAudioRawDataScene",
  37. "ProcessVideoRawDataScene",
  38. "PushEncodedVideoImageScene",
  39. "ScreenShareScene",
  40. "ScreenShareWhileVideoCallScene",
  41. "SetBeautyEffectOptionsScene",
  42. "SetEncryptionScene",
  43. "SetVideoEncodeConfigurationScene",
  44. "StartLocalVideoTranscoderScene",
  45. "SpatialAudioWithMediaPlayerScene",
  46. "StartDirectCdnStreamingScene",
  47. "StartRhythmPlayerScene",
  48. //"StartRtmpStreamWithTranscodingScene",
  49. "StreamMessageScene",
  50. "TakeSnapshotScene",
  51. "VirtualBackgroundScene",
  52. "VoiceChangerScene"
  53. };
  54. private void Awake()
  55. {
  56. PermissionHelper.RequestMicrophontPermission();
  57. PermissionHelper.RequestCameraPermission();
  58. GameObject content = GameObject.Find("Content");
  59. var contentRectTrans = content.GetComponent<RectTransform>();
  60. for (int i = 0; i < _baseSceneNameList.Length; i++)
  61. {
  62. var go = Instantiate(CasePanel, content.transform);
  63. var name = go.transform.Find("Text").gameObject.GetComponent<Text>();
  64. name.text = _baseSceneNameList[i];
  65. var button = go.transform.Find("Button").gameObject.GetComponent<Button>();
  66. button.onClick.AddListener(OnJoinSceneClicked);
  67. button.onClick.AddListener(SetScolllerActive);
  68. }
  69. for (int i = 0; i < _advancedNameList.Length; i++)
  70. {
  71. var go = Instantiate(CasePanel, content.transform);
  72. var name = go.transform.Find("Text").gameObject.GetComponent<Text>();
  73. name.text = _advancedNameList[i];
  74. var button = go.transform.Find("Button").gameObject.GetComponent<Button>();
  75. button.onClick.AddListener(OnJoinSceneClicked);
  76. button.onClick.AddListener(SetScolllerActive);
  77. }
  78. if (this.AppInputConfig)
  79. {
  80. this.AppIdInupt.text = this.AppInputConfig.appID;
  81. this.ChannelInput.text = this.AppInputConfig.channelName;
  82. this.TokenInput.text = this.AppInputConfig.token;
  83. }
  84. }
  85. // Start is called before the first frame update
  86. private void Start()
  87. {
  88. }
  89. // Update is called once per frame
  90. private void Update()
  91. {
  92. }
  93. private void OnApplicationQuit()
  94. {
  95. Debug.Log("OnApplicationQuit");
  96. }
  97. public void OnLeaveButtonClicked()
  98. {
  99. StartCoroutine(UnloadSceneAsync());
  100. CaseScrollerView.SetActive(true);
  101. }
  102. public IEnumerator UnloadSceneAsync()
  103. {
  104. if (this._playSceneName != "")
  105. {
  106. AsyncOperation async = SceneManager.UnloadSceneAsync(_playSceneName);
  107. yield return async;
  108. EventSystem.gameObject.SetActive(true);
  109. }
  110. }
  111. public void OnJoinSceneClicked()
  112. {
  113. this.AppInputConfig.appID = this.AppIdInupt.text;
  114. this.AppInputConfig.channelName = this.ChannelInput.text;
  115. this.AppInputConfig.token = this.TokenInput.text;
  116. var button = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
  117. var sceneName = button.transform.parent.Find("Text").gameObject.GetComponent<Text>().text;
  118. EventSystem.gameObject.SetActive(false);
  119. SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
  120. this._playSceneName = sceneName;
  121. }
  122. public void SetScolllerActive()
  123. {
  124. CaseScrollerView.SetActive(false);
  125. }
  126. }