diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs index 821608969c..5c54b13bcd 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs @@ -83,6 +83,8 @@ public class InputActionAsset : ScriptableObject, IInputActionCollection2 /// InputActionAssets. /// public const string Extension = "inputactions"; + ////REVIEW: actually pre-populate with some stuff? + internal const string kDefaultAssetLayoutJson = "{}"; /// /// True if any action in the asset is currently enabled. @@ -872,6 +874,11 @@ internal void MarkAsDirty() #endif } + internal bool IsEmpty() + { + return actionMaps.Count == 0 && controlSchemes.Count == 0; + } + internal void OnWantToChangeSetup() { if (m_ActionMaps.LengthSafe() > 0) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs index 3edceebd36..5f45b6f02b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs @@ -212,15 +212,12 @@ public override void OnImportAsset(AssetImportContext ctx) InputActionEditorWindow.RefreshAllOnAssetReimport(); } - ////REVIEW: actually pre-populate with some stuff? - private const string kDefaultAssetLayout = "{}"; - // Add item to plop an .inputactions asset into the project. [MenuItem("Assets/Create/Input Actions")] public static void CreateInputAsset() { ProjectWindowUtil.CreateAssetWithContent("New Controls." + InputActionAsset.Extension, - kDefaultAssetLayout, (Texture2D)EditorGUIUtility.Load(kAssetIcon)); + InputActionAsset.kDefaultAssetLayoutJson, (Texture2D)EditorGUIUtility.Load(kAssetIcon)); } } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 98eb2bddc3..7f7409f85c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -223,6 +223,14 @@ private void DirtyInputActionsEditorWindow(InputActionsEditorState newState) private bool HasAssetChanged(SerializedObject serializedAsset) { var asset = (InputActionAsset)serializedAsset.targetObject; + + // Checks if the asset being edited is a new asset that was never saved before. + // If it is, there's nothing to save. + // At the moment, an asset only has the default asset layout content on disk when it is first created. + // So in this case we cannot go through the normal path and compare what's on disk with what has been serialized. + if (m_AssetJson == InputActionAsset.kDefaultAssetLayoutJson && asset.IsEmpty()) + return false; + var newAssetJson = asset.ToJson(); return newAssetJson != m_AssetJson; }