A game about forced loneliness, made by TACStudios
1using System; 2using System.Runtime.InteropServices; 3using UnityEngine.InputSystem.Utilities; 4 5namespace UnityEngine.InputSystem.LowLevel 6{ 7 /// <summary> 8 /// A single character text input event. 9 /// </summary> 10 /// <remarks> 11 /// Text input does not fit the control-based input model well and thus is 12 /// represented as its own form of input. A device that is capable of receiving 13 /// text input (such as <see cref="Keyboard"/>) receives text input events 14 /// and should implement <see cref="ITextInputReceiver"/> in order for the 15 /// input system to be able to relay these events to the device. 16 /// </remarks> 17 [StructLayout(LayoutKind.Explicit, Size = InputEvent.kBaseEventSize + 4)] 18 public struct TextEvent : IInputEventTypeInfo 19 { 20 public const int Type = 0x54455854; 21 22 [FieldOffset(0)] 23 public InputEvent baseEvent; 24 25 /// <summary> 26 /// Character in UTF-32 encoding. 27 /// </summary> 28 [FieldOffset(InputEvent.kBaseEventSize)] 29 public int character; 30 31 public FourCC typeStatic => Type; 32 33 public static unsafe TextEvent* From(InputEventPtr eventPtr) 34 { 35 if (!eventPtr.valid) 36 throw new ArgumentNullException(nameof(eventPtr)); 37 if (!eventPtr.IsA<TextEvent>()) 38 throw new InvalidCastException(string.Format("Cannot cast event with type '{0}' into TextEvent", 39 eventPtr.type)); 40 41 return (TextEvent*)eventPtr.data; 42 } 43 44 public static TextEvent Create(int deviceId, char character, double time = -1) 45 { 46 ////TODO: detect and throw when if character is surrogate 47 var inputEvent = new TextEvent 48 { 49 baseEvent = new InputEvent(Type, InputEvent.kBaseEventSize + 4, deviceId, time), 50 character = character 51 }; 52 return inputEvent; 53 } 54 55 public static TextEvent Create(int deviceId, int character, double time = -1) 56 { 57 var inputEvent = new TextEvent 58 { 59 baseEvent = new InputEvent(Type, InputEvent.kBaseEventSize + 4, deviceId, time), 60 character = character 61 }; 62 return inputEvent; 63 } 64 } 65}