//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Saturday, March 30, 2019
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class VoiceWidget : MonoBehaviour
|
{
|
[SerializeField] RectTransform m_Content;
|
[SerializeField] ClickScreenOtherSpace m_ClickOtherSpace;
|
|
[SerializeField] VoiceRecorder m_TeamVoice;
|
[SerializeField] VoiceRecorder m_GuildVoice;
|
|
LogicBool active = new LogicBool();
|
|
ChatCenter chatModel { get { return ModelCenter.Instance.GetModel<ChatCenter>(); } }
|
TeamModel teamModel { get { return ModelCenter.Instance.GetModel<TeamModel>(); } }
|
|
public void Init()
|
{
|
m_Content.SetActive(active.Fetch());
|
UpdateRecorderState();
|
m_ClickOtherSpace.AddListener(Hide);
|
m_GuildVoice.voiceRecordSuccessEvent += OnVoiceRecordFairySuccessEvent;
|
m_TeamVoice.voiceRecordSuccessEvent += OnVoiceRecordTeamSuccessEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += UpdateRecorderState;
|
teamModel.myTeamRefreshEvent += UpdateRecorderState;
|
}
|
|
public void UnInit()
|
{
|
active.value = false;
|
m_GuildVoice.voiceRecordSuccessEvent -= OnVoiceRecordFairySuccessEvent;
|
m_TeamVoice.voiceRecordSuccessEvent -= OnVoiceRecordTeamSuccessEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= UpdateRecorderState;
|
teamModel.myTeamRefreshEvent -= UpdateRecorderState;
|
}
|
|
public void Show()
|
{
|
active.value = true;
|
}
|
|
public void Hide()
|
{
|
active.value = false;
|
}
|
|
private void Update()
|
{
|
if (active.dirty)
|
{
|
m_Content.SetActive(active.Fetch());
|
}
|
}
|
|
private void OnVoiceRecordTeamSuccessEvent(int _instId, float _seconds)
|
{
|
chatModel.SetVoice(_instId, ChatInfoType.Team, _seconds);
|
}
|
|
private void OnVoiceRecordFairySuccessEvent(int _instId, float _seconds)
|
{
|
chatModel.SetVoice(_instId, ChatInfoType.Fairy, _seconds);
|
}
|
|
private void UpdateRecorderState()
|
{
|
var chatable = FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Chat);
|
var guildVoiceEnable = false;
|
var teamVoiceEnable = false;
|
|
if (chatable)
|
{
|
guildVoiceEnable = PlayerDatas.Instance.fairyData.HasFairy;
|
teamVoiceEnable = teamModel.myTeam.inTeam;
|
}
|
else
|
{
|
guildVoiceEnable = false;
|
teamVoiceEnable = false;
|
}
|
|
m_GuildVoice.SetActive(false);
|
m_TeamVoice.SetActive(false);
|
}
|
|
private void OnFuncStateChangeEvent(int _type)
|
{
|
if ((FuncOpenEnum)_type == FuncOpenEnum.Chat)
|
{
|
UpdateRecorderState();
|
}
|
}
|
|
void TeamChatButton()
|
{
|
SysNotifyMgr.Instance.ShowTip("UnopenedFunction");
|
}
|
|
void TongVoiceButton()
|
{
|
SysNotifyMgr.Instance.ShowTip("UnopenedFunction");
|
}
|
|
}
|
|
}
|