Skip to content

Commit 410db9d

Browse files
author
jonas echterhoff
authored
CHANGE: no set-only properties (#639)
1 parent 11dc566 commit 410db9d

6 files changed

Lines changed: 79 additions & 37 deletions

File tree

Assets/QA/Input_Test/IMETest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public void Update()
8888
m_AddedTextListeners = true;
8989
}
9090

91-
keyboard.imeEnabled = enableIME;
92-
keyboard.imeCursorPosition = cursorPosition;
91+
keyboard.SetIMEEnabled(enableIME);
92+
keyboard.SetIMECursorPosition(cursorPosition);
9393

9494
activeIME = keyboard.imeSelected.isPressed;
9595

@@ -134,7 +134,8 @@ public void OnSubmitCursorPosition()
134134

135135
if (validInput)
136136
{
137-
keyboard.imeCursorPosition = cursorPosition = new Vector2(x, y);
137+
cursorPosition = new Vector2(x, y);
138+
keyboard.SetIMECursorPosition(cursorPosition);
138139
}
139140
}
140141
}

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,13 +3595,13 @@ public unsafe void Devices_CanEnableAndDisableIME()
35953595
return InputDeviceCommand.GenericFailure;
35963596
});
35973597

3598-
keyboard.imeEnabled = true;
3598+
keyboard.SetIMEEnabled(true);
35993599

36003600
Assert.That(receivedIMEEnabledValue, Is.True);
36013601

36023602
receivedIMEEnabledValue = null;
36033603

3604-
keyboard.imeEnabled = false;
3604+
keyboard.SetIMEEnabled(false);
36053605

36063606
Assert.That(receivedIMEEnabledValue, Is.False);
36073607
}
@@ -3631,7 +3631,7 @@ public unsafe void Devices_CanSetIMECursorPositionOnKeyboard()
36313631
});
36323632

36333633
////REVIEW: should this require IME to be enabled?
3634-
keyboard.imeCursorPosition = Vector2.one;
3634+
keyboard.SetIMECursorPosition(Vector2.one);
36353635
Assert.That(commandWasSent, Is.True);
36363636
}
36373637
}

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ however, it has to be formatted properly to pass verification tests.
2222
### Changed
2323

2424
- Added icons for PlayerInput, PlayerInputManager, InputSystemUIInputModule and MultiplayerEventSystem components.
25+
- Changed `Keyboard` IME properties (`imeEnabled`, `imeCursorPosition`) to methods (`SetIMEEnabled`, `SetIMECursorPosition`).
26+
- Added getters to all `IInputRuntime` properties.
2527
- Replace some `GetXxx` methods in our API with `xxx` properties.
2628

2729
## [0.2.10-preview] - 2019-5-17

