using BeinLab.Util; using SC.XR.Unity.Module_InputSystem; using ShadowStudio.UI; using System.Collections; using System.Collections.Generic; using UnityEngine; using Vuforia; using XRTool.Util; public class StudioRtc : SCRtcManager { public Camera cam; public MeshRenderer meshRender; public static StudioRtc Instance; // Start is called before the first frame update void Start() { DontDestroyOnLoad(this.gameObject); Instance = this; } 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) { #if UNITY_ANDROID && !UNITY_EDITOR //if (boo && StudioRtc.Instance.me.cIdA == "") //CommonMethod.ShowNetLoading("音視頻_socket", "正在开启麦克风"); #endif SCRtcFactory.Instance.mSCRtcHandle.sendMic(boo); } public void sendVideo(bool boo) { #if UNITY_ANDROID && !UNITY_EDITOR //if (boo&& StudioRtc.Instance.me.cIdV == "") //CommonMethod.ShowNetLoading("音視頻_socket", "正在开启摄像头"); #endif 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 (!CheckDeviceType.checkIsPhone()) { ConsoleDlg.Instance.vufora_camera.enabled = false; Vuforia.VuforiaBehaviour.Instance.enabled = false; } if (rt == null) { rt = new RenderTexture(CustomInfo.mWidth, CustomInfo.mHight, 1); } //cam.targetTexture = rt; //me.setMyCamera(rt); //if (tex == null) //{ // tex = new Texture2D(CustomInfo.mWidth, CustomInfo.mHight, TextureFormat.RGBA32, false); //} //if (!CheckDeviceType.checkIsPhone()) //{ // 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 = CommonMethod.MyPeer.PeerId; sconfig.roomPwd = CustomInfo.roomPwd; sconfig.isRevAllAudio = true; sconfig.isRevAllVideo = true; sconfig.isSendAudio = CustomInfo.isSendAudio; sconfig.isSendVideo = CustomInfo.isSendVideo; 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); Debug.Log("rtcinit==================================>"); } //关闭RTC public void Close() { Debug.Log("退出房间CloseStart"); if (SCRtcFactory.Instance != null) { SCRtcFactory.Instance.Close(); if (SCRtcFactory.Instance.mSCRtcPeers != null) { SCRtcFactory.Instance.mSCRtcPeers.initPeers(); } } Debug.Log("退出房间CloseEnd"); } Timer timeCreator; int netCount; // Update is called once per frame void Update() { cam.transform.position = GSXRManager.Instance.head.position; cam.transform.rotation = GSXRManager.Instance.head.rotation; SCRtcFactory.Instance.Update(); if(CommonMethod.NetLoading&&CommonMethod.NetLoading.activeSelf) { if(timeCreator==null) { timeCreator = TimerMgr.Instance.CreateTimer(() => { int ct = CommonMethod.queueList.Count; for (int i = 0; i < ct; i++) { CommonMethod.queueList.Dequeue(); } SCInputModule.Instance.CanProcessEvent = true; netCount = 0; }, 30f); } } else { if(timeCreator!=null) { timeCreator.CleanUp(); timeCreator = null; } netCount = 0; } } }