/// <summary>
        /// Record the triggering of an action as an <see cref="ActionEventPtr">action event</see>.
        /// </summary>
        /// <param name="context"></param>
        /// <see cref="InputAction.performed"/>
        /// <see cref="InputAction.started"/>
        /// <see cref="InputAction.cancelled"/>
        /// <see cref="InputActionMap.actionTriggered"/>
        public unsafe void RecordAction(InputAction.CallbackContext context)
        {
            // Find/add state.
            var stateIndex = m_ActionMapStates.IndexOf(context.m_State);

            if (stateIndex == -1)
            {
                stateIndex = m_ActionMapStates.AppendWithCapacity(context.m_State);
            }

            // Allocate event.
            var valueSizeInBytes = context.valueSizeInBytes;
            var eventPtr         =
                (ActionEvent *)m_EventBuffer.AllocateEvent(ActionEvent.GetEventSizeWithValueSize(valueSizeInBytes));

            // Initialize event.
            eventPtr->baseEvent.type   = ActionEvent.Type;
            eventPtr->baseEvent.time   = context.time;
            eventPtr->stateIndex       = stateIndex;
            eventPtr->controlIndex     = context.m_ControlIndex;
            eventPtr->bindingIndex     = context.m_BindingIndex;
            eventPtr->interactionIndex = context.m_InteractionIndex;
            eventPtr->startTime        = context.startTime;
            eventPtr->phase            = context.phase;

            // Store value.
            var valueBuffer = eventPtr->valueData;

            context.ReadValue(valueBuffer, valueSizeInBytes);
        }
Beispiel #2
0
        /// <summary>
        /// Record the triggering of an action as an <see cref="ActionEventPtr">action event</see>.
        /// </summary>
        /// <param name="context"></param>
        /// <see cref="InputAction.performed"/>
        /// <see cref="InputAction.started"/>
        /// <see cref="InputAction.cancelled"/>
        /// <see cref="InputActionMap.actionTriggered"/>
        public unsafe void RecordAction(InputAction.CallbackContext context)
        {
            // Find/add state.
            var stateIndex = m_ActionMapStates.IndexOfReference(context.m_State);

            if (stateIndex == -1)
            {
                stateIndex = m_ActionMapStates.AppendWithCapacity(context.m_State);
            }

            // Make sure we get notified if there's a change to binding setups.
            HookOnActionChange();

            // Allocate event.
            var valueSizeInBytes = context.valueSizeInBytes;
            var eventPtr         =
                (ActionEvent *)m_EventBuffer.AllocateEvent(ActionEvent.GetEventSizeWithValueSize(valueSizeInBytes));

            // Initialize event.
            ref var triggerState = ref context.m_State.actionStates[context.m_ActionIndex];