123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- using LitJson;
- using SUIFW;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Video;
- using XRTool.Util;
- public class RoomMainForms : BaseUIForms
- {
- public static RoomMainForms Instance;
- public static string NOUSER = "nouser";
- public static string userId;
- public bool isSendAudio = true;
- public bool isSendVideo = true;
- public bool isCloseView = true;
- public RawImage bigView;
- public RawImage selfVideo;
- public RawImage jieTuBG;
- public RectTransform TempObj;
- public Button selfVideoBtn;
- public Button uploadBtn;
- public Button switchBtn;
- public Button guaDuanBtn;
- public Button inviteBtn;
- public Button audioOpenBtn;
- public Button audioCloseBtn;
- public Button videoOpenBtn;
- public Button videoCloseBtn;
- public Text titleRoomName;
- public Text titleRoomNum;
- public Text titleRoomPeopleCount;
- public Button openCoordinateBtn;
- public Button closeCoordinateBtn;
- public GameObject AllUserBtn;
- public GameObject AllNeedHideUI;
- public GameObject AllNeedShowUI;
- public bool isOpen = false;
- public Text userNumText;
- public bool isSwithVideo = false;
- public GameObject UpFilePop;
- public Button upImageBtn;
- public Button upVideoBtn;
- public Button cancelBtn;
- public GameObject Invite;
- private void Awake()
- {
- Instance = this;
- WSHandler.Rtc.onRtcState += onRtcState;
- WSHandler.Rtc.OnChangeOwner += ChangeOwner;
- guaDuanBtn.onClick.AddListener(ClickOnGuaDuan);
- audioOpenBtn.onClick.AddListener(()=> { sendAudio(true); } );
- audioCloseBtn.onClick.AddListener(()=> { sendAudio(false); });
- videoOpenBtn.onClick.AddListener(()=> { sendVideo(true); });
- videoCloseBtn.onClick.AddListener(() => { sendVideo(false); });
- openCoordinateBtn.onClick.AddListener(ClickOnOpenCoordinate);
- closeCoordinateBtn.onClick.AddListener(ClickOnCloseCoordinate);
- switchBtn.onClick.AddListener(Swith);
- selfVideoBtn.onClick.AddListener(CkickOnSelfVideoBtn);
- upImageBtn.onClick.AddListener(CallAndroidImage);
- upVideoBtn.onClick.AddListener(CallAndroidVideo);
- cancelBtn.onClick.AddListener(ClickOnCanel);
- uploadBtn.onClick.AddListener(ClickOnUpFileBtn);
- inviteBtn.onClick.AddListener(ClickInviteBtn);
- }
- private void Start()
- {
- OpenBlack();
-
- }
-
- private void Update()
- {
- if (userId != NOUSER)
- {
- if (isOpen)
- {
- if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
- {
- Debug.Log(Input.GetTouch(0).position.x + "AAA" + Input.GetTouch(0).position.y);
- Debug.Log(Screen.width + "BBB" + Screen.height);
- string x = (Input.GetTouch(0).position.x / Screen.width).ToString();
- string y = ((Screen.height - Input.GetTouch(0).position.y) / Screen.height).ToString();
- Debug.Log(x + "CCC" + y);
- WSHandler.Rtc.coordinate(10000, x, y, userId);
- }
- }
- else
- {
- if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
- {
- Debug.Log(Input.GetTouch(0).position.x + "DDD" + Input.GetTouch(0).position.y);
- Debug.Log(Screen.width + "EEE" + Screen.height);
- string x = (Input.GetTouch(0).position.x / Screen.width).ToString();
- string y = ((Screen.height - Input.GetTouch(0).position.y) / Screen.height).ToString();
- Debug.Log(x + "FFF" + y);
- WSHandler.Rtc.coordinate(10001, x, y, userId);
- }
- }
- }
-
- }
- private void OnEnable()
- {
- Screen.orientation = ScreenOrientation.LandscapeLeft;
- sendAudio(UserInfo.systemDatas.Mic == 1 ? true : false);
- sendVideo(UserInfo.systemDatas.Camera == 1 ? true : false);
- }
- private void OnDisable()
- {
- Screen.orientation = ScreenOrientation.Portrait;
- }
- #region 窗体生命周期
- public override void Display()
- {
- base.Display();
- Init();
- }
- public override void Redisplay()
- {
- base.Redisplay();
- }
- public override void Freeze()
- {
- base.Freeze();
- }
- public override void Hiding()
- {
- base.Hiding();
- }
- #endregion
- public void Init()
- {
- AllNeedHideUI.SetActive(true);
- isSwithVideo = false;
- setBigView(RemoteRtc.Instance.NoUser, NOUSER);
- AllUserBtn.SetActive(false);
- if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
- {
- titleRoomName.text = RoomMainInfo.RoomOwner;
- }
- titleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + RoomMainInfo.roomMaxPeopleNum;
- userNumText.text = (RoomMainInfo.roomPeopleNum - 1).ToString();
- titleRoomNum.text = "房间号:" + RoomMainInfo.roomNum;
- AgoraVideoAudioManager.Instance.SetChinnelName(RoomMainInfo.roomNum);
- AgoraVideoAudioManager.Instance.JoinChannel();
- isSendAudio = CustomInfo.isSendAudio;
- isSendVideo = CustomInfo.isSendVideo;
- isCloseView = CustomInfo.isCloseView;
- if (isSendAudio)
- {
- TimerMgr.Instance.CreateTimer(() => {
- RemoteRtc.Instance.sendMic(true);
- }, 1f);
- }
- if (isSendVideo)
- {
- TimerMgr.Instance.CreateTimer(() => {
- RemoteRtc.Instance.startCamera();
- RemoteRtc.Instance.sendVideo(true);
- }, 1f);
- }
- change();
- isOpen = false;
- openCoordinateBtn.gameObject.SetActive(true);
- closeCoordinateBtn.gameObject.SetActive(false);
- if (RoomOtherUser.Instance)
- {
- RoomOtherUser.Instance.UpdateList();
- }
- if (RoomFile.Instance)
- {
- RoomFile.Instance.Init();
- }
- if (UserInfo.systemDatas.Camera==1)
- StartCoroutine(ShowLoacalVideo(2f));
- }
- IEnumerator ShowLoacalVideo( float times)
- {
- yield return new WaitForSeconds(times);
- AgoraVideoAudioManager.Instance.ShowLocalView(selfVideo);
- }
- public void ShowOneVideo()
- {
- // AgoraVideoAudioManager.Instance.ShowOneView(bigView);
- }
- public void ShowUserBtns()
- {
- AllUserBtn.SetActive(true);
- }
- public void HideUserBtns()
- {
- AllUserBtn.SetActive(false);
- }
- private void ChangeOwner(JsonData data)
- {
- string peerId = data["data"]["peerId"].ToString();
- string nickName = data["data"]["nickName"].ToString();
- string isCreator = data["data"]["isCreator"].ToString();
- if (peerId == UserInfo.UnionId && isCreator == "1")
- {
- RoomMainInfo.isCreator = "0";
- RoomMainInfo.RoomOwner = "用户" + nickName + "的房间";
- //if (FileList.Instance && RoomFile.Instance)
- //{
- // if (FileList.Instance.transform.childCount > 0)
- // {
- // RoomFile.Instance.ShowClearBtn();
- // }
- //}
- }
- titleRoomName.text = "用户" + nickName + "的房间";
- titleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + 10;
- RoomOtherUser.Instance.UpdateList();
- }
- public void setBigView(Texture tex, string id)
- {
- if (id != NOUSER)
- {
- CustomPeer cPeer = (CustomPeer)RemoteRtc.Instance.customPeerList.getPeer(id);
- if (cPeer.isCloseVideo || !cPeer.isVideo)
- {
- ClickOnCloseCoordinate();
- tex = RemoteRtc.Instance.NoView;
- }
- RoomOtherUser.ShowAction?.Invoke(id);
- }
- userId = id;
- // bigView.texture = tex;
- }
- private string dcetype;
- private void onRtcState(string str)
- {
- if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
- {
- titleRoomName.text = RoomMainInfo.RoomOwner;
- }
- titleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + RoomMainInfo.roomMaxPeopleNum;
- userNumText.text = (RoomMainInfo.roomPeopleNum - 1).ToString();
- titleRoomNum.text = "房间号:" + RoomMainInfo.roomNum;
- switch (str)
- {
- case "closeProducer":
- if (dcetype == "video")
- {
- RemoteRtc.Instance.me.cIdV = "";
- }
- else
- {
- RemoteRtc.Instance.me.cIdA = "";
- }
- break;
- }
- }
- void change()
- {
- if (isSendVideo)
- {
- videoOpenBtn.gameObject.SetActive(false);
- videoCloseBtn.gameObject.SetActive(true);
- }
- else
- {
- videoOpenBtn.gameObject.SetActive(true);
- videoCloseBtn.gameObject.SetActive(false);
- }
- if (isSendAudio)
- {
- audioOpenBtn.gameObject.SetActive(false);
- audioCloseBtn.gameObject.SetActive(true);
- }
- else
- {
- audioOpenBtn.gameObject.SetActive(true);
- audioCloseBtn.gameObject.SetActive(false);
- }
- }
- public void LeaveRoom()
- {
- WSHandler.roomRtcCloes();
- WSHandler.Office.ChangeUserType(UserInfo.BusyType);
- CloseOrReturnUIForms();
- UIManager.GetInstance().ShowUIForms(SysConst.MainPanelForms);
- if (isswitch)
- {
- OpenBlack();
- }
- //if (InviteDlg.Instance)
- //{
- // InviteDlg.Instance.InvitingUnionIdList.Clear();
- //}
- if (RoomFile.Instance)
- {
- RoomFile.Instance.ClearAllFileItem();
- }
- AgoraVideoAudioManager.Instance.LeaveChannel();
- }
- public void CkickOnSelfVideoBtn()
- {
- isSwithVideo = !isSwithVideo;
- if (isSwithVideo)
- {
- SwitchVideoBig();
- }
- else
- {
- SwitchVideoSmall();
- }
- }
- private void SwitchVideoBig()
- {
- bigView.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 47.51f, 889f);
- bigView.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 169.6f, 500f);
- selfVideo.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);
- selfVideo.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);
- selfVideo.rectTransform.anchorMin = Vector2.zero;
- selfVideo.rectTransform.anchorMax = Vector2.one;
- selfVideo.transform.SetAsFirstSibling();
- }
- private void SwitchVideoSmall()
- {
- selfVideo.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 47.51f, 889f);
- selfVideo.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 169.6f, 500f);
- bigView.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);
- bigView.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);
- bigView.rectTransform.anchorMin = Vector2.zero;
- bigView.rectTransform.anchorMax = Vector2.one;
- bigView.transform.SetAsFirstSibling();
- }
- private void ClickOnOpenCoordinate()
- {
- //if (userId == NOUSER || bigView.texture == RemoteRtc.Instance.NoUser || bigView.texture == RemoteRtc.Instance.NoView)
- //{
- // return;
- //}
- if(userId == NOUSER || bigView.texture== AgoraVideoAudioManager.Instance.bg)
- {
- return;
- }
- else
- {
- isOpen = true;
- openCoordinateBtn.gameObject.SetActive(false);
- closeCoordinateBtn.gameObject.SetActive(true);
- }
- }
- public void ClickOnCloseCoordinate()
- {
- isOpen = false;
- openCoordinateBtn.gameObject.SetActive(true);
- closeCoordinateBtn.gameObject.SetActive(false);
- }
- private void ClickOnGuaDuan()
- {
- ShowUIForms(SysConst.PopForms);
- PopForms.Instance.ShowPublic(PopType.PopTwo, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消");
- }
- private void CallAndroidImage()
- {
- NativeGallery.GetVideoFromGallery((string path) => {
- Debug.Log("Video path: " + path);
- test.path = path;
- WSHandler.Rtc.uploadCert();
- if (RoomMainForms.Instance)
- {
- RoomMainForms.Instance.ClickOnCanel();
- }
- });
- /*
- if (test.Instance)
- {
- test.Instance.CallAndroidImage();
- }*/
- }
- private void CallAndroidVideo()
- {
- NativeGallery.GetImageFromGallery((string path) => {
- Debug.Log("Image path: " + path);
- test.path = path;
- WSHandler.Rtc.uploadCert();
- if (RoomMainForms.Instance)
- {
- RoomMainForms.Instance.ClickOnCanel();
- }
- });
- /*
- if (test.Instance)
- {
- test.Instance.CallAndroidVideo();
- }*/
- }
- private void ClickOnUpFileBtn()
- {
- UpFilePop.SetActive(true);
- }
- public void ClickOnCanel()
- {
- UpFilePop.SetActive(false);
- }
- public void ClickInviteBtn()
- {
- Invite.SetActive(true);
- InviteDlg.Instance.ShowHistory();
- }
- public WebCamTexture webTex;
- private string deviceName;
- private bool isswitch = true;
- IEnumerator CallCamera()
- {
- isswitch = true;
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- deviceName = devices[1].name;
- if (webTex != null)
- {
- webTex.Stop();
- webTex = null;
- }
- //设置摄像机摄像的区域
- webTex = new WebCamTexture(deviceName, 1920, 1080, CustomInfo.FPS);
- RemoteRtc.Instance.meshRender.texture = webTex;
- selfVideo.texture = webTex;
- webTex.Play();//开始摄像
- }
- }
- IEnumerator CallCamera1()
- {
- isswitch = false;
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- deviceName = devices[0].name;
- if (webTex != null)
- {
- webTex.Stop();
- webTex = null;
- }
- //设置摄像机摄像的区域
- webTex = new WebCamTexture(deviceName, 1920, 1080, CustomInfo.FPS);
- RemoteRtc.Instance.meshRender.texture = webTex;
- selfVideo.texture = webTex;
- webTex.Play();//开始摄像
- }
- }
- public void Swith()
- {
-
- AgoraVideoAudioManager.Instance.SwitchCamera(isswitch);
- isswitch = !isswitch;
- if (isswitch)
- {
- OpenBlack();
-
- }
- else
- {
- OpenFront();
- }
- }
- public void OpenFront()
- {
- //StopCoroutine(CallCamera1());
- //StartCoroutine(CallCamera());
- //RemoteRtc.Instance.meshRender.transform.localEulerAngles = new Vector3(180.0f, 0.0f, -180.0f);
- //selfVideo.transform.localEulerAngles = new Vector3(180.0f, 0.0f, -180.0f);
- }
- public void OpenBlack()
- {
- //StopCoroutine(CallCamera());
- //StartCoroutine(CallCamera1());
- //RemoteRtc.Instance.meshRender.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
- //selfVideo.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
- }
- public void ShowRoomissolvePop()
- {
- ShowUIForms(SysConst.PopForms);
- PopForms.Instance.ShowPublic(PopType.PopOne, RtcStrConfig.roomdissolve, "知道了");
- }
- public void sendVideo( bool state)
- {
- if(state)
- openVideoEffect();
- else
- closeVideoEffect();
- AgoraVideoAudioManager.Instance.EnableLocalVideo(state);
- //if (RemoteRtc.Instance.me.cIdV == "")
- //{
- // dcetype = "video";
- // RemoteRtc.Instance.startCamera();
- // RemoteRtc.Instance.sendVideo(true);
- // RemoteRtc.Instance.me.cIdV = "";
- // openVideoEffect();
- // AgoraVideoAudioManager.Instance.EnableLocalVideo(true);
- //}
- //else
- //{
- // dcetype = "video";
- // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdV);
- // RemoteRtc.Instance.stopCamera();
- // RemoteRtc.Instance.sendVideo(false);
- // closeVideoEffect();
- // AgoraVideoAudioManager.Instance.EnableLocalVideo(false);
- //}
- /*
- * 时间的跨度再次越过了半年
- */
- }
- public void sendAudio( bool state)
- {
- if(state)
- {
- openAudioEffect();
-
- }
- else
- {
- closeAudioEffect();
- }
- AgoraVideoAudioManager.Instance.EnableLoacalAudio(state);
- //if (RemoteRtc.Instance.me.cIdA != "")
- //{
- // dcetype = "audio";
- // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdA);
- // RemoteRtc.Instance.sendMic(false);
- // RemoteRtc.Instance.me.cIdA = "";
- // closeAudioEffect();
- // AgoraVideoAudioManager.Instance.EnableLoacalAudio(false);
- //}
- //else
- //{
- // dcetype = "audio";
- // RemoteRtc.Instance.sendMic(true);
- // openAudioEffect();
- // AgoraVideoAudioManager.Instance.EnableLoacalAudio(true);
- //}
- }
- private void closeVideoEffect()
- {
- isSendVideo = false;
- videoOpenBtn.gameObject.SetActive(true);
- videoCloseBtn.gameObject.SetActive(false);
- }
- private void openVideoEffect()
- {
- isSendVideo = true;
- videoOpenBtn.gameObject.SetActive(false);
- videoCloseBtn.gameObject.SetActive(true);
- }
- private void closeAudioEffect()
- {
- isSendAudio = false;
- audioOpenBtn.gameObject.SetActive(true);
- audioCloseBtn.gameObject.SetActive(false);
- }
- private void openAudioEffect()
- {
- isSendAudio = true;
- audioOpenBtn.gameObject.SetActive(false);
- audioCloseBtn.gameObject.SetActive(true);
- }
- public void CkickOnJieTuBtn()
- {
- AllNeedHideUI.SetActive(false);
- //if (isSwithVideo)
- //{
- //
- // selfVideo.gameObject.SetActive(false);
- // jieTuBG.texture = selfVideo.texture;
- //}
- //else
- //{
- // bigView.gameObject.SetActive(false);
- //
- // jieTuBG.texture = bigView.texture;
- //}
- Texture2D texture;
- if (isSwithVideo)
- {
- texture = selfVideo.texture as Texture2D;
- jieTuBG.rectTransform.localEulerAngles = selfVideo.rectTransform.localEulerAngles;
- }
- else
- {
- texture = bigView.texture as Texture2D;
- jieTuBG.rectTransform.localEulerAngles = bigView.rectTransform.localEulerAngles;
- }
- // 创建一个新的2D纹理
- Texture2D newTexture = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false);
- // 将截图复制到新的2D纹理中
- newTexture.SetPixels(texture.GetPixels());
- newTexture.Apply();
- jieTuBG.texture = newTexture;
- bigView.gameObject.SetActive(false);
- selfVideo.gameObject.SetActive(false);
- jieTuBG.gameObject.SetActive(true);
- }
- public void ShowShotsAllBtn()
- {
- AllNeedShowUI.SetActive(true);
- }
- public void JieTuWancheng()
- {
- AllNeedHideUI.SetActive(true);
- AllNeedShowUI.SetActive(false);
- if (!bigView.gameObject.activeSelf)
- {
- bigView.gameObject.SetActive(true);
- }
- if (!selfVideo.gameObject.activeSelf)
- {
- selfVideo.gameObject.SetActive(true);
- }
- jieTuBG.gameObject.SetActive(false);
- }
- private void OnDestroy()
- {
- WSHandler.Rtc.onRtcState -= onRtcState;
- }
- }
|