Skip to content

Commit 70d769a

Browse files
CHANGE: Make Project-wide Actions the default for Player Input (#1790)
* Add Reset() to default values This event is called once the component is added for the first time https://docs.unity3d.com/2022.3/Documentation/ScriptReference/MonoBehaviour.Reset.html * Check for changes on "Reset" not captured by EndChangeCheck() Without this, changes will not be detected when a user selects "Reset" in the Component Inspector. * Update CHANGELOG * Add project-wide actions define * Only reference InputSystem.Editor on the Editor
1 parent fbee9b1 commit 70d769a

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ however, it has to be formatted properly to pass verification tests.
2020
- Project-wide input actions template extension changed from .inputactions to .json. This avoids showing template actions in the action's selector UI that are not intended to be used.
2121
- Re-enabled some UI tests that were disabled on iOS.
2222
- Reorganized package Project Settings so that "Input System Package" setting node contains "Input Actions" and "Settings" becomes a child node when Project-wide Actions are available. For Unity versions where Project-wide Actions are not available, the settings structure remains unchanged.
23+
- Make Project-wide Actions the default actions for Player Input.
2324

2425
### Added
2526
- Support for [Game rotation vector](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GAME_ROTATION_VECTOR) sensor on Android

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
using UnityEngine.InputSystem.Users;
66
using UnityEngine.InputSystem.Utilities;
77

8+
#if UNITY_EDITOR
9+
using UnityEngine.InputSystem.Editor;
10+
#endif
11+
812
#if PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI
913
using UnityEngine.InputSystem.UI;
1014
#endif
@@ -1607,6 +1611,15 @@ private void AssignPlayerIndex()
16071611
}
16081612
}
16091613

1614+
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
1615+
void Reset()
1616+
{
1617+
// Set default actions to project wide actions.
1618+
m_Actions = ProjectWideActionsAsset.GetOrCreate();
1619+
}
1620+
1621+
#endif
1622+
16101623
private void OnEnable()
16111624
{
16121625
m_Enabled = true;

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputEditor.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override void OnInspectorGUI()
7474
EditorGUI.BeginChangeCheck();
7575
EditorGUILayout.PropertyField(m_ActionsProperty);
7676
var actionsWereChanged = false;
77-
if (EditorGUI.EndChangeCheck() || !m_ActionAssetInitialized)
77+
if (EditorGUI.EndChangeCheck() || !m_ActionAssetInitialized || CheckIfActionAssetChanged())
7878
{
7979
OnActionAssetChange();
8080
actionsWereChanged = true;
@@ -230,6 +230,22 @@ public override void OnInspectorGUI()
230230
DoDebugUI();
231231
}
232232

233+
// This checks changes that are not captured by BeginChangeCheck/EndChangeCheck.
234+
// One such case is when the user triggers a "Reset" on the component.
235+
bool CheckIfActionAssetChanged()
236+
{
237+
if (m_ActionsProperty.objectReferenceValue != null)
238+
{
239+
var assetInstanceID = m_ActionsProperty.objectReferenceValue.GetInstanceID();
240+
bool result = assetInstanceID != m_ActionAssetInstanceID;
241+
m_ActionAssetInstanceID = (int)assetInstanceID;
242+
return result;
243+
}
244+
245+
m_ActionAssetInstanceID = -1;
246+
return false;
247+
}
248+
233249
private void DoHelpCreateAssetUI()
234250
{
235251
if (m_ActionsProperty.objectReferenceValue != null)
@@ -566,6 +582,7 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
566582

567583
[NonSerialized] private bool m_NotificationBehaviorInitialized;
568584
[NonSerialized] private bool m_ActionAssetInitialized;
585+
[NonSerialized] private int m_ActionAssetInstanceID;
569586
}
570587
}
571588
#endif // UNITY_EDITOR

0 commit comments

Comments
 (0)