From 276b253dc8e4e8458b807fbbdbf6305d2aca775a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freire?= Date: Fri, 29 Sep 2023 17:10:45 +0200 Subject: [PATCH 1/5] Avoid new created assets to be dirty when opened --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index a57a4d0fc3..c0cd220496 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -210,6 +210,11 @@ private void DirtyInputActionsEditorWindow(InputActionsEditorState newState) private bool HasAssetChanged(SerializedObject serializedAsset) { var asset = (InputActionAsset)serializedAsset.targetObject; + + // Checks if the new asset is empty. If it is, there's nothing to save. + if (asset.actionMaps.Count == 0 && asset.controlSchemes.Count == 0) + return false; + var newAssetJson = asset.ToJson(); return newAssetJson != m_AssetJson; } From b0bcfbfbd0aa0561069447e1ec76d2ba7ec042fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freire?= Date: Wed, 4 Oct 2023 13:59:51 +0200 Subject: [PATCH 2/5] Add methods to check asset for default json layout and being empty --- .../InputSystem/Actions/InputActionAsset.cs | 12 ++++++++++++ .../Editor/AssetImporter/InputActionImporter.cs | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs index 821608969c..8fec37f306 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 kDefaultAssetLayout = "{}"; /// /// True if any action in the asset is currently enabled. @@ -872,6 +874,16 @@ internal void MarkAsDirty() #endif } + internal bool IsEmpty() + { + return actionMaps.Count == 0 && controlSchemes.Count == 0; + } + + internal static bool HasDefaultJsonLayout(string assetJson) + { + return assetJson == kDefaultAssetLayout; + } + 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..57cf49552c 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.kDefaultAssetLayout, (Texture2D)EditorGUIUtility.Load(kAssetIcon)); } } } From 0134b98742eeeb17aa56e50e7cc36b1495fcc3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freire?= Date: Wed, 4 Oct 2023 14:11:32 +0200 Subject: [PATCH 3/5] Improve dirty asset detection when new asset is first created Ideally at this stage, the file on disk should have a serializable equivalent as the serialized asset. However, because the new asset on disk is being created with a specific default json layout, the serialized JSON asset doesn't have not the same content. There are opportunities for change in this area. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index c0cd220496..8e46e7b7ab 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -211,8 +211,11 @@ private bool HasAssetChanged(SerializedObject serializedAsset) { var asset = (InputActionAsset)serializedAsset.targetObject; - // Checks if the new asset is empty. If it is, there's nothing to save. - if (asset.actionMaps.Count == 0 && asset.controlSchemes.Count == 0) + // 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 (InputActionAsset.HasDefaultJsonLayout(m_AssetJson) && asset.IsEmpty()) return false; var newAssetJson = asset.ToJson(); From 0683ea9e4d6ee1da79f1fc709273e4d4670c16a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freire?= Date: Wed, 4 Oct 2023 14:45:32 +0200 Subject: [PATCH 4/5] Remove default json layout check method --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 8e46e7b7ab..74e2e3e85d 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -215,7 +215,7 @@ private bool HasAssetChanged(SerializedObject serializedAsset) // 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 (InputActionAsset.HasDefaultJsonLayout(m_AssetJson) && asset.IsEmpty()) + if (m_AssetJson == InputActionAsset.kDefaultAssetLayoutJson && asset.IsEmpty()) return false; var newAssetJson = asset.ToJson(); From a1ac19fc1625719b0134bea53fb92cfd04eb087a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freire?= Date: Wed, 4 Oct 2023 14:50:36 +0200 Subject: [PATCH 5/5] Update renamed constant --- .../InputSystem/Actions/InputActionAsset.cs | 7 +------ .../Editor/AssetImporter/InputActionImporter.cs | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs index 8fec37f306..5c54b13bcd 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs @@ -84,7 +84,7 @@ public class InputActionAsset : ScriptableObject, IInputActionCollection2 /// public const string Extension = "inputactions"; ////REVIEW: actually pre-populate with some stuff? - internal const string kDefaultAssetLayout = "{}"; + internal const string kDefaultAssetLayoutJson = "{}"; /// /// True if any action in the asset is currently enabled. @@ -879,11 +879,6 @@ internal bool IsEmpty() return actionMaps.Count == 0 && controlSchemes.Count == 0; } - internal static bool HasDefaultJsonLayout(string assetJson) - { - return assetJson == kDefaultAssetLayout; - } - 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 57cf49552c..5f45b6f02b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs @@ -217,7 +217,7 @@ public override void OnImportAsset(AssetImportContext ctx) public static void CreateInputAsset() { ProjectWindowUtil.CreateAssetWithContent("New Controls." + InputActionAsset.Extension, - InputActionAsset.kDefaultAssetLayout, (Texture2D)EditorGUIUtility.Load(kAssetIcon)); + InputActionAsset.kDefaultAssetLayoutJson, (Texture2D)EditorGUIUtility.Load(kAssetIcon)); } } }