Files
cloud-mainworld/ufm cloud/Assets/#User/Community Modules/Scripts/#Scripts Backup/GetVideoPlayerTexture.cs._20260703-070904.txt
T
2026-10-22 12:41:09 +01:00

51 lines
1.4 KiB
Plaintext

using SomniumSpace.Bridge.Components;
using UnityEngine;
using WebSocketSharp;
namespace CommunityModules
{
public class GetVideoPlayerTexture : MonoBehaviour
{
[SerializeField] private GameObject _videoPlayerObject;
[SerializeField] private Material[] _materials = new Material[0];
[SerializeField] private string _textureName = "_MainTex";
private SomniumVideoPlayer _videoPlayerRef;
private Texture _videoTexture = null;
// Start is called before the first frame update
void Start()
{
InvokeRepeating(nameof(GetTexture), 1.0f, 1.0f);
}
private void GetTexture()
{
if (_materials == null ||
_videoPlayerObject == null)
return;
if (_videoPlayerRef == null) // _videoPlayerObject
_videoPlayerRef = _videoPlayerObject.GetComponent<SomniumVideoPlayer>();
if (_videoTexture == null)
{
_videoTexture = _videoPlayerRef.GetTexture();
AssignTexture();
}
}
private void AssignTexture()
{
if (_textureName.IsNullOrEmpty())
return;
foreach (var mat in _materials)
{
if (mat != null)
mat.SetTexture(_textureName, _videoTexture);
}
}
}
}