@@ -52,6 +52,7 @@ public class MixerInteractive : MonoBehaviour
5252 public static event OnInteractiveJoystickControlEventHandler OnInteractiveJoystickControlEvent ;
5353
5454 public delegate void OnInteractiveMessageEventHandler ( object sender , InteractiveMessageEventArgs e ) ;
55+ public static event OnInteractiveMessageEventHandler OnInteractiveMessageEvent ;
5556
5657 private static InteractivityManager interactivityManager ;
5758 private static List < InteractiveEventArgs > queuedEvents ;
@@ -116,6 +117,7 @@ private void Initialize()
116117 interactivityManager . OnParticipantStateChanged += HandleParticipantStateChanged ;
117118 interactivityManager . OnInteractiveButtonEvent += HandleInteractiveButtonEvent ;
118119 interactivityManager . OnInteractiveJoystickControlEvent += HandleInteractiveJoystickControlEvent ;
120+ interactivityManager . OnInteractiveMessageEvent += HandleInteractiveMessageEvent ;
119121 }
120122 else
121123 {
@@ -178,6 +180,11 @@ private static void HandleError(object sender, InteractiveEventArgs e)
178180 queuedEvents . Add ( e ) ;
179181 }
180182
183+ private static void HandleInteractiveMessageEvent ( object sender , InteractiveEventArgs e )
184+ {
185+ queuedEvents . Add ( e ) ;
186+ }
187+
181188 /// <summary>
182189 /// Can query the state of the InteractivityManager.
183190 /// </summary>
@@ -443,6 +450,11 @@ void Update()
443450 processedEvents . Add ( interactiveEvent ) ;
444451 break ;
445452 default :
453+ if ( OnInteractiveMessageEvent != null )
454+ {
455+ OnInteractiveMessageEvent ( this , interactiveEvent as InteractiveMessageEventArgs ) ;
456+ }
457+ processedEvents . Add ( interactiveEvent ) ;
446458 break ;
447459 }
448460 }
@@ -593,6 +605,25 @@ public static InteractiveScene GetScene(string sceneID)
593605 return InteractivityManager . SingletonInstance . GetScene ( sceneID ) ;
594606 }
595607
608+ /// <summary>
609+ /// Sends a custom message. The format must be JSON.
610+ /// </summary>
611+ /// <param name="message">The message to send.</param>
612+ public static void SendInteractiveMessage ( string message )
613+ {
614+ InteractivityManager . SingletonInstance . SendMessage ( message ) ;
615+ }
616+
617+ /// <summary>
618+ /// Sends a custom message. The message will be formatted as JSON automatically.
619+ /// </summary>
620+ /// <param name="messageType">The name of this type of message.</param>
621+ /// <param name="parameters">A collection of name / value pairs.</param>
622+ public static void SendInteractiveMessage ( string messageType , Dictionary < string , object > parameters )
623+ {
624+ InteractivityManager . SingletonInstance . SendMessage ( messageType , parameters ) ;
625+ }
626+
596627 private IEnumerator InitializeCoRoutine ( )
597628 {
598629 using ( UnityWebRequest request = UnityWebRequest . Get ( "https://beam.pro/api/v1/interactive/hosts" ) )
@@ -865,4 +896,9 @@ void OnDestroy()
865896 {
866897 ResetInternalState ( ) ;
867898 }
899+
900+ void OnApplicationQuit ( )
901+ {
902+ StopInteractive ( ) ;
903+ }
868904}
0 commit comments