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

Commit 8f7441e

Browse files
committed
1st checkin for new controls infrastructure
This is the 1st checkin for the infrastructure for new controls.
1 parent d97aed2 commit 8f7441e

File tree

9 files changed

+613
-5
lines changed

9 files changed

+613
-5
lines changed
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using UnityEngine;
2+
3+
namespace Microsoft.Mixer
4+
{
5+
public class InteractiveCoordinatesChangedEventArgs : InteractiveEventArgs
6+
{
7+
public string ControlID
8+
{
9+
get;
10+
private set;
11+
}
12+
13+
public InteractiveParticipant Participant
14+
{
15+
get;
16+
private set;
17+
}
18+
19+
public Vector3 Position
20+
{
21+
get;
22+
private set;
23+
}
24+
25+
internal InteractiveCoordinatesChangedEventArgs(
26+
string id,
27+
InteractiveParticipant participant,
28+
Vector3 position) : base(InteractiveEventType.Coordinates)
29+
{
30+
ControlID = id;
31+
Participant = participant;
32+
Position = position;
33+
}
34+
}
35+
}

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

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public enum InteractiveEventType
6161
/// </summary>
6262
Joystick,
6363

64+
/// <summary>
65+
/// Events representing mouse button input.
66+
/// </summary>
67+
MouseButton,
68+
69+
/// <summary>
70+
/// Events representing coordinate input, where input are x, y, z values from 0 to 1.
71+
/// </summary>
72+
Coordinates,
73+
6474
/// <summary>
6575
/// Events representing text input.
6676
/// </summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Microsoft.Mixer
2+
{
3+
public class InteractiveMouseButtonEventArgs : InteractiveEventArgs
4+
{
5+
public string ControlID
6+
{
7+
get;
8+
private set;
9+
}
10+
11+
public InteractiveParticipant Participant
12+
{
13+
get;
14+
private set;
15+
}
16+
17+
public bool IsPressed
18+
{
19+
get;
20+
private set;
21+
}
22+
23+
internal InteractiveMouseButtonEventArgs(
24+
string id,
25+
InteractiveParticipant participant,
26+
bool isPressed) : base(InteractiveEventType.MouseButton)
27+
{
28+
ControlID = id;
29+
Participant = participant;
30+
IsPressed = isPressed;
31+
}
32+
}
33+
}

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

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 163 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
using System.Net;
3030
using System.Net.Security;
3131
using System.Text;
32+
using System.Threading;
3233
using UnityEngine;
34+
using UnityEngine.Networking;
35+
using System.Collections;
3336
#if UNITY_WSA && !UNITY_EDITOR
3437
using Windows.System.Threading;
3538
using System.Threading.Tasks;
@@ -44,6 +47,7 @@
4447
#endif
4548
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_IOS || UNITY_ANDROID
4649
using System.Security.Cryptography.X509Certificates;
50+
using System.Timers;
4751
using WebSocketSharp;
4852
using Microsoft.Win32;
4953
using System.Collections.Specialized;
@@ -77,12 +81,21 @@ public partial class InteractivityManager : IDisposable
7781
public delegate void OnInteractiveJoystickControlEventHandler(object sender, InteractiveJoystickEventArgs e);
7882
public event OnInteractiveJoystickControlEventHandler OnInteractiveJoystickControlEvent;
7983

84+
public delegate void OnInteractiveMouseButtonEventHandler(object sender, InteractiveMouseButtonEventArgs e);
85+
public event OnInteractiveMouseButtonEventHandler OnInteractiveMouseButtonEvent;
86+
87+
public delegate void OnInteractiveCoordinatesChangedHandler(object sender, InteractiveCoordinatesChangedEventArgs e);
88+
public event OnInteractiveCoordinatesChangedHandler OnInteractiveCoordinatesChangedEvent;
89+
8090
internal delegate void OnInteractiveTextControlEventHandler(object sender, InteractiveTextEventArgs e);
8191
internal event OnInteractiveTextControlEventHandler OnInteractiveTextControlEvent;
8292

8393
public delegate void OnInteractiveMessageEventHandler(object sender, InteractiveMessageEventArgs e);
8494
public event OnInteractiveMessageEventHandler OnInteractiveMessageEvent;
8595

