/// <summary> /// Pop a specific action located anywhere in the stack off the stack. /// </summary> /// <param name="action"></param> /// <remarks> /// Does nothing if the action is not on the stack. /// </remarks> public void Pop(InputAction action) { if (action == null) { throw new ArgumentNullException("action"); } if (m_ActionCount == 0) { return; } // Find the action on the stack. var index = ArrayHelpers.IndexOfReference(m_Actions, m_ActionCount, action); if (index == -1) { return; } // If we don't own the action array, duplicate. if ((m_Flags & Flags.UsingActionArrayOfMap) != 0) { ArrayHelpers.DuplicateWithCapacity(ref m_Actions, m_ActionCount, 10); } // Remove the action. ArrayHelpers.EraseAtWithCapacity(ref m_Actions, ref m_ActionCount, index); // Finally, disable action if necessary. if (enabled) { action.Disable(); } }
private void EnsureCapacity(int capacity) { Debug.Assert(capacity >= 1); // Make sure we have the necessary space in m_Actions. In case we're currently using m_Actions // from another InputActionMap, this will automatically switch to a new array as the array // from the map won't have any space left. // // That is, except if we popped actions off the back. In that case we need to duplicate now // or we'd write into the array of the action map and stomp over its actions. if ((m_Flags & Flags.UsingActionArrayOfMap) != 0 && m_Actions != null && m_Actions.Length > m_ActionCount) { ArrayHelpers.DuplicateWithCapacity(ref m_Actions, m_ActionCount, capacity); } else { ArrayHelpers.EnsureCapacity(ref m_Actions, m_ActionCount, capacity); } // We always end up with an array of our own. m_Flags &= ~Flags.UsingActionArrayOfMap; }