public TValue ReadValue <TValue>()
            {
                ////TODO: instead of straight casting, perform 'as' casts and throw better exceptions than just InvalidCastException
                ////TODO: this needs to be shared with InputActionManager

                var value = default(TValue);

                if (m_State == null)
                {
                    return(value);
                }

                // In the case of a composite, this will be null.
                InputControl <TValue> controlOfType = null;

                // If the binding that triggered the action is part of a composite, let
                // the composite determine the value we return.
                var compositeObject = composite;

                if (compositeObject != null)
                {
                    var compositeOfType = (IInputBindingComposite <TValue>)compositeObject;
                    var context         = new InputBindingCompositeContext();
                    value = compositeOfType.ReadValue(ref context);
                }
                else
                {
                    controlOfType = (InputControl <TValue>)control;
                    value         = controlOfType.ReadValue();
                }

                // Run value through processors, if any.
                var bindingStates  = m_State.bindingStates;
                var processorCount = bindingStates[m_BindingIndex].processorCount;

                if (processorCount > 0)
                {
                    var processorStartIndex = bindingStates[m_BindingIndex].processorStartIndex;
                    var processors          = m_State.processors;
                    for (var i = 0; i < processorCount; ++i)
                    {
                        value = ((IInputControlProcessor <TValue>)processors[processorStartIndex + i]).Process(value, controlOfType);
                    }
                }

                return(value);
            }
        public unsafe void ReadValue(ref InputBindingCompositeContext context, void *buffer, int bufferSize)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            var valueSize = valueSizeInBytes;

            if (bufferSize < valueSize)
            {
                throw new ArgumentException("bufferSize < valueSizeInBytes", "bufferSize");
            }

            var value    = ReadValue(ref context);
            var valuePtr = UnsafeUtility.AddressOf(ref value);

            UnsafeUtility.MemCpy(buffer, valuePtr, valueSize);
        }
Example #3
0
 public abstract float EvaluateMagnitude(ref InputBindingCompositeContext context);
Example #4
0
 public abstract object ReadValueAsObject(ref InputBindingCompositeContext context);
Example #5
0
 public abstract unsafe void ReadValue(ref InputBindingCompositeContext context, void *buffer, int bufferSize);
 public abstract TValue ReadValue(ref InputBindingCompositeContext context);