Packages/com.unity.inputsystem/InputSystem/Devices/Keyboard.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public event Action<char> onTextInput
345345
/// Some languages use complex input methods which involve opening windows to insert characters.
346346
/// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
347347
///
348-
/// See <see cref="Keyboard.imeEnabled"/> for turning IME on/off
348+
/// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
349349
/// </remarks>
350350
public event Action<IMECompositionString> onIMECompositionChange
351351
{
@@ -362,34 +362,27 @@ public event Action<IMECompositionString> onIMECompositionChange
362362
/// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
363363
/// Setting this to On, will enable the OS-level IME system when the user presses keystrokes.
364364
///
365-
/// See <see cref="Keyboard.imeCursorPosition"/>, <see cref="Keyboard.onIMECompositionChange"/>, <see cref="Keyboard.imeSelected"/> for more IME settings and data.
365+
/// See <see cref="Keyboard.SetIMECursorPosition"/>, <see cref="Keyboard.onIMECompositionChange"/>, <see cref="Keyboard.imeSelected"/> for more IME settings and data.
366366
/// </remarks>
367-
public bool imeEnabled
367+
public void SetIMEEnabled(bool enabled)
368368
{
369-
set
370-
{
371-
EnableIMECompositionCommand command = EnableIMECompositionCommand.Create(value);
372-
ExecuteCommand(ref command);
373-
}
369+
EnableIMECompositionCommand command = EnableIMECompositionCommand.Create(enabled);
370+
ExecuteCommand(ref command);
374371
}
375372

376-
377373
/// Sets the cursor position for IME composition dialogs. Units are from the upper left, in pixels, moving down and to the right.
378374
/// </summary>
379375
/// <remarks>
380376
///
381377
/// Some languages use complex input methods which involve opening windows to insert characters.
382378
/// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
383379
///
384-
/// See <see cref="Keyboard.imeEnabled"/> for turning IME on/off
380+
/// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
385381
/// </remarks>
386-
public Vector2 imeCursorPosition
382+
public void SetIMECursorPosition(Vector2 position)
387383
{
388-
set
389-
{
390-
SetIMECursorPositionCommand command = SetIMECursorPositionCommand.Create(value);
391-
ExecuteCommand(ref command);
392-
}
384+
SetIMECursorPositionCommand command = SetIMECursorPositionCommand.Create(position);
385+
ExecuteCommand(ref command);
393386
}
394387

395388
/// <summary>
@@ -576,14 +569,14 @@ public string keyboardLayout
576569
public KeyControl oem5Key => this[Key.OEM5];
577570

578571
/// <summary>
579-
/// True when IME composition is enabled. Requires <see cref="Keyboard.imeEnabled"/> to be set to true, and the user to enable it at the OS level.
572+
/// True when IME composition is enabled. Requires <see cref="Keyboard.SetIMEEnabled"/> to be called to enable IME, and the user to enable it at the OS level.
580573
/// </summary>
581574
/// <remarks>
582575
///
583576
/// Some languages use complex input methods which involve opening windows to insert characters.
584577
/// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
585578
///
586-
/// See <see cref="Keyboard.imeEnabled"/> for turning IME on/off
579+
/// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
587580
/// </remarks>
588581
public ButtonControl imeSelected { get; private set; }
589582

Packages/com.unity.inputsystem/InputSystem/IInputRuntime.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public unsafe interface IInputRuntime
7676
/// <summary>
7777
/// Set delegate to be called on input updates.
7878
/// </summary>
79-
InputUpdateDelegate onUpdate { set; }
79+
InputUpdateDelegate onUpdate { get; set; }
8080

8181
/// <summary>
8282
/// Set delegate to be called right before <see cref="onUpdate"/>.
@@ -85,9 +85,9 @@ public unsafe interface IInputRuntime
8585
/// This delegate is meant to allow events to be queued that should be processed right
8686
/// in the upcoming update.
8787
/// </remarks>
88-
Action<InputUpdateType> onBeforeUpdate { set; }
88+
Action<InputUpdateType> onBeforeUpdate { get; set; }
8989

90-
Func<InputUpdateType, bool> onShouldRunUpdate { set; }
90+
Func<InputUpdateType, bool> onShouldRunUpdate { get; set; }
9191

9292
/// <summary>
9393
/// Set delegate to be called when a new device is discovered.
@@ -99,18 +99,18 @@ public unsafe interface IInputRuntime
9999
/// First parameter is the ID assigned to the device, second parameter is a description
100100
/// in JSON format of the device (see <see cref="InputDeviceDescription.FromJson"/>).
101101
/// </remarks>
102-
Action<int, string> onDeviceDiscovered { set; }
102+
Action<int, string> onDeviceDiscovered { get; set; }
103103

104104
/// <summary>
105105
/// Set delegate to call when the application changes focus.
106106
/// </summary>
107107
/// <seealso cref="Application.onFocusChanged"/>
108-
Action<bool> onFocusChanged { set; }
108+
Action<bool> onFocusChanged { get; set; }
109109

110110
/// <summary>
111111
/// Set delegate to invoke when system is shutting down.
112112
/// </summary>
113-
Action onShutdown { set; }
113+
Action onShutdown { get; set; }
114114

115115
/// <summary>
116116
/// Set the background polling frequency for devices that have to be polled.
@@ -119,7 +119,7 @@ public unsafe interface IInputRuntime
119119
/// The frequency is in Hz. A value of 60 means that polled devices get sampled
120120
/// 60 times a second.
121121
/// </remarks>
122-
float pollingFrequency { set; }
122+
float pollingFrequency { get; set; }
123123

124124
/// <summary>
125125
/// The current time on the same timeline that input events are delivered on.
@@ -166,8 +166,8 @@ public unsafe interface IInputRuntime
166166
bool isInBatchMode { get; }
167167

168168
#if UNITY_EDITOR
169-
Action<PlayModeStateChange> onPlayModeChanged { set; }
170-
Action onProjectChange { set; }
169+
Action<PlayModeStateChange> onPlayModeChanged { get; set; }
170+
Action onProjectChange { get; set; }
171171
bool isInPlayMode { get; }
172172
bool isPaused { get; }
173173
#endif

Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public unsafe long DeviceCommand(int deviceId, InputDeviceCommand* commandPtr)
4747

4848
public unsafe InputUpdateDelegate onUpdate
4949
{
50+
get => m_OnUpdate;
5051
set
5152
{
5253
if (value != null)
@@ -87,11 +88,13 @@ public unsafe InputUpdateDelegate onUpdate
8788
};
8889
else
8990
NativeInputSystem.onUpdate = null;
91+
m_OnUpdate = value;
9092
}
9193
}
9294