96+
public delegate void OnInteractiveDoWorkEventHandler(object sender, InteractiveEventArgs e);
97+
public event OnInteractiveDoWorkEventHandler OnInteractiveDoWorkEvent;
98+
8699
private static InteractivityManager _singletonInstance;
87100

88101
/// <summary>
@@ -172,7 +185,7 @@ public IList<InteractiveParticipant> Participants
172185
}
173186
}
174187

175-
private IList<InteractiveControl> Controls
188+
internal IList<InteractiveControl> Controls
176189
{
177190
get
178191
{
@@ -1280,6 +1293,18 @@ private void RaiseQueuedInteractiveEvents()
12801293
OnInteractiveJoystickControlEvent(this, interactiveEvent as InteractiveJoystickEventArgs);
12811294
}
12821295
break;
1296+
case InteractiveEventType.MouseButton:
1297+
if (OnInteractiveMouseButtonEvent != null)
1298+
{
1299+
OnInteractiveMouseButtonEvent(this, interactiveEvent as InteractiveMouseButtonEventArgs);
1300+
}
1301+
break;
1302+
case InteractiveEventType.Coordinates:
1303+
if (OnInteractiveCoordinatesChangedEvent != null)
1304+
{
1305+
OnInteractiveCoordinatesChangedEvent(this, interactiveEvent as InteractiveCoordinatesChangedEventArgs);
1306+
}
1307+
break;
12831308
case InteractiveEventType.TextInput:
12841309
if (OnInteractiveTextControlEvent != null)
12851310
{
@@ -2514,6 +2539,44 @@ private void HandleGiveInput(JsonReader jsonReader)
25142539

25152540
uint participantID = participant.UserID;
25162541

2542+
// Handle screen input
2543+
if (inputEvent.Kind == CONTROL_KIND_SCREEN)
2544+
{
2545+
// Update x, y coordinates
2546+
if (inputEvent.Event == EVENT_NAME_MOVE)
2547+
{
2548+
Vector2 newMousePosition = new Vector2(inputEvent.X, inputEvent.Y);
2549+
// Translate the position to screen space.
2550+
newMousePosition.x *= Screen.width;
2551+
newMousePosition.y *= Screen.height;
2552+
if (_mousePositionsByParticipant.ContainsKey(participantID))
2553+
{
2554+
_mousePositionsByParticipant[participantID] = newMousePosition;
2555+
}
2556+
else
2557+
{
2558+
_mousePositionsByParticipant.Add(participantID, newMousePosition);
2559+
}
2560+
InteractiveCoordinatesChangedEventArgs mouseMoveEventArgs = new InteractiveCoordinatesChangedEventArgs(
2561+
inputEvent.ControlID,
2562+
participant,
2563+
newMousePosition
2564+
);
2565+
_queuedEvents.Add(mouseMoveEventArgs);
2566+
}
2567+
else if (inputEvent.Event == EVENT_NAME_MOUSE_DOWN ||
2568+
inputEvent.Event == EVENT_NAME_MOUSE_UP)
2569+
{
2570+
InteractiveMouseButtonEventArgs mouseButtonEventArgs = new InteractiveMouseButtonEventArgs(
2571+
inputEvent.ControlID,
2572+
participant,
2573+
inputEvent.IsPressed
2574+
);
2575+
_queuedEvents.Add(mouseButtonEventArgs);
2576+
UpdateInternalMouseButtonState(mouseButtonEventArgs);
2577+
}
2578+
}
2579+
25172580
// Put the input key values in the control data structure.
25182581
string controlID = inputEvent.ControlID;
25192582
string controlType = inputEvent.Kind;
@@ -2797,6 +2860,13 @@ private bool TryGetJoystickStateByParticipant(uint userID, string controlID, out
27972860
return joystickExists;
27982861
}
27992862

2863+
internal InternalMouseButtonState TryGetMouseButtonState(uint userID)
2864+
{
2865+
InternalMouseButtonState mouseButtonState = new InternalMouseButtonState();
2866+
_mouseButtonStateByParticipant.TryGetValue(userID, out mouseButtonState);
2867+
return mouseButtonState;
2868+
}
2869+
28002870
internal string GetText(string controlID, uint userID)
28012871
{
28022872
string text = string.Empty;
@@ -3442,11 +3512,11 @@ private void SendJsonString(string jsonString)
34423512
private const string WS_MESSAGE_KEY_Y = "y";
34433513

34443514
// Values
3445-
private const string WS_MESSAGE_VALUE_CONTROL_TYPE_BUTTON = "button";
3515+
internal const string WS_MESSAGE_VALUE_CONTROL_TYPE_BUTTON = "button";
34463516
internal const string WS_MESSAGE_VALUE_DISABLED = "disabled";
34473517
internal const string WS_MESSAGE_VALUE_DEFAULT_GROUP_ID = "default";
34483518
internal const string WS_MESSAGE_VALUE_DEFAULT_SCENE_ID = "default";
3449-
private const string WS_MESSAGE_VALUE_CONTROL_TYPE_JOYSTICK = "joystick";
3519+
internal const string WS_MESSAGE_VALUE_CONTROL_TYPE_JOYSTICK = "joystick";
34503520
internal const string WS_MESSAGE_VALUE_CONTROL_TYPE_LABEL = "label";
34513521
internal const string WS_MESSAGE_VALUE_CONTROL_TYPE_TEXTBOX = "textbox";
34523522
private const bool WS_MESSAGE_VALUE_TRUE = true;
@@ -3493,6 +3563,7 @@ private void SendJsonString(string jsonString)
34933563
internal const string CONTROL_TYPE_JOYSTICK = "joystick";
34943564
internal const string CONTROL_KIND_LABEL = "label";
34953565
internal const string CONTROL_KIND_TEXTBOX = "textbox";
3566+
internal const string CONTROL_KIND_SCREEN = "screen";
34963567

34973568
// Event names
34983569
private const string EVENT_NAME_MOUSE_DOWN = "mousedown";
@@ -3519,6 +3590,8 @@ private void SendJsonString(string jsonString)
35193590
internal static Dictionary<string, InternalJoystickState> _joystickStates;
35203591
internal static Dictionary<uint, Dictionary<string, InternalJoystickState>> _joystickStatesByParticipant;
35213592
internal static Dictionary<uint, Dictionary<string, string>> _textboxValuesByParticipant;
3593+
internal static Dictionary<uint, InternalMouseButtonState> _mouseButtonStateByParticipant;
3594+
internal static Dictionary<uint, Vector2> _mousePositionsByParticipant;
35223595

35233596
// Generic data structures for storing any control data
35243597
internal static Dictionary<string, Dictionary<uint, Dictionary<string, object>>> _giveInputControlDataByParticipant;
@@ -3583,6 +3656,8 @@ private void InitializeInternal()
35833656

35843657
_joystickStates = new Dictionary<string, InternalJoystickState>();
35853658
_joystickStatesByParticipant = new Dictionary<uint, Dictionary<string, InternalJoystickState>>();
3659+
_mouseButtonStateByParticipant = new Dictionary<uint, InternalMouseButtonState>();
3660+
_mousePositionsByParticipant = new Dictionary<uint, Vector2>();
35863661

35873662
_participantsWhoTriggeredGiveInput = new Dictionary<string, InternalParticipantTrackingState>();
35883663
_queuedControlPropertyUpdates = new Dictionary<string, Dictionary<string, InternalControlPropertyUpdateData>>();
@@ -3695,6 +3770,56 @@ private void ClearPreviousControlState()
36953770
}
36963771
}
36973772

3773+
// Mouse button state
3774+
List<uint> _mouseButtonStateByParticipantKeys = new List<uint>(_mouseButtonStateByParticipant.Keys);
3775+
foreach (uint _mouseButtonStateByParticipantKey in _mouseButtonStateByParticipantKeys)
3776+
{
3777+
InternalMouseButtonState oldMouseButtonState = _mouseButtonStateByParticipant[_mouseButtonStateByParticipantKey];
3778+
InternalMouseButtonState newMouseButtonState = new InternalMouseButtonState();
3779+
// If we just recieved a mouse down, but not an up, then the state is pressed
3780+
if (oldMouseButtonState.NextIsDown)
3781+
{
3782+
newMouseButtonState.IsDown = true;
3783+
newMouseButtonState.IsPressed = true;
3784+
newMouseButtonState.IsUp = false;
3785+
3786+
newMouseButtonState.NextIsDown = false;
3787+
newMouseButtonState.NextIsPressed = true;
3788+
newMouseButtonState.NextIsUp = false;
3789+
}
3790+
else if (oldMouseButtonState.NextIsUp)
3791+
{
3792+
newMouseButtonState.IsDown = false;
3793+
newMouseButtonState.IsPressed = false;
3794+
newMouseButtonState.IsUp = true;
3795+
3796+
newMouseButtonState.NextIsDown = false;
3797+
newMouseButtonState.NextIsPressed = false;
3798+
newMouseButtonState.NextIsUp = false;
3799+
}
3800+
else if (oldMouseButtonState.NextIsPressed)
3801+
{
3802+
newMouseButtonState.IsDown = false;
3803+
newMouseButtonState.IsPressed = true;
3804+
newMouseButtonState.IsUp = false;
3805+
3806+
newMouseButtonState.NextIsDown = false;
3807+
newMouseButtonState.NextIsPressed = true;
3808+
newMouseButtonState.NextIsUp = false;
3809+
}
3810+
else
3811+
{
3812+
newMouseButtonState.IsDown = false;
3813+
newMouseButtonState.IsPressed = false;
3814+
newMouseButtonState.IsUp = false;
3815+
3816+
newMouseButtonState.NextIsDown = false;
3817+
newMouseButtonState.NextIsPressed = false;
3818+
newMouseButtonState.NextIsUp = false;
3819+
}
3820+
_mouseButtonStateByParticipant[_mouseButtonStateByParticipantKey] = newMouseButtonState;
3821+
}
3822+
36983823
var controlIDKeys = new List<string>(_participantsWhoTriggeredGiveInput.Keys);
36993824
foreach (string controlIDKey in controlIDKeys)
37003825
{
@@ -3904,6 +4029,31 @@ private void UpdateInternalTextBoxState(InteractiveTextEventArgs e)
39044029
_textboxValuesByParticipant[e.Participant.UserID][e.ControlID] = text;
39054030
}
39064031

4032+
private void UpdateInternalMouseButtonState(InteractiveMouseButtonEventArgs e)
4033+
{
4034+
// Make sure the entry exists
4035+
uint participantId = e.Participant.UserID;
4036+
bool isPressed = e.IsPressed;
4037+
InternalMouseButtonState buttonState;
4038+
bool participantEntryExists = _mouseButtonStateByParticipant.TryGetValue(participantId, out buttonState);
4039+
if (!participantEntryExists)
4040+
{
4041+
buttonState = new InternalMouseButtonState();
4042+
buttonState.IsDown = false;
4043+
buttonState.IsPressed = false;
4044+
buttonState.IsUp = false;
4045+
buttonState.NextIsDown = e.IsPressed;
4046+
buttonState.NextIsPressed = e.IsPressed;
4047+
buttonState.NextIsUp = !e.IsPressed;
4048+
_mouseButtonStateByParticipant.Add(participantId, buttonState);
4049+
}
4050+
InternalMouseButtonState newState = _mouseButtonStateByParticipant[participantId];
4051+
newState.NextIsDown = isPressed;
4052+
newState.NextIsPressed = isPressed;
4053+
newState.NextIsUp = !isPressed;
4054+
_mouseButtonStateByParticipant[participantId] = newState;
4055+
}
4056+
39074057
internal void _QueuePropertyUpdate(string sceneID, string controlID, string name, bool value)
39084058
{
39094059
KnownControlPropertyPrimitiveTypes type = KnownControlPropertyPrimitiveTypes.Boolean;
@@ -4110,6 +4260,16 @@ internal struct InternalJoystickState
41104260
internal int countOfUniqueJoystickInputs;
41114261
}
41124262

4263+
internal struct InternalMouseButtonState
4264+
{
4265+
internal bool IsDown;
4266+
internal bool IsPressed;
4267+
internal bool IsUp;
4268+
internal bool NextIsDown;
4269+
internal bool NextIsPressed;
4270+
internal bool NextIsUp;
4271+
}
4272+
41134273
internal struct InternalParticipantTrackingState
41144274
{
41154275
internal InteractiveParticipant previousParticpant;

0 commit comments

Comments
 (0)