From c578ca869fa3071272350733db554749a4bc6647 Mon Sep 17 00:00:00 2001 From: Fredrik Ludvigsen Date: Tue, 29 Jun 2021 15:36:33 +0200 Subject: [PATCH] Added ClearPartBindings to BindingSyntax --- .../Actions/InputActionSetupExtensions.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionSetupExtensions.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionSetupExtensions.cs index 7f4110b5d3..8613293959 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionSetupExtensions.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionSetupExtensions.cs @@ -1423,6 +1423,40 @@ private BindingSyntax IteratePartBinding(bool next, string partName) return default; } + /// + /// Remove part bindings from a composite binding. + /// + /// + /// If the binding is not a composite (see ), nothing + /// will be removed, and an invalid BindingSyntax is returned. + /// + /// The instance is not . + public BindingSyntax ClearPartBindings () { + if (!valid) + throw new InvalidOperationException("Instance not valid"); + + ref var bindings = ref m_ActionMap.m_Bindings; + var index = m_BindingIndexInMap; + + if (!bindings[index].isComposite) + return default; + + index++; // Skip to first part binding + + while (index < bindings.Length && bindings[index].isPartOfComposite) + ArrayHelpers.EraseAt(ref bindings, index); + + m_ActionMap.ClearPerActionCachedBindingData(); + m_ActionMap.LazyResolveBindings(); + + // We have switched to a different binding array. For singleton actions, we need to + // sync up the reference that the action itself has. + if (m_ActionMap.m_SingletonAction != null) + m_ActionMap.m_SingletonAction.m_SingletonActionBindings = bindings; + + return this; + } + ////TODO: allow setting overrides through this accessor ///