public void OnClickButtonJoin() { //只有状态为leaved时才能直接加入频道 if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state) { //获取userID和roomID GetID(); //调用加入频道接口 YouMe.YouMeVoiceAPI.GetInstance().SetVolume(70); //设置语音通话音量为 70%,可以减少近距离的啸叫 var errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, roomID, YouMe.YouMeUserRole.YOUME_USER_TALKER_FREE); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { //只有直接返回值为成功才会进回调 state = YouMe.ChannelState.CHANNEL_STATE_JOINING; tipsText.text = "进入中"; } } else { //其它状态值都直接返回 return; } }
public void onButtonLeaveAll() { if ((stateA == YouMe.ChannelState.CHANNEL_STATE_LEAVED) && (stateB == YouMe.ChannelState.CHANNEL_STATE_LEAVED)) { //都已不在房间,不须再离开房间 return; } //正在离开所有房间的时候,除了反初始化,其他都不能操作,需要等相关回调才能操作 //因此将不允许操作的按钮状态暂时设置为不可交互 joinAButton.interactable = false; leaveAButton.interactable = false; joinBButton.interactable = false; leaveBButton.interactable = false; leaveAllButton.interactable = false; AMicToggle.gameObject.SetActive(false); BMicToggle.gameObject.SetActive(false); micToggle.gameObject.SetActive(false); var errorcode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll(); //如果直接返回值不是成功,则不会进入回调 if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorcode) { stateA = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL; stateB = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL; tipsText.text = "正在退出所有频道"; } }
// Use this for initialization void Start() { //初设两个状态值 inited = false; state = YouMe.ChannelState.CHANNEL_STATE_LEAVED; userID = null; roomID = null; //自行封装的未初始化成功时的ui展现 NotInitedUI(); SetID(); //注册回调 YouMe.YouMeVoiceAPI.GetInstance().SetCallback(gameObject.name); //初始化,填入从游密申请到的AppKey和AppSecret(可在游密官网https://console.youme.im/user/register注册账号或者直接联系我方商务获取) //YouMe.YouMeVoiceAPI.GetInstance ().Init (您获取的AppKey, 您获取的AppSecret); var errorCode = YouMe.YouMeVoiceAPI.GetInstance().Init("YOUME670584CA1F7BEF370EC7780417B89BFCC4ECBF78", "yYG7XY8BOVzPQed9T1/jlnWMhxKFmKZvWSFLxhBNe0nR4lbm5OUk3pTAevmxcBn1mXV9Z+gZ3B0Mv/MxZ4QIeDS4sDRRPzC+5OyjuUcSZdP8dLlnRV7bUUm29E2CrOUaALm9xQgK54biquqPuA0ZTszxHuEKI4nkyMtV9sNCNDMBAAE=", YOUME_RTC_SERVER_REGION.RTC_HK_SERVER, ""); //如果直接返回值不是成功,则不会进入回调,可按初始化失败时的方法处理 if (errorCode != YouMe.YouMeErrorCode.YOUME_SUCCESS) { tipsText.text = "初始化失败,错误码:" + (int)errorCode; } }
public void onButtonJoinB() { //正在进入房间的时候,除了退出所有房间和反初始化,其他都不能操作,需要等相关回调才能操作 //因此将不允许操作的按钮状态暂时设置为不可交互 if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == stateB) { BTipsText.text = "正在离开"; joinAButton.interactable = false; leaveAButton.interactable = false; joinBButton.interactable = false; leaveBButton.interactable = false; AMicToggle.gameObject.SetActive(false); BMicToggle.gameObject.SetActive(false); micToggle.gameObject.SetActive(false); BTipsText.text = "正在进入"; GetID(); var errorcode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelMultiMode(userID, BRoomID); //如果直接返回值不是成功,则不会进入回调 if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorcode) { stateB = YouMe.ChannelState.CHANNEL_STATE_JOINING; } } }
public void OnClickButtonJoin() { //只有状态为leaved时才能直接加入频道 if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state) { //获取userID和roomID GetID(); //调用加入频道接口 string[] regionNames = new string[] { "cn", "sg", "sg", "", "cn" }; YouMe.YouMeVoiceAPI.GetInstance().SetServerRegion(regionNames); var errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, roomID, YouMe.YouMeUserRole.YOUME_USER_TALKER_FREE); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { //只有直接返回值为成功才会进回调 state = YouMe.ChannelState.CHANNEL_STATE_JOINING; tipsText.text = "进入中"; } } else { //其它状态值都直接返回 return; } }
// Use this for initialization void Start() { //初设两个状态值 inited = false; state = YouMe.ChannelState.CHANNEL_STATE_LEAVED; userID = null; roomID = null; //自行封装的未初始化成功时的ui展现 NotInitedUI(); SetID(); //注册回调 YouMe.YouMeVoiceAPI.GetInstance().SetCallback(gameObject.name); //初始化,填入从游密申请到的AppKey和AppSecret(可在游密官网https://console.youme.im/user/register注册账号或者直接联系我方商务获取) //YouMe.YouMeVoiceAPI.GetInstance ().Init (您获取的AppKey, 您获取的AppSecret); var errorCode = YouMe.YouMeVoiceAPI.GetInstance().Init("YOUME5BE427937AF216E88E0F84C0EF148BD29B691556", "y1sepDnrmgatu/G8rx1nIKglCclvuA5tAvC0vXwlfZKOvPZfaUYOTkfAdUUtbziW8Z4HrsgpJtmV/RqhacllbXD3abvuXIBlrknqP+Bith9OHazsC1X96b3Inii6J7Und0/KaGf3xEzWx/t1E1SbdrbmBJ01D1mwn50O/9V0820BAAE=", YouMe.YOUME_RTC_SERVER_REGION.RTC_CN_SERVER, ""); //如果直接返回值不是成功,则不会进入回调,可按初始化失败时的方法处理 if (errorCode != YouMe.YouMeErrorCode.YOUME_SUCCESS) { tipsText.text = "初始化失败,错误码:" + (int)errorCode; } }
public void onButtonJoinA() { //正在进入A房间的时候,除了退出所有房间和反初始化,其他都不允许操作,需要等相关回调才能操作 //因此将不允许操作的按钮状态暂时设置为不可交互 // if(YouMe.ChannelState.CHANNEL_STATE_LEAVED==stateA){ // ATipsText.text = "正在离开"; // // joinAButton.interactable = false; // leaveAButton.interactable = false; // joinBButton.interactable = false; // leaveBButton.interactable = false; // AMicToggle.gameObject.SetActive (false); // BMicToggle.gameObject.SetActive (false); // micToggle.gameObject.SetActive (false); ATipsText.text = "正在进入"; GetID(); var errorcode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelMultiMode(userID, ARoomID, YouMe.YouMeUserRole.YOUME_USER_TALKER_FREE); //如果直接返回值不是成功,则不会进入回调 if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorcode) { stateA = YouMe.ChannelState.CHANNEL_STATE_JOINING; } // } }
//回调函数 void OnEvent(string strParam) { string[] strSections = strParam.Split(new char[] { ',' }, 4); if (strSections == null) { return; } //解析后得到两个字段,第一个为事件类型,第二个为错误码类型 YouMe.YouMeEvent eventType = (YouMeEvent)int.Parse(strSections [0]); YouMe.YouMeErrorCode errorCode = (YouMeErrorCode)int.Parse(strSections [1]); switch (eventType) { case YouMe.YouMeEvent.YOUME_EVENT_INIT_OK: tipsText.text = "初始化成功"; inited = true; InitedUI(); break; case YouMe.YouMeEvent.YOUME_EVENT_INIT_FAILED: tipsText.text = "初始化失败,错误码:" + errorCode; break; case YouMe.YouMeEvent.YOUME_EVENT_JOIN_OK: tipsText.text = "加入频道成功"; nextRole = YouMe.YouMeUserRole.YOUME_USER_NONE; nextRoomID = null; state = YouMe.ChannelState.CHANNEL_STATE_JOINED; JoinedUI(); break; case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL: if (YouMe.YouMeUserRole.YOUME_USER_NONE != nextRole) { //需要加入新频道 errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, nextRoomID, nextRole); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_JOINING; JoiningUI(); } } else { tipsText.text = "离开频道成功"; labelDropdown.text = "静音"; roomDropdown.interactable = true; LeavedUI(); state = YouMe.ChannelState.CHANNEL_STATE_LEAVED; } break; default: tipsText.text = tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode; break; } }
/// <summary> /// 进入聊天频道 /// </summary> public void OnClickButtonJoin() { //只有状态为leaved时才能直接加入频道 if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state) { # if UNITY_ANDROID //安卓处理的接口 var errorCode1 = YouMe.YouMeVoiceAPI.GetInstance().SetVideoFrameRawCbEnabled(true); Debug.Log("Android Status:" + errorCode1); #endif //获取userID和roomID GetID(); //======================设置分辨率========================= YouMe.YouMeVoiceAPI.GetInstance().SetVideoLocalResolution(240, 320); YouMe.YouMeVoiceAPI.GetInstance().SetMixVideoSize(240, 320); YouMe.YouMeVoiceAPI.GetInstance().AddMixOverlayVideo(selfUserID, 0, 0, 0, 240, 320); YouMe.YouMeVoiceAPI.GetInstance().SetVideoNetResolution(240, 320); //======================调用加入频道接口========================= var errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(selfUserID, roomID, YouMe.YouMeUserRole.YOUME_USER_TALKER_FREE); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { //只有直接返回值为成功才会进回调 state = YouMe.ChannelState.CHANNEL_STATE_JOINING; } //======================调用加入频道接口========================= userIds.Clear(); Debug.Log("User host " + selfUserID + " join"); userIds.Add(selfUserID, 1); //=========================创建视频流============================= selfVideoImage.transform.rotation = Quaternion.Euler(180, 0, 0); //竖屏显示需要旋转下 int videoRenderid = YouMeTexture.GetInstance().CreateTexture(selfUserID); //更新视频,默认15帧每秒 YouMeTexture.GetInstance().SetVideoRenderUpdateCallback(videoRenderid, (videoTexture) => { UpdateVideoRender(videoTexture); }); //=========================创建视频流============================= //显示自己的视频开关 cameraControlButton.gameObject.SetActive(true); }
// Use this for initialization void Start() { //初设两个状态值 inited = false; state = YouMe.ChannelState.CHANNEL_STATE_LEAVED; selfUserID = null; roomID = null; usedPositions = new Dictionary <int, string>(10); //自行封装的未初始化成功时的ui展现 NotInitedUI(); SetID(); userIds.Clear(); preChatRoomMembers.Clear(); //注册回调 YouMe.YouMeVoiceAPI.GetInstance().SetCallback(gameObject.name); // ==================================================================================== // ===================================== 初始化 ========================================= //初始化,填入从游密申请到的AppKey和AppSecret(可在游密官网https://console.youme.im/user/register注册账号或者直接联系我方商务获取) //YouMe.YouMeVoiceAPI.GetInstance ().Init (您获取的AppKey, 您获取的AppSecret); Debug.Log("call init"); var errorCode = YouMe.YouMeVoiceAPI.GetInstance().Init("YOUME5BE427937AF216E88E0F84C0EF148BD29B691556", "y1sepDnrmgatu/G8rx1nIKglCclvuA5tAvC0vXwlfZKOvPZfaUYOTkfAdUUtbziW8Z4HrsgpJtmV/RqhacllbXD3abvuXIBlrknqP+Bith9OHazsC1X96b3Inii6J7Und0/KaGf3xEzWx/t1E1SbdrbmBJ01D1mwn50O/9V0820BAAE=", YouMe.YOUME_RTC_SERVER_REGION.RTC_CN_SERVER, ""); //如果直接返回值不是成功,则不会进入回调,可按初始化失败时的方法处理 if (errorCode != YouMe.YouMeErrorCode.YOUME_SUCCESS) { // TODO Debug.Log("init error:" + errorCode); } // ===================================== end初始化 ===================================== // ==================================================================================== ShowVersion(); }
public void OnClickButtonLeave() { //joining和joined的状态可以直接调用离开 if (YouMe.ChannelState.CHANNEL_STATE_JOINING == state || YouMe.ChannelState.CHANNEL_STATE_JOINED == state) { //调用加入频道接口 var errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll(); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { //只有直接返回值为成功才会进回调 state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL; tipsText.text = "离开中"; } } else { //其它状态值都直接返回 return; } }
public void onButtonLeaveA() { //正在离开房间的时候,除了退出所有房间和反初始化,其他都不能操作,需要等相关回调才能操作 //因此将不允许操作的按钮状态暂时设置为不可交互 if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateA) { joinAButton.interactable = false; leaveAButton.interactable = false; joinBButton.interactable = false; leaveBButton.interactable = false; AMicToggle.gameObject.SetActive(false); BMicToggle.gameObject.SetActive(false); micToggle.gameObject.SetActive(false); var errorcode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelMultiMode(ARoomID); //如果直接返回值不是成功,则不会进入回调 if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorcode) { stateA = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ONE; } } }
public void onDropdown() { roomDropdown.interactable = false; LeavedUI(); switch (roomDropdown.value) { case 0: tipsText.text = "静音模式"; //调用离开频道 var errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll(); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL; LeavingUI(); } break; case 1: tipsText.text = "主播模式"; if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state) { //当前状态为不在房间,则可直接加入新房间 if (hostAuthority) { //为主播身份 GetID(); errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, hostRoomID, YouMe.YouMeUserRole.YOUME_USER_HOST); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_JOINING; JoiningUI(); } //SpeakerUI (); } else { //为听众身份 GetID(); errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, hostRoomID, YouMe.YouMeUserRole.YOUME_USER_LISTENER); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_JOINING; JoiningUI(); } //ListenerUI (); } } if (YouMe.ChannelState.CHANNEL_STATE_JOINED == state) { //当前状态为已经在房间,需要先退出并等回调成功,再重新加入 nextRoomID = hostRoomID; if (hostAuthority) { //准备以主播身份加入主播频道 nextRole = YouMe.YouMeUserRole.YOUME_USER_HOST; } else { //准备以听众身份加入主播频道 nextRole = YouMe.YouMeUserRole.YOUME_USER_LISTENER; } //先调用离开频道 errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll(); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL; LeavingUI(); } } break; case 2: tipsText.text = "指挥模式"; if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state) { //当前状态为不在房间,则可直接加入新房间 if (commanderAuthority) { //为指挥身份 GetID(); errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, commanderRoomID, YouMe.YouMeUserRole.YOUME_USER_COMMANDER); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_JOINING; JoiningUI(); } } else { //为听众身份 GetID(); errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, commanderRoomID, YouMe.YouMeUserRole.YOUME_USER_LISTENER); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_JOINING; JoiningUI(); } } } if (YouMe.ChannelState.CHANNEL_STATE_JOINED == state) { //当前状态为已经在房间,需要先退出并等回调成功,再重新加入 nextRoomID = commanderRoomID; if (hostAuthority) { //准备以指挥身份加入指挥频道 nextRole = YouMe.YouMeUserRole.YOUME_USER_COMMANDER; } else { //准备以听众身份加入指挥频道 nextRole = YouMe.YouMeUserRole.YOUME_USER_LISTENER; } //先调用离开频道 errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll(); if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode) { state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL; LeavingUI(); } } break; } }
//回调函数 void OnEvent(string strParam) { string[] strSections = strParam.Split(new char[] { ',' }, 4); if (strSections == null) { return; } //解析后得到两个字段,第一个为事件类型,第二个为错误码类型 YouMe.YouMeEvent eventType = (YouMeEvent)int.Parse(strSections[0]); YouMe.YouMeErrorCode errorCode = (YouMeErrorCode)int.Parse(strSections[1]); string channelID = strSections[2]; string param = strSections[3]; switch (eventType) { case YouMe.YouMeEvent.YOUME_EVENT_INIT_OK: tipsText.text = "初始化成功"; inited = true; InitedUI(); break; case YouMe.YouMeEvent.YOUME_EVENT_INIT_FAILED: tipsText.text = "初始化失败,错误码:" + errorCode; break; case YouMe.YouMeEvent.YOUME_EVENT_JOIN_OK: //如果已调用了离开接口,则无须再等此类回调 if (YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL == state) { return; } tipsText.text = tipsText.text + "\n加入频道成功"; JoinedUI(); state = YouMe.ChannelState.CHANNEL_STATE_JOINED; break; case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL: tipsText.text = tipsText.text + "\n离开频道成功"; LeavedUI(); state = YouMe.ChannelState.CHANNEL_STATE_LEAVED; break; case YouMe.YouMeEvent.YOUME_EVENT_JOIN_FAILED: //进入语音频道失败 tipsText.text = tipsText.text + "\n加入频道失败,错误码:" + errorCode; LeavedUI(); state = YouMe.ChannelState.CHANNEL_STATE_LEAVED; break; case YouMe.YouMeEvent.YOUME_EVENT_REC_PERMISSION_STATUS: if (errorCode == YouMe.YouMeErrorCode.YOUME_ERROR_REC_NO_PERMISSION) { tipsText.text = tipsText.text + "\n录音启动失败(此时不管麦克风mute状态如何,都没有声音输出"; } break; case YouMe.YouMeEvent.YOUME_EVENT_RECONNECTING: tipsText.text = tipsText.text + "\n断网了,正在重连"; break; case YouMe.YouMeEvent.YOUME_EVENT_RECONNECTED: tipsText.text = tipsText.text + "\n断网重连成功"; break; case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_MIC_OFF: //其他用户的麦克风关闭: //Send Event callback, event(18):OTHERS_SPEAKER_ON, errCode:0, room:, param:3026935 tipsText.text = tipsText.text + "\n用户" + param + "的麦克风关闭"; break; case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_MIC_ON: //其他用户的麦克风打开: tipsText.text = tipsText.text + "\n用户" + param + "的麦克风打开"; break; case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_SPEAKER_ON: //其他用户的扬声器打开: tipsText.text = tipsText.text + "\n用户" + param + "的扬声器打开"; break; case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_SPEAKER_OFF: //其他用户的扬声器关闭 tipsText.text = tipsText.text + "\n用户" + param + "的扬声器关闭"; break; default: tipsText.text = tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode; break; } }
//回调函数 void OnEvent(string strParam) { string[] strSections = strParam.Split(new char[] { ',' }, 4); if (strSections == null) { return; } //解析后得到两个字段,第一个为事件类型,第二个为错误码类型 YouMe.YouMeEvent eventType = (YouMeEvent)int.Parse(strSections [0]); YouMe.YouMeErrorCode errorCode = (YouMeErrorCode)int.Parse(strSections [1]); string channelID = strSections [2]; string param = strSections [3]; //打印输出 //Debug.LogError ("eventType:" + eventType.ToString ()); //Debug.LogError ("iErrorCode:" + iErrorCode.ToString ()); switch (eventType) { case YouMe.YouMeEvent.YOUME_EVENT_INIT_OK: // callbackList.Add (() => { // // }); tipsText.text = "初始化成功"; inited = true; InitedUI(); break; case YouMe.YouMeEvent.YOUME_EVENT_INIT_FAILED: tipsText.text = "初始化失败,错误码:" + errorCode; break; case YouMe.YouMeEvent.YOUME_EVENT_JOIN_OK: YouMe.YouMeVoiceAPI.GetInstance().SetMicrophoneMute(false); Debug.LogError(YouMe.YouMeVoiceAPI.GetInstance().SetVadCallbackEnabled(true)); if (YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL == stateA) { //说明已经调用了离开所有频道的操作,此时只需要等离开所有频道的回调就行 return; } tipsText.text = ""; micToggle.gameObject.SetActive(true); YouMe.YouMeVoiceAPI.GetInstance().SetSpeakerMute(false); if (string.Equals(channelID, ARoomID)) { stateA = YouMe.ChannelState.CHANNEL_STATE_JOINED; ATipsText.text = "已进入"; //加入A频道成功后,则离开A频道按钮变为可交互。B频道根据状态恢复UI leaveAButton.interactable = true; AMicToggle.gameObject.SetActive(true); if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateB) { BMicToggle.gameObject.SetActive(true); leaveBButton.interactable = true; } else { joinBButton.interactable = true; } } else if (string.Equals(channelID, BRoomID)) { BTipsText.text = "已进入"; stateB = YouMe.ChannelState.CHANNEL_STATE_JOINED; //加入B频道成功后,则离开B频道按钮变为可交互。A频道根据状态恢复UI leaveBButton.interactable = true; BMicToggle.gameObject.SetActive(true); if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateA) { AMicToggle.gameObject.SetActive(true); leaveAButton.interactable = true; } else { joinAButton.interactable = true; } } break; case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ONE: if (YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL == stateA) { //说明已经调用了离开所有频道的操作,此时只需要等离开所有频道的回调就行 return; } if (string.Equals(channelID, ARoomID)) { stateA = YouMe.ChannelState.CHANNEL_STATE_LEAVED; ATipsText.text = "已离开"; //离开A频道成功后,则加入A频道按钮变为可交互。B频道根据状态恢复UI joinAButton.interactable = true; if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateB) { BMicToggle.gameObject.SetActive(true); micToggle.gameObject.SetActive(true); leaveBButton.interactable = true; } else { joinBButton.interactable = true; } } else if (string.Equals(channelID, BRoomID)) { BTipsText.text = "已离开"; stateB = YouMe.ChannelState.CHANNEL_STATE_LEAVED; //加入B频道成功后,则加入B频道按钮变为可交互。A频道根据状态恢复UI joinBButton.interactable = true; if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateA) { AMicToggle.gameObject.SetActive(true); leaveAButton.interactable = true; micToggle.gameObject.SetActive(true); } else { joinAButton.interactable = true; } } break; case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL: tipsText.text = "已退出所有频道"; stateA = YouMe.ChannelState.CHANNEL_STATE_LEAVED; ATipsText.text = "已离开"; stateB = YouMe.ChannelState.CHANNEL_STATE_LEAVED; BTipsText.text = "已离开"; joinAButton.interactable = true; joinBButton.interactable = true; leaveAllButton.interactable = true; break; case YouMe.YouMeEvent.YOUME_EVENT_SPEAK_SUCCESS: AMicToggle.interactable = true; BMicToggle.interactable = true; micToggle.interactable = true; if (string.Equals(channelID, ARoomID)) { tipsText.text = "可以对A房间说话"; } else if (string.Equals(channelID, BRoomID)) { tipsText.text = "可以对B房间说话"; } break; case YouMe.YouMeEvent.YOUME_EVENT_SPEAK_FAILED: AMicToggle.interactable = true; BMicToggle.interactable = true; micToggle.interactable = true; if (string.Equals(channelID, ARoomID)) { tipsText.text = "对A房间说话的操作失败"; AMicToggle.isOn = false; YouMe.YouMeVoiceAPI.GetInstance().SetMicrophoneMute(true); micToggle.isOn = true; } else if (string.Equals(channelID, BRoomID)) { tipsText.text = "对B房间说话的操作失败"; BMicToggle.isOn = false; YouMe.YouMeVoiceAPI.GetInstance().SetMicrophoneMute(true); micToggle.isOn = true; } break; case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_VOICE_ON: Debug.LogError("YOUME_EVENT_OTHERS_VOICE_ON:" + param); break; case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_VOICE_OFF: Debug.LogError("YOUME_EVENT_OTHERS_VOICE_OFF:" + param); break; default: tipsText.text = tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode; break; } }