Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit d069210

Browse files
committed
MixerInteractive.cs
My last checkin did not include this file, but should have.
1 parent 22f62b2 commit d069210

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Source/InteractiveSDK/Assets/MixerInteractive/Source/Scripts/MixerInteractive.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)