9395
public Action<InputUpdateType> onBeforeUpdate
9496
{
97+
get => m_OnBeforeUpdate;
9598
set
9699
{
97100
// This is stupid but the enum prevents us from jacking the delegate in directly.
@@ -100,11 +103,13 @@ public Action<InputUpdateType> onBeforeUpdate
100103
NativeInputSystem.onBeforeUpdate = updateType => value((InputUpdateType)updateType);
101104
else
102105
NativeInputSystem.onBeforeUpdate = null;
106+
m_OnBeforeUpdate = value;
103107
}
104108
}
105109

106110
public Func<InputUpdateType, bool> onShouldRunUpdate
107111
{
112+
get => m_OnShouldRunUpdate;
108113
set
109114
{
110115
// This is stupid but the enum prevents us from jacking the delegate in directly.
@@ -113,16 +118,19 @@ public Func<InputUpdateType, bool> onShouldRunUpdate
113118
NativeInputSystem.onShouldRunUpdate = updateType => value((InputUpdateType)updateType);
114119
else
115120
NativeInputSystem.onShouldRunUpdate = null;
121+
m_OnShouldRunUpdate = value;
116122
}
117123
}
118124

119125
public Action<int, string> onDeviceDiscovered
120126
{
127+
get => NativeInputSystem.onDeviceDiscovered;
121128
set => NativeInputSystem.onDeviceDiscovered = value;
122129
}
123130

124131
public Action onShutdown
125132
{
133+
get => m_ShutdownMethod;
126134
set
127135
{
128136
if (value == null)
@@ -148,6 +156,7 @@ public Action onShutdown
148156

149157
public Action<bool> onFocusChanged
150158
{
159+
get => m_FocusChangedMethod;
151160
set
152161
{
153162
if (value == null)
@@ -162,7 +171,12 @@ public Action<bool> onFocusChanged
162171

163172
public float pollingFrequency
164173
{
165-
set => NativeInputSystem.SetPollingFrequency(value);
174+
get => m_PollingFrequency;
175+
set
176+
{
177+
m_PollingFrequency = value;
178+
NativeInputSystem.SetPollingFrequency(value);
179+
}
166180
}
167181

168182
public double currentTime => NativeInputSystem.currentTime;
@@ -172,7 +186,10 @@ public float pollingFrequency
172186
public double currentTimeOffsetToRealtimeSinceStartup => NativeInputSystem.currentTimeOffsetToRealtimeSinceStartup;
173187

174188
private Action m_ShutdownMethod;
175-
189+
private InputUpdateDelegate m_OnUpdate;
190+
private Action<InputUpdateType> m_OnBeforeUpdate;
191+
private Func<InputUpdateType, bool> m_OnShouldRunUpdate;
192+
private float m_PollingFrequency = 60.0f;
176193
private void OnShutdown()
177194
{
178195
m_ShutdownMethod();
@@ -198,14 +215,43 @@ private void OnFocusChanged(bool focus)
198215
public bool isInPlayMode => EditorApplication.isPlaying;
199216
public bool isPaused => EditorApplication.isPaused;
200217

218+
private Action<PlayModeStateChange> m_OnPlayModeChanged;
219+
private Action m_OnProjectChanged;
220+
221+
private void OnPlayModeStateChanged(PlayModeStateChange value)
222+
{
223+
m_OnPlayModeChanged(value);
224+
}
225+
226+
private void OnProjectChanged()
227+
{
228+
m_OnProjectChanged();
229+
}
230+
201231
public Action<PlayModeStateChange> onPlayModeChanged
202232
{
203-
set => EditorApplication.playModeStateChanged += value;
233+
get => m_OnPlayModeChanged;
234+
set
235+
{
236+
if (value == null)
237+
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
238+
else if (m_OnPlayModeChanged == null)
239+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
240+
m_OnPlayModeChanged = value;
241+
}
204242
}
205243

206244
public Action onProjectChange
207245
{
208-
set => EditorApplication.projectChanged += value;
246+
get => m_OnProjectChanged;
247+
set
248+
{
249+
if (value == null)
250+
EditorApplication.projectChanged -= OnProjectChanged;
251+
else if (m_OnProjectChanged == null)
252+
EditorApplication.projectChanged += OnProjectChanged;
253+
m_OnProjectChanged = value;
254+
}
209255
}
210256

211257
#endif // UNITY_EDITOR

0 commit comments

Comments
 (0)