using BeinLab.Util;
using ShadowStudio.Mgr;
using ShadowStudio.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XRTool.Util;
using XRTool.WorldUI;
using static BoundingBox;
namespace ShadowStudio.Model
{
///
/// 用户的视频通话窗口
///
public class PlayerViewComponent : UIComponent
{
public static string viewId = "ArtId_PlayerView";
public static Dictionary viewDic = new Dictionary();
private string peerid;
private bool isInit = false;
private Peer _peer;
public static event Action ViewChange;
///
/// 创建一个视频通话窗口
/// 即时同步
///
/// 点击的用户的id
///
public static void CreateViewComponent(string peerid, Transform target, bool isDel = false)
{
if (viewDic.ContainsKey(peerid))
{
return;
}
GoodsInfo data = new GoodsInfo();
var info = ArtInfoMgr.Instance.GetArtInfo(viewId);
data.art_id = viewId;
data.id = UnityEngine.Random.Range(100000, 999999999);
if (target)
{
data.goods_info = UnityUtil.TransferToString(target, 2);
}
else
{
data.goods_info = UnityUtil.ArtTransferInfo(info);
}
data.goods_name = peerid;
data.rid = int.Parse(UserInfoMgr.Instance.userConfig.Id);
data.scene_id = -1;
///创建本地窗口
ArtInfoMgr.Instance.SyncGoods(data);
///
///ArtInfoMgr.Instance.SendTransfer(data);
if (target && isDel)
{
Destroy(target.gameObject);
}
}
private bool checkRtc()
{
if (_peer != null)
{
if (cPeer != null)
{
return true;
}
else
{
cPeer = AgoraRTCManager.Instance.GetCustomPeer(_peer.PeerId);
return true;
}
}
return false;
}
void StateUpdata()
{
if (cPeer.isVideo)
{
if (cPeer.isOpenVideo)
{
openVideo.SetActive(false);
closeVideo.SetActive(false);
pauseVideo.SetActive(true);
VideoEmpty.gameObject.SetActive(true);
agoraShowVideo.gameObject.SetActive(false);
}
else
{
openVideo.SetActive(false);
closeVideo.SetActive(true);
pauseVideo.SetActive(false);
VideoEmpty.gameObject.SetActive(false);
agoraShowVideo.gameObject.SetActive(true);
}
}
else
{
openVideo.SetActive(true);
closeVideo.SetActive(false);
pauseVideo.SetActive(false);
VideoEmpty.gameObject.SetActive(true);
agoraShowVideo.gameObject.SetActive(false);
}
if (cPeer.isAudio)
{
if (cPeer.isOpenAduio)
{
openAudio.SetActive(false);
closeAudio.SetActive(false);
pauseAudio.SetActive(true);
}
else
{
openAudio.SetActive(false);
closeAudio.SetActive(true);
pauseAudio.SetActive(false);
}
}
else
{
openAudio.SetActive(true);
closeAudio.SetActive(false);
pauseAudio.SetActive(false);
}
}
public float volume = 0.2f;
public Text textMic;
public GameObject pauseCerAudio;
public GameObject pauseCerVideo;
public GameObject pauseAudio;
public GameObject pauseVideo;
public GameObject openVideo;
public GameObject closeVideo;
public MeshRenderer videoBG;
public Text nametext;
public XRIcon touxiang;
public GameObject openAudio;
public GameObject closeAudio;
public GameObject VolumnGo;
public RawImage agoraShowVideo;
private void Update()
{
checkRtc();
StateUpdata();
}
bool isRtcInit = false;
AgoraCustomPeer cPeer;
public void setVideo(string peerid)
{
_peer = UserItemList.Instance.GetPeer(peerid);
nametext.text = _peer.NickName;
if (peerid == CommonMethod.MyPeer.PeerId)
{
isRtcInit = true;
return;
}
else
{
Debug.Log(" Peerid != MyPeer" + peerid);
}
}
public void addMic()
{
volume += 0.1f;
}
public void redMic()
{
volume -= 0.1f;
}
public void openMic()
{
if (_peer.IsSlef)
{
AgoraRTCManager.Instance.MuteLocalAudioStream(true);
}
else
{
AgoraRTCManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true);
}
}
public void closeMic()
{
if (_peer.IsSlef)
{
AgoraRTCManager.Instance.MuteLocalAudioStream(false);
}
else
{
AgoraRTCManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false);
}
}
public void OpenVideo()
{
if (_peer.IsSlef)
{
AgoraRTCManager.Instance.MuteLocalVideoStream(true);
}
else
{
AgoraRTCManager.Instance.MuteRemoteVideoStream(cPeer.peerId, true);
}
}
public void CloseVideo()
{
if (_peer.IsSlef)
{
AgoraRTCManager.Instance.MuteLocalVideoStream(false);
}
else
{
AgoraRTCManager.Instance.MuteRemoteVideoStream(cPeer.peerId, false);
}
}
private Button closeBtn;
public Button CloseBtn
{
get
{
if (!closeBtn)
{
closeBtn = UnityUtil.GetBreadthChild