119 lines
3.2 KiB
C#
119 lines
3.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using System.Collections;
|
|
using System;
|
|
|
|
public class ChatVoiceButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
|
|
{
|
|
private bool _IsPointExit = false;
|
|
public GC_CHAT.CHATTYPE _DefaultChatChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_INVALID;
|
|
public GameObject _HoldGO;
|
|
public GameObject _ReleaseGO;
|
|
|
|
private const float _CHAT_VOICE_LIMIT = 10.0f;
|
|
private float _ChatVoiceStart = 0;
|
|
|
|
|
|
public void Update()
|
|
{
|
|
if (_ChatVoiceStart < 0)
|
|
return;
|
|
|
|
if (Time.realtimeSinceStartup - _ChatVoiceStart >= _CHAT_VOICE_LIMIT)
|
|
{
|
|
PointUP();
|
|
_ChatVoiceStart = -1;
|
|
}
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
Debug.Log("OnPointerDown");
|
|
//if (_DefaultChatChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_INVALID)
|
|
{
|
|
if (ChatInfoLogic.Instance() && ChatInfoLogic.Instance().gameObject.activeSelf)
|
|
{
|
|
_DefaultChatChannel = (GC_CHAT.CHATTYPE)ChatInfoLogic.Instance().GetCurChannelType();
|
|
}
|
|
else if (FriendAndMailRoot.Instance() && FriendAndMailRoot.Instance().gameObject.activeSelf)
|
|
{
|
|
_DefaultChatChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND;
|
|
}
|
|
}
|
|
|
|
if (!ChatInputLogic.IsCanChat((int)_DefaultChatChannel, true))
|
|
return;
|
|
|
|
//if ((int)_DefaultChatChannel == (int)CG_CHAT.CHATTYPE.CHAT_TYPE_GUILD)
|
|
//{
|
|
// if (!GameManager.gameManager.PlayerDataPool.IsHaveGuild())
|
|
// {
|
|
// GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{4909}"));
|
|
// return;
|
|
// }
|
|
//}
|
|
//else if ((int)_DefaultChatChannel == (int)CG_CHAT.CHATTYPE.CHAT_TYPE_TEAM)
|
|
//{
|
|
// if (!GameManager.gameManager.PlayerDataPool.IsHaveTeam())
|
|
// {
|
|
// GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{4910}"));
|
|
// return;
|
|
// }
|
|
//}
|
|
|
|
bool isInputStart = ChatVoiceInputLogic.InputVoice(_DefaultChatChannel);
|
|
if (isInputStart)
|
|
{
|
|
_IsPointExit = false;
|
|
|
|
if (_HoldGO != null)
|
|
{
|
|
_HoldGO.SetActive(true);
|
|
}
|
|
if (_ReleaseGO != null)
|
|
{
|
|
_ReleaseGO.SetActive(false);
|
|
}
|
|
|
|
_ChatVoiceStart = Time.realtimeSinceStartup;
|
|
}
|
|
else
|
|
{
|
|
_IsPointExit = true;
|
|
PointUP();
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
_IsPointExit = true;
|
|
ChatVoiceInputLogic.CancelVoiceSlider();
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
PointUP();
|
|
}
|
|
|
|
private void PointUP()
|
|
{
|
|
if (_IsPointExit)
|
|
{
|
|
ChatVoiceInputLogic.CancelVoiceKeyUp();
|
|
}
|
|
else
|
|
{
|
|
ChatVoiceInputLogic.StopVoice();
|
|
}
|
|
|
|
if (_HoldGO != null)
|
|
{
|
|
_HoldGO.SetActive(false);
|
|
}
|
|
if (_ReleaseGO != null)
|
|
{
|
|
_ReleaseGO.SetActive(true);
|
|
}
|
|
}
|
|
}
|