using Thousandto.Code.Center; using Thousandto.Code.Global; using Thousandto.CoreSDK; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace Thousandto.Code.Logic { /// /// 实时语音系统 /// public class RealTimeVoiceSystem { //帮会及时语音设置 private GuildVoiceSetting _setting = new GuildVoiceSetting(); //及时语音频道的处理逻辑 private Dictionary _voiceDict = new Dictionary(); //获取当前通道 public VoiceChannel CurrentChannel { get { if (BaseVoiceLogic.ActiveVoiceLogic == null) return VoiceChannel.Exit; return BaseVoiceLogic.ActiveVoiceLogic.Channel; } } //公会语音设置 public GuildVoiceSetting Setting { get { return _setting; } } public void Initialize() { _voiceDict[(int)VoiceChannel.Exit] = new EmptyVoiceLogic(); _voiceDict[(int)VoiceChannel.Guild] = new GuildVoiceLogic(); _voiceDict[(int)VoiceChannel.Team] = new TeamVoiceLogic(); _voiceDict[(int)VoiceChannel.Exit].Initialize(); _voiceDict[(int)VoiceChannel.Guild].Initialize(); _voiceDict[(int)VoiceChannel.Team].Initialize(); GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_GUILD_COMMANDER_PLAYER_CHANGED, OnPlayerVoiceStateChanged); } public void Uninitialize() { ReqChangeChannel(VoiceChannel.Exit); GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_GUILD_COMMANDER_PLAYER_CHANGED, OnPlayerVoiceStateChanged); var e = _voiceDict.GetEnumerator(); while (e.MoveNext()) { e.Current.Value.Uninitialize(); } /* _voiceDict[(int)VoiceChannel.Exit].Uninitialize(); _voiceDict[(int)VoiceChannel.Guild].Uninitialize(); _voiceDict[(int)VoiceChannel.Team].Uninitialize(); */ } #region//处理Server的返回 //请求设置帮会语音模式 //public void RespVoiceModelChanged(MSG_Guild.ResSynVoiceMode result) //{ // GameCenter.GuildSystem.TalkState = VoiceState.None; // var gvl = _voiceDict[(int)VoiceChannel.Guild] as GuildVoiceLogic; // gvl.State = VoiceState.None; // gvl.IsCommanderModel = (result.mode == 1); // if(gvl.IsCommanderModel) gvl.SystemIsMute = true; // _setting.RespVoiceModelChanged(gvl.IsCommanderModel); //} //玩家麦状态改变 public void OnPlayerVoiceStateChanged(object obj,object sender) { //((GuildVoiceLogic)(_voiceDict[(int)VoiceChannel.Guild])).State = GameCenter.GuildSystem.TalkState; } //接收到集合消息 //public void RespTogetther(MSG_Guild.ResCallUpVoicer result) //{ // //这里默认集合消息也会发送给帮主,如果帮助自己也不在实时聊天中,也会弹出进入提示 // if (BaseVoiceLogic.ActiveVoiceLogic.Channel != VoiceChannel.Guild) // { // _setting.RespTogetther(); // } // else // { // _setting.RespTogetherSuccess(); // } //} #endregion #region//下面是有用的接口 //设置麦克风静音 public void SetMicrophoneMute(bool isMute) { if (BaseVoiceLogic.ActiveVoiceLogic != null) { BaseVoiceLogic.ActiveVoiceLogic.UserIsMute = isMute; } } //获取麦克风的静音信息 public bool GetMicrophoneMute() { if (BaseVoiceLogic.ActiveVoiceLogic != null) { return BaseVoiceLogic.ActiveVoiceLogic.UserIsMute; } return false; } //请求进入房间 public void ReqChangeChannel(VoiceChannel channel) { if (BaseVoiceLogic.ActiveVoiceLogic != null && BaseVoiceLogic.ActiveVoiceLogic.Channel == channel) return; BaseVoiceLogic voiceLogic = null; if (_voiceDict.TryGetValue((int)channel, out voiceLogic)) { voiceLogic.Enter(); } } //获取通道中玩家的数量 public int GetChannelPlayerNum(VoiceChannel channel) { if (BaseVoiceLogic.ActiveVoiceLogic != null) { if (BaseVoiceLogic.ActiveVoiceLogic.Channel == channel) { return BaseVoiceLogic.ActiveVoiceLogic.UserCount; } } return 0; } //根据角色查找通道 public VoiceChannel ChannelOfPlayer(string userID) { if (BaseVoiceLogic.ActiveVoiceLogic != null) { if (BaseVoiceLogic.ActiveVoiceLogic.AllUsers.IndexOf(userID)>=0) { return BaseVoiceLogic.ActiveVoiceLogic.Channel; } } return VoiceChannel.Exit; } //根据通道获取文本 public string ChannelToText(VoiceChannel channel) { switch (channel) { case VoiceChannel.Exit: return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_VOICE_CHANNEL_EXIT); case VoiceChannel.Team: return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_VOICE_CHANNEL_TEAM); case VoiceChannel.Guild: return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_VOICE_CHANNEL_GUILD); default: return Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_VOICE_CHANNEL_EXIT); } } #endregion } }