zengjia
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Stary.Evo;
|
||||
using Unity.RenderStreaming;
|
||||
using Unity.XR.XREAL;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -10,8 +11,6 @@ namespace Script
|
||||
{
|
||||
void SetUp();
|
||||
void HangUp();
|
||||
|
||||
void SetLocalVideoImage(RawImage localVideoImage);
|
||||
}
|
||||
|
||||
public class RenderStreamingSystem : AbstractSystem, IRenderStreamingSystem
|
||||
@@ -45,18 +44,16 @@ namespace Script
|
||||
private SignalingManager _signalingManager;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 本地视频显示
|
||||
/// </summary>
|
||||
private RawImage localVideoImage;
|
||||
|
||||
private YUVToRenderTexture _yuvToRenderTexture;
|
||||
protected override void OnInit()
|
||||
{
|
||||
participantVideoContainer = GameObject.Find("CanvasMain/ParticipantUI").transform;
|
||||
var renderStreaming = GameObject.Find("RenderStreaming").transform;
|
||||
_signalingManager = renderStreaming.GetComponent<SignalingManager>();
|
||||
hostConnection = renderStreaming.GetComponent<HostConnection>();
|
||||
videoStreamSender = hostConnection.GetComponent<VideoStreamSender>();
|
||||
microphoneStreamer = hostConnection.GetComponent<AudioStreamSender>();
|
||||
_yuvToRenderTexture = renderStreaming.AddOrGetComponent<YUVToRenderTexture>();
|
||||
if (settings == null)
|
||||
settings = new RenderStreamingSettings();
|
||||
if (settings != null)
|
||||
@@ -100,8 +97,8 @@ namespace Script
|
||||
|
||||
private void OnStartedStream(string id)
|
||||
{
|
||||
if (videoStreamSender.sourceWebCamTexture != null && localVideoImage != null)
|
||||
localVideoImage.texture = videoStreamSender.sourceWebCamTexture;
|
||||
// if (videoStreamSender.sourceWebCamTexture != null && localVideoImage != null)
|
||||
// localVideoImage.texture = videoStreamSender.sourceWebCamTexture;
|
||||
}
|
||||
|
||||
public void SetUp()
|
||||
@@ -110,6 +107,11 @@ namespace Script
|
||||
microphoneStreamer.enabled = true;
|
||||
hostConnection.RoomConnectionId = this.GetSystem<IGlobalConfigSystem>().GetConnectionId();
|
||||
hostConnection.CreateConnection(hostConnection.RoomConnectionId);
|
||||
if (_yuvToRenderTexture != null)
|
||||
{
|
||||
_yuvToRenderTexture.Play();
|
||||
videoStreamSender.sourceTexture = _yuvToRenderTexture.localRenderTexture;
|
||||
}
|
||||
}
|
||||
|
||||
public void HangUp()
|
||||
@@ -124,14 +126,10 @@ namespace Script
|
||||
GameObject.Destroy(ui.root);
|
||||
|
||||
participantUIs.Clear();
|
||||
if (localVideoImage != null)
|
||||
localVideoImage.texture = null;
|
||||
}
|
||||
|
||||
public void SetLocalVideoImage(RawImage localVideoImage)
|
||||
{
|
||||
this.localVideoImage = localVideoImage;
|
||||
if (_yuvToRenderTexture != null)
|
||||
_yuvToRenderTexture.Stop();
|
||||
}
|
||||
|
||||
|
||||
#region 开启相关
|
||||
|
||||
@@ -176,17 +174,21 @@ namespace Script
|
||||
var ui = new ParticipantUI();
|
||||
|
||||
// 根节点
|
||||
ui.root = new GameObject($"ParticipantUI_{participantId}");
|
||||
ui.root = new GameObject($"ParticipantUI_{participantId}").AddComponent<RectTransform>().gameObject;
|
||||
ui.root.transform.SetParent(participantVideoContainer, false);
|
||||
// 添加VerticalLayoutGroup使内容垂直排列
|
||||
var vlg = ui.root.AddComponent<VerticalLayoutGroup>();
|
||||
vlg.childControlWidth = true;
|
||||
vlg.childControlHeight = false;
|
||||
vlg.childForceExpandWidth = true;
|
||||
vlg.childForceExpandHeight = false;
|
||||
vlg.spacing = 2;
|
||||
ui.root.transform.GetComponent<RectTransform>().anchorMin = Vector2.zero;
|
||||
ui.root.transform.GetComponent<RectTransform>().anchorMax = Vector2.one;
|
||||
|
||||
ui.root.transform.GetComponent<RectTransform>().anchorMin = new Vector2(0,1);
|
||||
ui.root.transform.GetComponent<RectTransform>().anchorMax = new Vector2(0,1);
|
||||
ui.root.transform.GetComponent<RectTransform>().pivot = new Vector2(0.5f,0.5f);
|
||||
if (participantUIs.Count % 2 == 0)
|
||||
{
|
||||
ui.root.transform.rotation = Quaternion.Euler(0, -45, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.root.transform.rotation = Quaternion.Euler(0, 45, 0);
|
||||
}
|
||||
|
||||
// 名称标签
|
||||
var labelObj = new GameObject("NameLabel");
|
||||
labelObj.transform.SetParent(ui.root.transform, false);
|
||||
@@ -231,6 +233,8 @@ namespace Script
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class ParticipantUI
|
||||
|
||||
Reference in New Issue
Block a user