using LitJson; using ShadowStudio.UI; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using XRTool.Util; using static ScenesManager; public class RemoteRtc : SCRtcManager { public Texture2D NoView; public Texture2D NoUser; public Camera cam; public MeshRenderer meshRender; public static RemoteRtc Instance; public Texture2D testTexture; public Transform cam2; public Transform[] trans; public Transform cube; // Start is called before the first frame update void Start() { WSHandler.Rtc.onRtcState += onRtcState; DontDestroyOnLoad(this.gameObject); Instance = this; StartCoroutine(CallCamera()); } void onRtcState(string state) { if(state=="joinRoom") { ScenesManager.Instance.showWindow(SceneType.ShowRoom); } if(state=="joined"||state=="closed") { RoomOtherUser.Instance.UpdateList(); } } public void setVolume(float f) { SCRtcFactory.Instance.mSCRtcHandle.audioMeChange(f); } public void setVolume(string cid, float f) { // SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cid, f); } public void sendMic(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.sendMic(boo); } public void sendVideo(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo); } public void muteVideo(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo); } public void muteAudio(bool boo) { SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo); } public void closeRev(string id) { SCRtcFactory.Instance.mSCRtcHandle.closeRev(id); } public void startRev(string id) { SCRtcFactory.Instance.mSCRtcHandle.openRev(id); } public RenderTexture rt; public Texture2D tex; public void startCamera() { if (rt == null) { rt = new RenderTexture(1280, 720, 1); } cam.targetTexture = rt; me.setMyCamera(rt); //if (tex == null) //{ // tex = new Texture2D(CustomInfo.mWidth, CustomInfo.mHight, TextureFormat.RGBA32, false); //} //meshRender.material.mainTexture = tex; //SCRtcFactory.Instance.mSCRtcHandle.addCameraLocal(meshRender.material.mainTexture.GetNativeTexturePtr().ToInt32()); //SCRtcFactory.Instance.mSCRtcHandle.startCamera(); //meshRender.transform.localEulerAngles = new Vector3(0, 180, 180); meshRender.gameObject.SetActive(true); } public void stopCamera() { meshRender.gameObject.SetActive(false); //SCRtcFactory.Instance.mSCRtcHandle.stopCamera(); } public void openSpeaker() { SCRtcFactory.Instance.mSCRtcHandle.openSpeaker(); } public CustomMe me; public CustomPeerList customPeerList; public void start(string roomID) { CustomInfo.RoomId = roomID; InitListener(); SCRtcConfig sconfig = new SCRtcConfig(); sconfig.Url = CustomInfo.url; sconfig.Post = CustomInfo.POST; sconfig.RoomId = CustomInfo.RoomId; sconfig.Token = UserInfo.User_Token; sconfig.disPlayName = UserInfo.Account; sconfig.roomPwd = CustomInfo.roomPwd; sconfig.isRevAllAudio = true; sconfig.isRevAllVideo = true; sconfig.isSendAudio = false; sconfig.isSendVideo = false; sconfig.mWidth = CustomInfo.mWidth; sconfig.mHight = CustomInfo.mHight; sconfig.FPS = CustomInfo.FPS; me = new CustomMe(); customPeerList = new CustomPeerList(); SCRtcFactory.Instance.init(sconfig, this, me, customPeerList); // RenderTexture myRenderTexture = new RenderTexture(sconfig.mWidth, sconfig.mHight, 1); } //关闭RTC public void Close() { SCRtcFactory.Instance.Close(); if (SCRtcFactory.Instance != null && SCRtcFactory.Instance.mSCRtcPeers != null) { SCRtcFactory.Instance.mSCRtcPeers.initPeers(); } int ct = PopPeerView.Instance.bigList.Count; for (int j = ct - 1; j >= 0; j--) { PopPeerView.Instance.bigList[j].closeView(); } } //public TextMesh textmesh; // Update is called once per frame void Update() { //textmesh.text = SCRtcFactory.Instance.mSCRtcHandle.getwifi(); //cam.transform.position = SvrManager.Instance.head.position; //cam.transform.rotation = SvrManager.Instance.head.rotation; SCRtcFactory.Instance.Update(); /* Vector3[] v3s = CameraView.GetCorners(1,cam2); for (int i = 0; i < v3s.Length; i++) { trans[i].position = cam2.TransformPoint( v3s[i]); } cube.position = CameraView.PosChange(0.2f, 0.3f, 1, cam2);*/ } public void changeViewClose() { CustomInfo.isCloseView = true; //cam.cullingMask = 1 << 9; WSHandler.Rtc.onRtcState("changeView"); } public void changeViewOpen() { CustomInfo.isCloseView = false; //cam.cullingMask = -1; WSHandler.Rtc.onRtcState("changeView"); } public WebCamTexture webTex; private string deviceName; IEnumerator CallCamera() { yield return null; // if (Application.HasUserAuthorization(UserAuthorization.WebCam)) // { WebCamDevice[] devices = WebCamTexture.devices; Debug.Log("WebCamDevice====."+devices.Length); #if UNITY_EDITOR deviceName = devices[0].name; #else deviceName = devices[2].name; #endif if (webTex != null) { webTex.Stop(); webTex = null; } //设置摄像机摄像的区域 webTex = new WebCamTexture(deviceName, 1280, 720, CustomInfo.FPS); // webTex = new WebCamTexture(deviceName, 640, 480, CustomInfo.FPS); meshRender.material.mainTexture = webTex; webTex.Play();//开始摄像 // } } public void InitCenter() { WSHandler.Office.OnInit -= Init; WSHandler.Office.OnInit += Init; WSHandler.init(); } private void Init(JsonData data) { if (PopUpInfo.Instance) { PopUpInfo.Instance.HideNetErrorPanel(); } if (ShowRoom.Instance && ShowRoom.Instance.gameObject.activeSelf) { if (PopUpInfo.Instance) { PopUpInfo.Instance.ShowNetErrorPanel(); } OnJoinRoom(WSHandler._roomid); } WSHandler.Office.OnInit -= Init; } public void OnJoinRoom(string roomId) { RoomMainInfo.roomNum = roomId; WSHandler.Office.OnJoinRoomReveived -= joinRoom; WSHandler.Office.OnJoinRoomReveived += joinRoom; WSHandler.Office.JoinRoom(roomId); } private void joinRoom(JsonData data) { if (data.Keys.Contains("data")) { switch (data["data"]["code"].ToString()) { case "200": WSHandler.roomRtcinit(RoomMainInfo.roomNum); WSHandler.Office.ChangeUserType(UserInfo.BusyType); break; case "1000": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间号无效"); ShowNetError(); break; case "1001": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间人数已满"); ShowNetError(); break; case "1003": PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间不存在"); ShowNetError(); break; default: PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间不存在"); ShowNetError(); break; } if (PopUpInfo.Instance) { PopUpInfo.Instance.HideNetErrorPanel(); } } else { Debug.LogError("消息错误"); } WSHandler.Office.OnJoinRoomReveived -= joinRoom; } private void ShowNetError() { if (ShowRoom.Instance) { ShowRoom.Instance.ExitRoom(); } ScenesManager.Instance.showWindow(SceneType.ShowOffice); } }