@@ -52,6 +52,7 @@ public class MixerInteractive : MonoBehaviour
52
52
public static event OnInteractiveJoystickControlEventHandler OnInteractiveJoystickControlEvent ;
53
53
54
54
public delegate void OnInteractiveMessageEventHandler ( object sender , InteractiveMessageEventArgs e ) ;
55
+ public static event OnInteractiveMessageEventHandler OnInteractiveMessageEvent ;
55
56
56
57
private static InteractivityManager interactivityManager ;
57
58
private static List < InteractiveEventArgs > queuedEvents ;
@@ -116,6 +117,7 @@ private void Initialize()
116
117
interactivityManager . OnParticipantStateChanged += HandleParticipantStateChanged ;
117
118
interactivityManager . OnInteractiveButtonEvent += HandleInteractiveButtonEvent ;
118
119
interactivityManager . OnInteractiveJoystickControlEvent += HandleInteractiveJoystickControlEvent ;
120
+ interactivityManager . OnInteractiveMessageEvent += HandleInteractiveMessageEvent ;
119
121
}
120
122
else
121
123
{
@@ -178,6 +180,11 @@ private static void HandleError(object sender, InteractiveEventArgs e)
178
180
queuedEvents . Add ( e ) ;
179
181
}
180
182
183
+ private static void HandleInteractiveMessageEvent ( object sender , InteractiveEventArgs e )
184
+ {
185
+ queuedEvents . Add ( e ) ;
186
+ }
187
+
181
188
/// <summary>
182
189
/// Can query the state of the InteractivityManager.
183
190
/// </summary>
@@ -443,6 +450,11 @@ void Update()
443
450
processedEvents . Add ( interactiveEvent ) ;
444
451
break ;
445
452
default :
453
+ if ( OnInteractiveMessageEvent != null )
454
+ {
455
+ OnInteractiveMessageEvent ( this , interactiveEvent as InteractiveMessageEventArgs ) ;
456
+ }
457
+ processedEvents . Add ( interactiveEvent ) ;
446
458
break ;
447
459
}
448
460
}
@@ -593,6 +605,25 @@ public static InteractiveScene GetScene(string sceneID)
593
605
return InteractivityManager . SingletonInstance . GetScene ( sceneID ) ;
594
606
}
595
607
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
+
596
627
private IEnumerator InitializeCoRoutine ( )
597
628
{
598
629
using ( UnityWebRequest request = UnityWebRequest . Get ( "https://beam.pro/api/v1/interactive/hosts" ) )
@@ -865,4 +896,9 @@ void OnDestroy()
865
896
{
866
897
ResetInternalState ( ) ;
867
898
}
899
+
900
+ void OnApplicationQuit ( )
901
+ {
902
+ StopInteractive ( ) ;
903
+ }
868
904
}
0 commit comments