Skip to content

Commit 9e5c31c

Browse files
committed
Code cleanup and simplification after reviewing all code on the branch
1 parent 5d40eb4 commit 9e5c31c

File tree

8 files changed

+34
-23
lines changed

8 files changed

+34
-23
lines changed

Assets/Samples/RebindingUI/CanvasGroupModifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CanvasGroupModifier : MonoBehaviour
1616
private bool m_SavedInteractable;
1717
private GameObject m_SelectedObject;
1818

19-
void OnEnable()
19+
private void OnEnable()
2020
{
2121
if (canvasGroup != null)
2222
{
@@ -29,7 +29,7 @@ void OnEnable()
2929
}
3030
}
3131

32-
void OnDisable()
32+
private void OnDisable()
3333
{
3434
if (canvasGroup != null)
3535
{

Assets/Samples/RebindingUI/Game/Enemy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void OnCollisionEnter(Collision other)
4040
}
4141

4242
// Update is called once per frame
43-
void Update()
43+
private void Update()
4444
{
4545
// Animate rotation
4646
if (animationTarget)

Assets/Samples/RebindingUI/Game/Explosion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Explosion : MonoBehaviour
88
private bool m_Exploded;
99
private bool m_Destroyed;
1010

11-
void Awake()
11+
private void Awake()
1212
{
1313
m_ParticleSystem = GetComponent<ParticleSystem>();
1414
m_Rigidbodies = gameObject.GetComponentsInChildren<Rigidbody>();
@@ -25,7 +25,7 @@ private void OnDisable()
2525
m_ParticleSystem.Stop();
2626
}
2727

28-
void Update()
28+
private void Update()
2929
{
3030
if (!m_ParticleSystem.isPlaying && !m_Destroyed)
3131
{

Assets/Samples/RebindingUI/Game/Message.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,44 @@
44

55
namespace UnityEngine.InputSystem.Samples.RebindUI
66
{
7+
/// <summary>
8+
/// A UI to show messages reflecting changes to gameplay state.
9+
/// </summary>
710
public class Message : MonoBehaviour
811
{
12+
[Tooltip("The associated gameplay manager.")]
913
public GameplayManager gameplayManager;
14+
15+
[Tooltip("The associated UI root to hide/show.")]
1016
public GameObject root;
17+
18+
[Tooltip("The associated UI text to be altered to show messages.")]
1119
public Text text;
20+
1221
private Action m_TimeoutCallback;
1322

1423
private void OnEnable()
1524
{
25+
// Monitor changes to gameplay state and game pause state.
1626
gameplayManager.GameplayStateChanged += OnGameplayStateChanged;
1727
gameplayManager.PauseChanged += OnPauseChanged;
18-
OnGameplayStateChanged(gameplayManager.state);
19-
}
2028

21-
private void OnPauseChanged(bool paused)
22-
{
29+
// Initialize
2330
OnGameplayStateChanged(gameplayManager.state);
2431
}
2532

2633
private void OnDisable()
2734
{
35+
// Unsubscribe from monitoring gameplay and pause state.
2836
gameplayManager.GameplayStateChanged += OnGameplayStateChanged;
2937
gameplayManager.PauseChanged -= OnPauseChanged;
3038
}
3139

40+
private void OnPauseChanged(bool paused)
41+
{
42+
OnGameplayStateChanged(gameplayManager.state);
43+
}
44+
3245
private void Hide()
3346
{
3447
root.SetActive(false);

Assets/Samples/RebindingUI/Game/PlayerController.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ namespace UnityEngine.InputSystem.Samples.RebindUI
1313
[DefaultExecutionOrder(-1)] // We need this to run before Player to avoid potential additional latency
1414
public class PlayerController : MonoBehaviour
1515
{
16-
[Header("Input Action Bindings")]
1716
[Tooltip("The move action, must generate Vector2")]
1817
public InputActionReference move;
18+
1919
[Tooltip("The move action, must generate Vector2")]
2020
public InputActionReference look;
21+
2122
[Tooltip("The move action, must generate Button value")]
2223
public InputActionReference fire;
24+
2325
[Tooltip("The move action, must generate Button value")]
2426
public InputActionReference change;
2527

@@ -33,7 +35,7 @@ public class PlayerController : MonoBehaviour
3335
// Required player reference
3436
private Player m_Player;
3537

36-
private const float kMouseSensitivity = 0.5f;
38+
private const float kMouseSensitivity = 0.4f;
3739
private const float kGamepadSensitivity = 1.0f;
3840

3941
private void Awake()
@@ -98,7 +100,7 @@ private void Update()
98100
if (lookValue.sqrMagnitude > 0.05f)
99101
feedbackController?.RecordRecentDeviceFromAction(look);
100102

101-
var timeInvariant = (look.action.activeControl is DeltaControl);
103+
var timeInvariant = look.action.activeControl is DeltaControl;
102104
var scale = timeInvariant ?
103105
1.0f * kMouseSensitivity :
104106
Time.deltaTime * 300.0f * kGamepadSensitivity;

Assets/Samples/RebindingUI/InvokeUnityEvent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public InputActionReference action
3838
}
3939
}
4040

41+
/// <summary>
42+
/// Access or set the Unity event to be triggered when the action is performed.
43+
/// </summary>
4144
public UnityEvent onPerformed
4245
{
4346
get => m_OnPerformed;

Assets/Samples/RebindingUI/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
This sample demonstrates how to use the Input System APIs to set up a rebinding UI. The main file is [RebindActionUI](./RebindActionUI.cs) which, aside from serving as an example, contains a reusable `MonoBehaviour` component for composing rebinding UIs. The [RebindUIPrefab](./RebindUIPrefab.prefab) contains a ready-made prefab that can be used as a simple drop-in setup for rebinding an individual action.
22

3-
To demonstrate how to use images instead of textual display strings, take a look at [GamepadIconsExample](./GamepadIconsExample.cs).
3+
To demonstrate how to use images instead of textual display strings, take a look at [GamepadIconsExample](./GamepadIconsExample.cs).
4+
5+
To demonstrate how to show dynamic texts based on input action bindings, see [ActionLabel](./ActionLabel.cs).
46

57
Finally, the [RebindSaveLoad](./RebindSaveLoad.cs) script demonstrates how to persist user rebinds in `PlayerPrefs` and how to restore them from there.
68

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,6 @@ void IInputStateChangeMonitor.NotifyControlStateChanged(InputControl control, do
13541354
#endif
13551355

13561356
SplitUpMapAndControlAndBindingIndex(mapControlAndBindingIndex, out var mapIndex, out var controlIndex, out var bindingIndex);
1357-
// CALLBACK HERE
13581357
ProcessControlStateChange(mapIndex, controlIndex, bindingIndex, time, eventPtr);
13591358
}
13601359

@@ -1952,7 +1951,6 @@ private void ProcessDefaultInteraction(ref TriggerState trigger, int actionIndex
19521951
var threshold = controls[trigger.controlIndex] is ButtonControl button ? button.pressPointOrDefault : ButtonControl.s_GlobalDefaultButtonPressPoint;
19531952
if (actuation >= threshold)
19541953
{
1955-
// TODO CALLBACK HERE!
19561954
ChangePhaseOfAction(InputActionPhase.Performed, ref trigger,
19571955
phaseAfterPerformedOrCanceled: InputActionPhase.Performed);
19581956
}
@@ -2513,7 +2511,7 @@ private void ChangePhaseOfActionInternal(int actionIndex, TriggerState* actionSt
25132511
var action = map.m_Actions[actionIndex - mapIndices[trigger.mapIndex].actionStartIndex];
25142512
trigger.phase = newPhase;
25152513

2516-
// Early out if suppressed
2514+
// Early out from CallActionListeners if suppressed
25172515
if (m_Suppressed)
25182516
return;
25192517

@@ -2558,13 +2556,6 @@ private void CallActionListeners(int actionIndex, InputActionMap actionMap, Inpu
25582556

25592557
k_InputActionCallbackMarker.Begin();
25602558

2561-
// Early return in case of suppressed action notifications.
2562-
if (m_Suppressed)
2563-
{
2564-
k_InputActionCallbackMarker.End();
2565-
return;
2566-
}
2567-
25682559
// Global callback goes first.
25692560
var action = context.action;
25702561
if (s_GlobalState.onActionChange.length > 0)

0 commit comments

Comments
 (0)