DeviceRemoveEvent.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Runtime.InteropServices;
  2. using UnityEngine.InputSystem.Utilities;
  3. namespace UnityEngine.InputSystem.LowLevel
  4. {
  5. /// <summary>
  6. /// Notifies about the removal of an input device.
  7. /// </summary>
  8. /// <remarks>
  9. /// Device that got removed is the one identified by <see cref="InputEvent.deviceId"/>
  10. /// of <see cref="baseEvent"/>.
  11. /// </remarks>
  12. [StructLayout(LayoutKind.Explicit, Size = InputEvent.kBaseEventSize)]
  13. public struct DeviceRemoveEvent : IInputEventTypeInfo
  14. {
  15. public const int Type = 0x4452454D;
  16. /// <summary>
  17. /// Common event data.
  18. /// </summary>
  19. [FieldOffset(0)]
  20. public InputEvent baseEvent;
  21. public FourCC typeStatic => Type;
  22. public unsafe InputEventPtr ToEventPtr()
  23. {
  24. fixed(DeviceRemoveEvent * ptr = &this)
  25. {
  26. return new InputEventPtr((InputEvent*)ptr);
  27. }
  28. }
  29. public static DeviceRemoveEvent Create(int deviceId, double time = -1)
  30. {
  31. var inputEvent =
  32. new DeviceRemoveEvent {baseEvent = new InputEvent(Type, InputEvent.kBaseEventSize, deviceId, time)};
  33. return inputEvent;
  34. }
  35. }
  36. }