How to connect and listen to the UIView stream
Example
The example below shows how connect to the UIView stream and capture all the signals that are being sent. It also shows how to get the data payload out of the Signal.
using System;
using Doozy.Runtime.Signals;
using Doozy.Runtime.UIManager;
using Doozy.Runtime.UIManager.Containers;
using UnityEngine;
namespace Sandbox
{
public class TestClass : MonoBehaviour
{
private SignalReceiver m_Receiver;
private void Awake()
{
//initialize receiver and set callback
m_Receiver = new SignalReceiver().SetOnSignalCallback(OnSignal);
}
private void OnEnable()
{
//connect receiver to the stream
UIView.stream.ConnectReceiver(m_Receiver);
}
private void OnDisable()
{
//disconnect receiver from the stream
UIView.stream.DisconnectReceiver(m_Receiver);
}
private void OnSignal(Signal signal)
{
//ignore pings
if (!signal.hasValue) return;
//ignore if the payload type does not match
if (!(signal.valueAsObject is UIViewSignalData data)) return;
//get the view category
string viewCategory = data.viewCategory;
//get the view name
string viewName = data.viewName;
//get the view command
switch (data.execute)
{
case ShowHideExecute.Show:
//show command was issued
break;
case ShowHideExecute.Hide:
//hide command was issued
break;
case ShowHideExecute.InstantShow:
//instant show command was issued
break;
case ShowHideExecute.InstantHide:
//instant hide command was issued
break;
case ShowHideExecute.ReverseShow:
//hide command was issued (but it was already performing a show, thus a reverse show was triggered)
break;
case ShowHideExecute.ReverseHide:
//show command was issued (but it was already performing a hide, thus a reverse hide was triggered)
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
Code language: PHP (php)