A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR || PACKAGE_DOCS_GENERATION
2using System.ComponentModel;
3using UnityEngine.InputSystem.LowLevel;
4using UnityEditor;
5
6namespace UnityEngine.InputSystem.Processors
7{
8 /// <summary>
9 /// If Unity is currently in an <see cref="EditorWindow"/> callback, transforms a 2D coordinate from
10 /// player window space into window space of the current EditorWindow.
11 /// </summary>
12 /// <remarks>
13 /// This processor is only available in the editor. Also, it only works on devices that
14 /// support the <see cref="QueryEditorWindowCoordinatesCommand"/> request.
15 ///
16 /// Outside of <see cref="EditorWindow"/> callbacks, this processor does nothing and just passes through
17 /// the coordinates it receives.
18 /// </remarks>
19 /// <seealso cref="Pointer.position"/>
20 [DesignTimeVisible(false)]
21 public class EditorWindowSpaceProcessor : InputProcessor<Vector2>
22 {
23 /// <summary>
24 /// Transform the given player screen-space coordinate into the coordinate space of the current
25 /// <c>EditorWindow</c>.
26 /// </summary>
27 /// <param name="value">GameView screen space coordinate.</param>
28 /// <param name="control">Ignored.</param>
29 /// <returns>The given coordinate transformed into <c>EditorWindow</c> space.</returns>
30 /// <remarks>
31 /// This method will only succeed if the editor is currently in an <c>EditorWindow</c> callback such
32 /// as <c>OnGUI</c>.
33 /// </remarks>
34 public override Vector2 Process(Vector2 value, InputControl control)
35 {
36 // We go and fire trigger QueryEditorWindowCoordinatesCommand regardless
37 // of whether we are currently in EditorWindow code or not. The expectation
38 // here is that the underlying editor code is in a better position than us
39 // to judge whether the conversion should be performed or not. In native code,
40 // the IOCTL implementations will early out if they detect that the current
41 // EditorWindow is in fact a game view.
42
43 if (Mouse.s_PlatformMouseDevice != null)
44 {
45 var command = QueryEditorWindowCoordinatesCommand.Create(value);
46 // Not all pointer devices implement the editor window position IOCTL,
47 // so we try the global mouse device if available.
48 if (Mouse.s_PlatformMouseDevice.ExecuteCommand(ref command) > 0)
49 return command.inOutCoordinates;
50 }
51
52 return value;
53 }
54 }
55}
56#endif // UNITY_EDITOR