public static Message?Create(InputRemoting sender, string layoutName) { // Try to load the layout. Ignore the layout if it couldn't // be loaded. InputControlLayout layout; try { layout = sender.m_LocalManager.TryLoadControlLayout(new InternedString(layoutName)); if (layout == null) { Debug.Log(string.Format( "Could not find layout '{0}' meant to be sent through remote connection; this should not happen", layoutName)); return(null); } } catch (Exception exception) { Debug.Log(string.Format( "Could not load layout '{0}'; not sending to remote listeners (exception: {1})", layoutName, exception)); return(null); } var json = layout.ToJson(); var bytes = Encoding.UTF8.GetBytes(json); return(new Message { type = MessageType.NewLayout, data = bytes }); }
public static unsafe Message Create(InputRemoting sender, IntPtr events, int eventCount) { // Find total size of event buffer we need. var totalSize = 0u; var eventPtr = new InputEventPtr(events); for (var i = 0; i < eventCount; ++i, eventPtr = eventPtr.Next()) { totalSize += eventPtr.sizeInBytes; } // Copy event data to buffer. Would be nice if we didn't have to do that // but unfortunately we need a byte[] and can't just pass the 'events' IntPtr // directly. var data = new byte[totalSize]; fixed(byte *dataPtr = data) { UnsafeUtility.MemCpy(dataPtr, events.ToPointer(), totalSize); } // Done. return(new Message { type = MessageType.NewEvents, data = data }); }
public static unsafe void Process(InputRemoting receiver, Message msg) { var manager = receiver.m_LocalManager; 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) { ////TODO: add API to send events in bulk rather than one by one manager.QueueEvent(eventPtr); } ++eventCount; eventPtr = eventPtr.Next(); } } }
public static void Process(InputRemoting receiver, Message msg) { Debug.Log("DisconnectMsg.Process"); receiver.RemoveRemoteDevices(msg.participantId); receiver.StopSending(); }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); // Remove devices added by remote. var devices = receiver.m_Senders[senderIndex].devices; if (devices != null) { foreach (var remoteDevice in devices) { var device = receiver.m_LocalManager.TryGetDeviceById(remoteDevice.localId); if (device != null) { receiver.m_LocalManager.RemoveDevice(device); } } } ////TODO: remove layouts added by remote ArrayHelpers.EraseAt(ref receiver.m_Senders, senderIndex); ////TODO: stop sending if last remote disconnects and StartSendingOnConnect is active }
public static void Process(InputRemoting receiver, Message msg) { ////REVIEW: we probably don't want to do this blindly var layoutName = Encoding.UTF8.GetString(msg.data); receiver.m_LocalManager.RemoveControlLayout(layoutName); }
public static void Process(InputRemoting receiver, Message msg) { var json = Encoding.UTF8.GetString(msg.data); var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); receiver.m_LocalManager.RegisterControlLayout(json); ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].layouts, json); }
public static Message Create(InputRemoting sender, InputDevice device) { return(new Message { type = MessageType.RemoveDevice, data = BitConverter.GetBytes(device.id) }); }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); var @namespace = receiver.m_Senders[senderIndex].layoutNamespace; var layoutName = Encoding.UTF8.GetString(msg.data); receiver.m_LocalManager.RemoveControlLayout(layoutName, @namespace: @namespace); }
public static Message Create(InputRemoting sender, string layoutName) { var bytes = Encoding.UTF8.GetBytes(layoutName); return(new Message { type = MessageType.RemoveLayout, data = bytes }); }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); var data = DeserializeData <Data>(msg.data); // Make sure we haven't already seen the device. var devices = receiver.m_Senders[senderIndex].devices; if (devices != null) { foreach (var entry in devices) { if (entry.remoteId == data.deviceId) { Debug.LogError(string.Format( "Already received device with id {0} (layout '{1}', description '{3}) from remote {2}", data.deviceId, data.layout, msg.participantId, data.description)); return; } } } // Create device. var layout = string.Format("{0}::{1}", receiver.m_Senders[senderIndex].layoutNamespace, data.layout); InputDevice device; try { device = receiver.m_LocalManager.AddDevice(layout, string.Format("Remote{0}::{1}", msg.participantId, data.name)); } catch (Exception exception) { Debug.Log( string.Format( "Could not create remote device '{0}' with layout '{1}' locally (exception: {2})", data.description, data.layout, 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, layoutName = layout }; ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].devices, record); }
public static void Process(InputRemoting receiver, Message msg) { if (receiver.sending) { receiver.SendAllCurrentData(msg.participantId); } else if ((receiver.m_Flags & Flags.StartSendingOnConnect) == Flags.StartSendingOnConnect) { receiver.StartSending(); } }
public static void Process(InputRemoting receiver, Message msg) { if (receiver.sending) { receiver.SendAllDevices(); } else if ((receiver.m_Flags & Flags.StartSendingOnConnect) == Flags.StartSendingOnConnect) { receiver.StartSending(); } }
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); } }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); var data = DeserializeData <Data>(msg.data); // Make sure we haven't already seen the device. var devices = receiver.m_Senders[senderIndex].devices; if (devices != null) { foreach (var entry in devices) { if (entry.remoteId == data.deviceId) { Debug.LogError(string.Format( "Already received device with id {0} (layout '{1}', description '{3}) from remote {2}", data.deviceId, data.layout, msg.participantId, data.description)); return; } } } // Create device. InputDevice device; try { ////REVIEW: this gives remote devices names the same way that local devices receive them; should we make remote status visible in the name? device = receiver.m_LocalManager.AddDevice(data.layout); device.m_ParticipantId = msg.participantId; } catch (Exception exception) { Debug.LogError( $"Could not create remote device '{data.description}' with layout '{data.layout}' locally (exception: {exception})"); return; } device.m_Description = data.description; device.m_DeviceFlags |= InputDevice.DeviceFlags.Remote; // Remember it. var record = new RemoteInputDevice { remoteId = data.deviceId, localId = device.id, description = data.description, layoutName = data.layout }; ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].devices, record); }
public static Message Create(InputRemoting sender, InputDevice device) { var data = new Data { deviceId = device.id, usages = device.usages.Select(x => x.ToString()).ToArray() }; return(new Message { type = MessageType.ChangeUsages, data = SerializeData(data) }); }
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])); } } }
public static Message Create(InputRemoting sender, InputDevice device) { Debug.Assert(!device.remote, "Device being sent to remotes should be a local device, not a remote one"); var data = new Data { name = device.name, layout = device.layout, deviceId = device.id, description = device.description }; var json = JsonUtility.ToJson(data); var bytes = Encoding.UTF8.GetBytes(json); return(new Message { type = MessageType.NewDevice, data = bytes }); }
private void SetUpRemoting() { remote = new InputRemoting(manager); remote.RestoreState(m_RemotingState, manager); if (playerConnection != null) { DestroyImmediate(playerConnection); } playerConnection = CreateInstance <RemoteInputPlayerConnection>(); remote.Subscribe(playerConnection); // Feed messages from players into editor. playerConnection.Subscribe(remote); // Feed messages from editor into players. playerConnection.Bind(EditorConnection.instance, false); // We don't enable sending on the editor's remote by default. // By default, the editor acts as a receiver only. m_RemotingState = new InputRemoting.SerializedState(); }
public static void Process(InputRemoting receiver, Message msg) { receiver.StopSending(); }