Intermediate – Complex Native Objects And Texture Access

Now that we have our bridge from Unity set up, we can start building out the real plugin. I typically use singleton object for my plugins, as it provides a single entry point from our C functions.

The singleton allows us to have a persistent object that we can easily reference. The remainder of the setup is a little bit specific to to this plugin, but I’ll include it as an example. We’re going to set up an AVPlayer to play our video, to start.

We’ve got our AVPlayer setup to play our video, now we need to push it back into Unity. To do that, we’re going to write our frames into a texture. We need to add a few new methods to point to the correct texture, and to actually render the video.

On the Unity end, we’ll need to pass in some data before our video can play.

This is basically it! This isn’t exactly robust, there’s a lot more that needs to go in to build something stable and usable. This has no error checking, no looping, no scaling, no video gravity, etc. But, those things aren’t really relevant to this post, just good practices.

I have my Unity scene set up like this:

When I run the app on my device, I see my video playing on the texture: