Files
JJBB/Assets/Project/Script/GUI/Chat/ChatInfoLogItemVoice.cs
2024-08-23 15:49:34 +08:00

173 lines
4.4 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using Games.ChatHistory;
using GCGame.Table;
using Games.GlobeDefine;
using GCGame;
using Module.Log;
using Games.Item;
public class ChatVoiceInfo
{
public string url;
public float soundSec;
public string text;
public static ChatVoiceInfo GetVoiceInfo(string chatContent)
{
ChatVoiceInfo chatVoiceInfo = new ChatVoiceInfo();
var splitStrs = chatContent.Split(ChatLinkBase.StrSplit);
if (splitStrs.Length != 4)
return null;
chatVoiceInfo.url = splitStrs[1];
chatVoiceInfo.soundSec = float.Parse(splitStrs[2]);
chatVoiceInfo.text = splitStrs[3].Trim(ChatVoiceInputLogic._VoiceChatEnd);
return chatVoiceInfo;
}
}
public class ChatInfoLogItemVoice : ChatInfoLogItem
{
public Text _Scends;
public Animator _AudioAnimator;
public GameObject _ReadTips;
private string _Url;
private float _VoiceTime;
public override float GetItemHeight()
{
return _ChatInfo.preferredHeight + 25;
}
protected override bool SetDetailLog()
{
//base.SetDetailLog();
StartCoroutine(SetOrnamentBG());
ClearChat();
var voiceInfo = ChatVoiceInfo.GetVoiceInfo(_ChatHistory.ChatInfo);
if (_SenderName != null)
{
_SenderName.text = _ChatHistory.SenderName;
_SenderName.gameObject.SetActive(true);
}
if (_SenderLv != null)
{
_SenderLv.text = _ChatHistory.SenderLevel.ToString();
}
if (_SenderIcon != null)
{
string spriteName = _ChatHistory.SenderIcon;
LoadAssetBundle.Instance.SetImageSprite(_SenderIcon, spriteName);
_SenderIcon.gameObject.SetActive(true);
_SenderIconBG.gameObject.SetActive(true);
}
_Url = voiceInfo.url;
_Scends.text = voiceInfo.soundSec.ToString() + "\"";
_VoiceTime = voiceInfo.soundSec;
_ChatInfo.text = voiceInfo.text;
SetBGWidth();
GuiTextDebug.debug("VoiceUrl:" + _Url);
_AudioAnimator.Play("StopPlay");
if (_ChatHistory.SenderGuid == GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid)
{
_ReadTips.SetActive(false);
}
else
{
_ReadTips.SetActive(!_ChatHistory._ReadTip);
}
SetPrivilegeVIPIcon();
SetVIPIcon();
return true;
}
protected override void SetBGWidth()
{
if (_ChatInfoBG == null)
return;
float bgWidth = _ChatInfoBGMinSize.x;
if (_ChatInfo.preferredWidth + 20 > bgWidth && _ChatInfo.preferredWidth + 20 < _ChatInfo.rectTransform.sizeDelta.x)
{
bgWidth = _ChatInfo.preferredWidth + 25;
}
else if (_ChatInfo.preferredWidth + 20 > _ChatInfo.rectTransform.sizeDelta.x)
{
bgWidth = _ChatInfo.rectTransform.sizeDelta.x + 25;
}
_ChatInfoBG.gameObject.SetActive(true);
_ChatInfoBG.rectTransform.sizeDelta = new Vector2(Math.Min(_ChatInfoBGMinSize.x + _ChatInfo.preferredWidth, 430), _ChatInfo.preferredHeight + _ChatInfoBGMinSize.y + 20);
_LayoutElement.minHeight = _ChatInfoBG.rectTransform.rect.height;
_LayoutElement.minWidth = RectTransform.rect.width;
}
#region
private bool _IsPlaying = false;
public void OnBtnClickVoice()
{
if (_IsPlaying)
{
FinishPlay(_Url);
ChatVoice.Instance().ChatVoiceStopPlay();
}
else
{
_IsPlaying = true;
ChatVoice.Instance().ChatVoicePlay(_Url, _VoiceTime, _ChatHistory, FinishPlay);
//_AudioAnimator.Play("PlayAudioAnim");
_ChatHistory._ReadTip = true;
_ReadTips.SetActive(!_ChatHistory._ReadTip);
}
}
private void FinishPlay(string url)
{
_IsPlaying = false;
//if (_PlayingUrl == url)
//{
// _AudioAnimator.Play("StopPlay");
//}
}
public void PlayVoiceAnim()
{
_IsPlaying = true;
_AudioAnimator.Play("PlayAudioAnim");
if (_ChatHistory._ReadTip)
{
_ReadTips.SetActive(false);
}
}
public void StopVoiceAnim()
{
_IsPlaying = false;
_AudioAnimator.Play("StopPlay");
}
#endregion
}