Skip to main content

Core Architecture

The way that the architecture is setup is based on the pub/sub concept, but implemented using custom udon events. These events allow for the modular extension of the TV without having to get too into the nitty-gritty of the TV itself.

The Udon

There are two scripts that compose the core of the TV: TVManager and VPManager The TVManager script is the main workhorse. This is the behavior that manages the TV's state, triggers events for external behaviors, and proxies actions to the respective video manager scripts.
Conversely, the VPManager script is a lightweight proxy that captures events from the backing video player system (AVPro/Unity) and forwards that back to the tv manager script. It also manages the internal state of any speakers (audio sources) or screens (renderers) that are associated with it.

To make a TV from scratch is not difficult. Just make sure to add any desired VPManager scripts to the Video Managers list on the TVManager. The same goes for any screens or speakers associated with a video player that has a VPManager script associated; make sure to fill out the Speakers and Screens list in the inspector with any of the respective audio sources or renderers that relate to that video player.

Dynamically Controlling the TV

With the pub/sub style event system, there is a bit of a unique implementation for interacting with it. This was made in such a way to easily support Udon not written in U# (like uGraph).
There are a few events that have to take some kind of input or output data to act upon. For example, trying to change the TV's active video from custom script. This is accomplished through some predefined variables. These variables ALWAYS come in the form of:
(IN or OUT) + _ + meaningfulTerm

Continuing the example, To change the active URL from a udon graph script, one would need to do the following in order:

  • Have a VRCUrl reference/instance ready (eg: URL)
  • Use the node and inputs UdonBehavior -> SetProgramVariable [ tv, "IN_MAINURL", URL ]
  • Use the node and inputs UdonBehavior -> SendCustomEvent [ tv, "_ChangeMedia" ]

UdonGraph showing how to change the url on the TV

U# method: tv._ChangeMedia(URL, null, null);

And that's it. The specifics of this are that there is a handful of events that need some input data.
The input data variables need to be set before calling the corresponding event. In the case of the url change, it's the IN_URL.

You can read more about the TV's API surface on the TV Manager Scripting API page.

Conversely, there are some events that the TV produces that intends to deliver some data to the listener behaviors. For example, if the TV's volume is modified at any point, it will set the OUT_VOLUME variable to the volume as normalized value (0f to 1f) and then call the _TvVolumeChange event on the listeners.

To receive the volume data, you would need a variable on your listener behavior with the name OUT_VOLUME as well as a custom event (public void method for U#) that has the name _TvVolumeChange. You can then use the variable to do whatever you need to do.

UdonGraph showing how to change the url on the TV

You can read more about the plugin events on the TV Plugin API Doc page.