Skip to content

Commit 5e9bc34

Browse files
author
Rene Damm
authored
FIX: EditorWindow space not appearing to work (case 1191859, #938).
1 parent 37f94d7 commit 5e9bc34

File tree

12 files changed

+109
-9
lines changed

12 files changed

+109
-9
lines changed

Assets/Samples/EditorWindowDemo.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"displayName": "EditorWindow Demo",
3+
"description": "A simple example of how to use the input system from within EditorWindow code."
4+
}

Assets/Samples/EditorWindowDemo/Editor.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using UnityEditor;
2+
using UnityEngine.InputSystem;
3+
4+
public class EditorWindowDemo : EditorWindow
5+
{
6+
[MenuItem("Window/Input System Editor Window Demo")]
7+
public static void Open()
8+
{
9+
GetWindow<EditorWindowDemo>();
10+
}
11+
12+
protected void OnGUI()
13+
{
14+
// Grab the current pointer device (mouse, pen, touchscreen).
15+
var pointer = Pointer.current;
16+
if (pointer == null)
17+
return;
18+
19+
// Pointer positions should automatically be converted to EditorWindow space of
20+
// the current window. Unlike player window coordinates, this uses UI window space,
21+
// i.e. Y goes top down rather than bottom up.
22+
var position = pointer.position.ReadValue();
23+
var pressure = pointer.pressure.ReadValue();
24+
var contact = pointer.press.isPressed;
25+
26+
EditorGUILayout.LabelField($"Device: {pointer}");
27+
EditorGUILayout.LabelField($"Position: {position}");
28+
EditorGUILayout.LabelField($"Pressure: {pressure}");
29+
EditorGUILayout.LabelField($"Contact?: {contact}");
30+
31+
// Just for kicks, also read out some data from the currently used gamepad (if any).
32+
var gamepad = Gamepad.current;
33+
if (gamepad != null)
34+
{
35+
EditorGUILayout.Space();
36+
EditorGUILayout.LabelField($"Gamepad Left Stick: {gamepad.leftStick.ReadValue()}");
37+
EditorGUILayout.LabelField($"Gamepad Right Stick: {gamepad.leftStick.ReadValue()}");
38+
}
39+
40+
// We want to constantly refresh to show the current values so trigger
41+
// another refresh right away. Otherwise, the values we show will only
42+
// update periodically.
43+
Repaint();
44+
}
45+
}

Assets/Samples/EditorWindowDemo/Editor/EditorWindowDemo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a simple example of how to use the input system in EditorWindow code.
2+
3+
For more details see the [documentation](https://docs.unity3d.com/Packages/com.unity.inputsystem@latest/index.html?subfolder=/manual/UseInEditor.html).

Assets/Samples/EditorWindowDemo/README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ however, it has to be formatted properly to pass verification tests.
99

1010
## [1.0.0-preview.2] - 2999-11-11
1111

12+
### Changed
13+
14+
- Automatic conversion of window coordinates in `EditorWindow` code is now performed regardless of focus or the setting of `Lock Input to Game View` in the input debugger.
15+
1216
### Fixed
1317

1418
- Fixed touch taps triggering when they shouldn't on Android.
@@ -30,6 +34,10 @@ however, it has to be formatted properly to pass verification tests.
3034
- Fixed `ArgumentNullException` when adding a device and a binding in an action map had an empty path (case 1187163).
3135
- Fixed bindings that are not associated with any control scheme not getting enabled with other control schemes as they should.
3236

37+
### Added
38+
39+
- Added a new `EditorWindow Demo` sample that illustrates how to use the input system in editor UI code.
40+
3341
## [1.0.0-preview.1] - 2019-10-11
3442

3543
### Changed

Packages/com.unity.inputsystem/InputSystem/Controls/Processors/EditorWindowSpaceProcessor.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.ComponentModel;
33
using UnityEngine.InputSystem.LowLevel;
44
using UnityEditor;
5-
using UnityEngine.InputSystem.Editor;
65

76
namespace UnityEngine.InputSystem.Processors
87
{
@@ -27,10 +26,12 @@ public override Vector2 Process(Vector2 value, InputControl control)
2726
if (control == null)
2827
throw new System.ArgumentNullException(nameof(control));
2928

30-
// Don't convert to EditorWindowSpace if input is going to game view.
31-
if (InputEditorUserSettings.lockInputToGameView ||
32-
(EditorApplication.isPlaying && Application.isFocused))
33-
return value;
29+
// We go and fire trigger QueryEditorWindowCoordinatesCommand regardless
30+
// of whether we are currently in EditorWindow code or not. The expectation
31+
// here is that the underlying editor code is in a better position than us
32+
// to judge whether the conversion should be performed or not. In native code,
33+
// the IOCTL implementations will early out if they detect that the current
34+
// EditorWindow is in fact a game view.
3435

3536
if (Mouse.s_PlatformMouseDevice != null)
3637
{

Packages/com.unity.inputsystem/InputSystem/Editor/Internal/InputControlTreeView.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
using UnityEditor.IMGUI.Controls;
88
using UnityEngine.Profiling;
99

10+
////TODO: switch to ReadValueFromState (the current value reading code dates back to very early versions of the input system)
11+
//// (note that doing so will have an impact on mouse coordinates which then will go through EditorWindowSpaceProcessor)
12+
1013
////TODO: make control values editable (create state events from UI and pump them into the system)
1114

1215
////TODO: show processors attached to controls
@@ -228,7 +231,6 @@ private bool ReadState(InputControl control, out GUIContent value, out GUIConten
228231
{
229232
if (stateBuffer != null)
230233
{
231-
////TODO: switch to ReadValueFromState
232234
var text = ReadRawValueAsString(control, stateBuffer);
233235
if (text != null)
234236
value = new GUIContent(text);

0 commit comments

Comments
 (0)