Example #1
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var @namespace  = receiver.m_Senders[senderIndex].templateNamespace;

                var templateName = Encoding.UTF8.GetString(msg.data);

                receiver.m_LocalManager.RemoveTemplate(templateName, @namespace: @namespace);
            }
Example #2
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var json        = Encoding.UTF8.GetString(msg.data);
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var @namespace  = receiver.m_Senders[senderIndex].templateNamespace;

                receiver.m_LocalManager.RegisterTemplate(json, @namespace: @namespace);
                ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].templates, json);
            }
Example #3
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex    = receiver.FindOrCreateSenderRecord(msg.participantId);
                var remoteDeviceId = BitConverter.ToInt32(msg.data, 0);

                var device = receiver.TryGetDeviceByRemoteId(remoteDeviceId, senderIndex);

                if (device != null)
                {
                    receiver.m_LocalManager.RemoveDevice(device);
                }
            }
Example #4
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var data        = DeserializeData <Data>(msg.data);

                var device = receiver.TryGetDeviceByRemoteId(data.deviceId, senderIndex);

                if (device != null)
                {
                    ////TODO: clearing usages and setting multiple usages

                    if (data.usages.Length == 1)
                    {
                        receiver.m_LocalManager.SetUsage(device, new InternedString(data.usages[0]));
                    }
                }
            }
Example #5
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);

                // Remove devices added by remote.
                foreach (var remoteDevice in receiver.m_Senders[senderIndex].devices)
                {
                    var device = receiver.m_LocalManager.TryGetDeviceById(remoteDevice.localId);
                    if (device != null)
                    {
                        receiver.m_LocalManager.RemoveDevice(device);
                    }
                }

                ////TODO: remove templates added by remote

                ArrayHelpers.EraseAt(ref receiver.m_Senders, senderIndex);

                ////TODO: stop sending if last remote disconnects and StartSendingOnConnect is active
            }
Example #6
0
            public static unsafe void Process(InputRemoting receiver, Message msg)
            {
                // This isn't the best solution but should do for now. NativeInputSystem isn't
                // designed for having multiple InputManagers and we only have that scenario
                // for tests ATM. So, to make InputManagers that aren't really properly connected
                // still work for testing, we directly feed them the events we get here.
                var isConnectedToNative = NativeInputSystem.onUpdate == receiver.m_LocalManager.OnNativeUpdate;

                fixed(byte *dataPtr = msg.data)
                {
                    var dataEndPtr  = new IntPtr(dataPtr + msg.data.Length);
                    var eventCount  = 0;
                    var eventPtr    = new InputEventPtr((InputEvent *)dataPtr);
                    var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);

                    while (eventPtr.data.ToInt64() < dataEndPtr.ToInt64())
                    {
                        // Patch up device ID to refer to local device and send event.
                        var remoteDeviceId = eventPtr.deviceId;
                        var localDeviceId  = receiver.FindLocalDeviceId(remoteDeviceId, senderIndex);
                        eventPtr.deviceId = localDeviceId;

                        if (localDeviceId != InputDevice.kInvalidDeviceId && isConnectedToNative)
                        {
                            ////TODO: add API to send events in bulk rather than one by one
                            InputSystem.QueueEvent(eventPtr);
                        }

                        ++eventCount;
                        eventPtr = eventPtr.Next();
                    }

                    if (!isConnectedToNative)
                    {
                        receiver.m_LocalManager.OnNativeUpdate(NativeInputUpdateType.Dynamic, eventCount, new IntPtr(dataPtr));
                    }
                }
            }
Example #7
0
            public static void Process(InputRemoting receiver, Message msg)
            {
                var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId);
                var data        = DeserializeData <Data>(msg.data);

                // Create device.
                var template = string.Format("{0}::{1}", receiver.m_Senders[senderIndex].templateNamespace,
                                             data.template);
                InputDevice device;

                try
                {
                    device = receiver.m_LocalManager.AddDevice(template,
                                                               string.Format("Remote{0}::{1}", msg.participantId, data.name));
                }
                catch (Exception exception)
                {
                    Debug.Log(
                        string.Format(
                            "Could not create remote device '{0}' with template '{1}' locally (exception: {2})",
                            data.description, data.template, exception));
                    return;
                }
                device.m_Description = data.description;
                device.m_Flags      |= InputDevice.Flags.Remote;

                // Remember it.
                var record = new RemoteInputDevice
                {
                    remoteId     = data.deviceId,
                    localId      = device.id,
                    description  = data.description,
                    templateName = template
                };

                ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].devices, record);
            }