UnityPlugin-AVProVideo icon indicating copy to clipboard operation
UnityPlugin-AVProVideo copied to clipboard

Support for UI Toolkit

Open midiphony opened this issue 4 years ago • 2 comments

UI Toolkit, the future main UI framework supported by Unity, will be production-ready starting from Unity 2021.2.

Many users have started to use it in its preview package version.

In this framework, we can set the background of VisualElements, as long as the source object is a RenderTexture or a Texture2D.

I am currently diving into the AVProVideo API and docs, and I was wondering :

  • Is it planned to support rendering of videos in a UI designed and rendered with UI Toolkit ?

Otherwise, I have the following question :

  • Currently, given the types of source object supported by UI Toolkit (RenderTexture and Texture2D), do you have some tips or recommendations to use the output of a MediaPlayer as the background source of a UI Toolkit's VisualElement ?

Thanks

midiphony avatar Jun 15 '21 18:06 midiphony

This is what I naively tried, to use AVProVideo's MediaPlayer with UI Toolkit.

After waiting for the first frame to be ready, I set the UI element texture like this : Texture2D texture2D = (Texture2D)_mediaPlayer.TextureProducer.GetTexture(0); _videoUiElement.style.backgroundImage = Background.FromTexture2D(texture2D); Texture is YFlipped on Windows without additional operation, but OK on Android (OpenGL). Also, I wonder if the (Texture2D) cast will always succeed, or if there are cases where the MediaPlayer texture can be of another type, like a RenderTexture.

It looks like the recommended way to use AVProVideo is to rely on the ApplyToMaterial, ApplyToMesh, DisplayUGUI, which all use custom shaders that you made.

Are there particular consequences, tips, or warnings that you know of, when directly using the texture produced by the MediaPlayer ?

(I understand that there is no priority yet to provide support with UI Toolkit. Nonetheless, any help/info will be appreciated :p)

midiphony avatar Jun 16 '21 16:06 midiphony