Add helper for update function
most of these code could be an internal helper, this would tidy up the scripts (which all use this).
void Update()
{
if(!playing) return;
if (tex == null)
{
// If received size is not null, it and scale the texture
uint i_videoHeight = 0;
uint i_videoWidth = 0;
_mediaPlayer.Size(0, ref i_videoWidth, ref i_videoHeight);
var texptr = _mediaPlayer.GetTexture(i_videoWidth, i_videoHeight, out bool updated);
if (i_videoWidth != 0 && i_videoHeight != 0 && updated && texptr != IntPtr.Zero)
{
Debug.Log("Creating texture with height " + i_videoHeight + " and width " + i_videoWidth);
tex = Texture2D.CreateExternalTexture((int)i_videoWidth,
(int)i_videoHeight,
TextureFormat.RGBA32,
false,
true,
texptr);
GetComponent<Renderer>().material.mainTexture = tex;
}
}
else if (tex != null)
{
var texptr = _mediaPlayer.GetTexture((uint)tex.width, (uint)tex.height, out bool updated);
if (updated)
{
tex.UpdateExternalTexture(texptr);
}
}
}