RTCRoomMain.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Blue;
  2. using TMPro;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class RTCRoomMain : SingletonMonobehaviour<RTCRoomMain>, IController
  6. {
  7. [SerializeField] private TextMeshProUGUI mRoomName_Text; // 房间名
  8. [SerializeField] private TextMeshProUGUI mRoomID_Text; // 房间ID
  9. [SerializeField] private TextMeshProUGUI mRoomPeopleCount_Text; // 房间人数
  10. [SerializeField] private Button mVideoOpen_Btn; // 开启视频
  11. [SerializeField] private Button mVideoClose_Btn; // 关闭视频
  12. [SerializeField] private Button mAudioOpen_Btn; // 开启音频
  13. [SerializeField] private Button mAudioClose_Btn; // 关闭音频
  14. [SerializeField] private Button mInvite_Btn; // 邀请用户
  15. [SerializeField] private Button mLeaveRoom; // 离开房间
  16. [SerializeField] private MeshRenderer mBigView_Mesh;
  17. [SerializeField] private RoomOtherUserPanel RoomOtherUserPanel_go;
  18. public GameObject mRoomOtherUser;
  19. public Transform InviteUserPanelPos;
  20. public Texture BigView_MeshTexture
  21. {
  22. set => mBigView_Mesh.material.mainTexture = value;
  23. }
  24. [SerializeField] private RawImage mRawImage_Raw;
  25. public Texture RawImageTexture
  26. {
  27. set => mRawImage_Raw.texture = value;
  28. }
  29. private IRTCService mRTCService;
  30. void Start()
  31. {
  32. mRTCService = this.GetService<IRTCService>();
  33. mVideoOpen_Btn.onClick.AddListener(VideoOpen);
  34. mVideoClose_Btn.onClick.AddListener(VideoClose);
  35. mAudioOpen_Btn.onClick.AddListener(AudioOpen);
  36. mAudioClose_Btn.onClick.AddListener(AudioClose);
  37. mInvite_Btn.onClick.AddListener(Invite);
  38. mLeaveRoom.onClick.AddListener(LeaveRoom);
  39. }
  40. private void OnEnable()
  41. {
  42. Vector3 vSDKSystem = OpenXRCamera.Instance.head.position;
  43. if (DeviceType.type == "Rhinox")
  44. vSDKSystem.y -= 1; // 遂光比较特殊,其他版本不需要
  45. transform.position = new Vector3(vSDKSystem.x + ResetVideoPanal.DifferencePosition.x, vSDKSystem.y + ResetVideoPanal.DifferencePosition.y, vSDKSystem.z + ResetVideoPanal.DifferencePosition.z);
  46. Vector3 pos = OpenXRCamera.Instance.head.position + new Vector3(-1 * (OpenXRCamera.Instance.head.right * 0.7f).x, 0.9f, (OpenXRCamera.Instance.head.forward * 1f).z);
  47. transform.position = new Vector3(pos.x, OpenXRCamera.Instance.head.position.y, pos.z);
  48. transform.eulerAngles = new Vector3(0, -30 + OpenXRCamera.Instance.head.eulerAngles.y, 0);
  49. }
  50. #region UI事件
  51. private void VideoOpen()
  52. {
  53. mRawImage_Raw.gameObject.SetActive(true);
  54. mRawImage_Raw.texture = XRRGBCamera.Instance.CaptureImage;
  55. mRTCService.ActiveVideo(true);
  56. }
  57. private void VideoClose()
  58. {
  59. mRawImage_Raw.gameObject.SetActive(false);
  60. mRTCService.ActiveVideo(false);
  61. }
  62. private void AudioOpen()
  63. {
  64. mRTCService.ActiveAudio(true);
  65. }
  66. private void AudioClose()
  67. {
  68. mRTCService.ActiveAudio(false);
  69. }
  70. private void Invite()
  71. {
  72. ShowRTC.Instance.window[2].SetActive(true);
  73. InviteUserPanel.Instance.TestInitData();
  74. InviteUserPanel.Instance.gameObject.transform.position = RTCRoomMain.Instance.InviteUserPanelPos.position;
  75. InviteUserPanel.Instance.gameObject.transform.eulerAngles = RTCRoomMain.Instance.InviteUserPanelPos.eulerAngles;
  76. }
  77. private void LeaveRoom()
  78. {
  79. mRTCService.LeaveRoom();
  80. ResetData();
  81. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  82. }
  83. #endregion
  84. /// <summary>
  85. /// 离开房间后清理数据及UI
  86. /// </summary>
  87. private void ResetData()
  88. {
  89. InviteUserPanel.Instance.Reset();
  90. RoomOtherUserPanel_go.Reset();
  91. }
  92. }