This commit is contained in:
2026-06-01 00:23:11 +08:00
parent 1d4ca1cbef
commit 8088a70820
34 changed files with 1968 additions and 15176 deletions

View File

@@ -1,70 +0,0 @@
namespace Unity.RenderStreaming
{
#if UNITY_ANDROID && !UNITY_EDITOR
public class AndroidImagePicker : MonoBehaviour
{
private static AndroidImagePicker _instance;
private Action<Texture2D> _callback;
private AndroidJavaObject _activity;
private bool _waitingForResult;
private string _pickedImagePath;
public static AndroidImagePicker Instance
{
get
{
if (_instance == null)
{
var go = new GameObject(nameof(AndroidImagePicker));
DontDestroyOnLoad(go);
_instance = go.AddComponent<AndroidImagePicker>();
}
return _instance;
}
}
public void PickImage(Action<Texture2D> onImagePicked)
{
_callback = onImagePicked;
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
_activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
}
_activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
using (AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent",
"android.intent.action.PICK"))
{
intent.Call<AndroidJavaObject>("setType", "image/*");
using (AndroidJavaObject i = intent.Call<AndroidJavaObject>("createChooser",
_activity, "选择头像"))
{
_activity.Call("startActivity", i);
}
}
}));
_waitingForResult = true;
}
private void Update()
{
if (!_waitingForResult) return;
try
{
if (_activity == null) return;
using (AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"))
{
}
}
catch
{
// ignored
}
}
}
#endif
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 36903d0e77054ebfb5c85727f54eee63
timeCreated: 1778830795

View File

@@ -3,16 +3,33 @@ using RenderStreaming;
using Stary.Evo;
using Stary.Evo.UIFarme;
using Unity.RenderStreaming;
using Unity.XR.XREAL;
using UnityEngine;
using UnityEngine.EventSystems;
public class Main : MonoBehaviour, IController
{
private GameObject _canvasMain;
private bool _isTouchPad = false;
private void Start()
{
_canvasMain = GameObject.Find("CanvasMain");
this.GetSystem<IPanelSystem>().PushQueue<StartPanel>();
XREALVirtualController.Singleton.pointerDown += SingletonOnpointerDown;
}
void SingletonOnpointerDown(XREALButtonType arg1, GameObject arg2, PointerEventData arg3)
{
_isTouchPad = !_isTouchPad;
if (arg1 == XREALButtonType.CustomButton0)
{
_canvasMain.SetActive(_isTouchPad);
}
}
public IArchitecture GetArchitecture()
{
return MainArchitecture.Interface;

View File

@@ -59,7 +59,7 @@ namespace Script
public override UITweenType TweenType => UITweenType.Fade;
public override string UIPath => "Canvas";
public override string UIPath => "XREALVirtualController(Clone)/Canvas";
public Action<List<UsersItem>> OnUsersChangedEvnent;
private Dictionary<UsersItem, GameObject> _userMap = new();

View File

@@ -167,7 +167,6 @@ namespace Script
private void OnHangUpTogValueChanged()
{
this.GetSystem<IRenderStreamingSystem>().HangUp();
this.GetSystem<IRenderStreamingSystem>().SetLocalVideoImage(null);
this.GetSystem<IPanelSystem>().PopQueue<MainPanel>();
this.GetSystem<IPanelSystem>().PushQueue<StartPanel>();
}

View File

@@ -9,7 +9,7 @@ using UnityEngine;
using Unity.XR.XREAL;
using CameraType = Unity.XR.XREAL.CameraType;
#if UNITY_ANDROID && !UNITY_EDITOR
using GalleryDataProvider = NativeGalleryDataProvider;
using GalleryDataProvider = Unity.XR.XREAL.NativeGalleryDataProvider;
#else
using GalleryDataProvider = Unity.XR.XREAL.MockGalleryDataProvider;
#endif

View File

@@ -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

View File

@@ -58,7 +58,7 @@ namespace Unity.RenderStreaming
public override UITweenType TweenType => UITweenType.Fade;
public override string UIPath => "Canvas";
public override string UIPath => "XREALVirtualController(Clone)/Canvas";
public override void Initialize(GameObject panelGo)
{

View File

@@ -0,0 +1,103 @@
using System;
using RenderStreaming;
using Stary.Evo;
using Unity.XR.XREAL;
using UnityEngine;
using UnityEngine.UI;
namespace Script
{
public class YUVToRenderTexture : MonoBehaviour, IController
{
/// <summary>
/// 本地视频显示
/// </summary>
public RenderTexture localRenderTexture;
private Material localVideoMaterial;
private XREALRGBCameraTexture m_RGBCameraTexture;
//private RawImage _localVideoImage;
//private RawImage _textureImage;
private void Start()
{
//_localVideoImage= GameObject.Find("CanvasMain/RawImage").GetComponent<RawImage>();
//_textureImage= GameObject.Find("CanvasMain/RawImage1").GetComponent<RawImage>();
localVideoMaterial = Resources.Load<Material>("LocalRenderMaterial");
m_RGBCameraTexture = XREALRGBCameraTexture.CreateSingleton();
Play();
}
public void Play()
{
if (!m_RGBCameraTexture.IsCapturing)
{
Debug.Log($"[RGBCamera] Play");
m_RGBCameraTexture.StartCapture();
}
}
void Update()
{
var yuvTextures = m_RGBCameraTexture.GetYUVFormatTextures();
if (yuvTextures[0] != null)
{
ConvertYUVToRenderTexture(yuvTextures);
}
}
public void ConvertYUVToRenderTexture(Texture2D[] yuvTextures)
{
if (yuvTextures == null || yuvTextures.Length < 3)
return;
// 获取Y纹理的尺寸作为目标RenderTexture的尺寸
int width = yuvTextures[0].width;
int height = yuvTextures[0].height;
// if (_localVideoImage==null || _localVideoImage.rectTransform.sizeDelta.x != width ||
// _localVideoImage.rectTransform.sizeDelta.y != height)
// {
// _localVideoImage.rectTransform.sizeDelta = new Vector2(width, height);
// }
// 如果RenderTexture不存在或尺寸不匹配创建新的
if (localRenderTexture == null || localRenderTexture.width != width ||
localRenderTexture.height != height)
{
// 释放旧的RenderTexture
if (localRenderTexture != null)
localRenderTexture.Release();
// 创建新的RenderTexture
localRenderTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32);
localRenderTexture.enableRandomWrite = true;
localRenderTexture.Create();
//_textureImage.texture = localRenderTexture;
}
// 设置YUV纹理到material
//_localVideoImage.texture = yuvTextures[0];
localVideoMaterial.SetTexture("_MainTex", yuvTextures[0]);
localVideoMaterial.SetTexture("_UTex", yuvTextures[1]);
localVideoMaterial.SetTexture("_VTex", yuvTextures[2]);
Graphics.Blit(null, localRenderTexture, localVideoMaterial);
}
public void Stop()
{
if (m_RGBCameraTexture.IsCapturing)
{
if (localRenderTexture != null)
localRenderTexture.Release();
Debug.Log($"[RGBCamera] Stop");
m_RGBCameraTexture.StopCapture();
}
}
public IArchitecture GetArchitecture()
{
return MainArchitecture.Interface;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b91baefd8a244074908d2c6622615f94
timeCreated: 1780237381