LayoutListener
The LayoutListener
class is a MonoBehaviour that listens for layout changes in a Unity application. It allows you to define a list of layout callbacks that will be triggered when a layout change message is received.
Properties:
LayoutCallbacks
: A public list ofLayoutCallback
objects. EachLayoutCallback
consists of a layout name and a UnityEvent to be invoked when the corresponding layout change is detected.
Fields:
Client
: A serialized field referencing theNetPadClient
object. The script uses this reference to subscribe and unsubscribe from layout change messages.
Methods:
OnEnable()
: Called when the script is enabled. Subscribes theOnReceive
method to theLayoutMessage
event in theNetPadClient
's message processor.OnDisable()
: Called when the script is disabled. Unsubscribes theOnReceive
method from theLayoutMessage
event in theNetPadClient
's message processor.OnReceive(LayoutMessage message)
: Called when aLayoutMessage
is received. Invokes theChangeLayout
method with the identifier of the new layout.ChangeLayout(string layoutName)
: Takes a layout name as a parameter and iterates through theLayoutCallbacks
list to find a matching layout name. If found, it invokes the associated UnityEvent.
The LayoutListener
class makes it easy to manage layout changes in a Unity application by reacting to layout change messages and triggering the appropriate UnityEvents. This can be useful in various scenarios, such as adapting the user interface to different input devices or screen orientations.

Last updated