Пример #1
0
        protected void AccumulateDelta(IntPtr oldStatePtr, IntPtr newStatePtr, InputControl <float> control)
        {
            var oldDelta = control.ReadValueFrom(oldStatePtr);
            var newDelta = control.ReadValueFrom(newStatePtr);

            control.WriteValueInto(newStatePtr, oldDelta + newDelta);
        }
Пример #2
0
        protected bool ResetDelta(IntPtr statePtr, InputControl <float> control)
        {
            var value = control.ReadValueFrom(statePtr);

            if (Mathf.Approximately(0f, value))
            {
                return(false);
            }
            control.WriteValueInto(statePtr, 0f);
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Set the control to the given value by sending a state event with the value to the
        /// control's device.
        /// </summary>
        /// <param name="control">An input control on a device that has been added to the system.</param>
        /// <param name="state">New value for the input control.</param>
        /// <typeparam name="TValue">Value type of the given control.</typeparam>
        /// <example>
        /// <code>
        /// var gamepad = InputSystem.AddDevice&lt;Gamepad&gt;();
        /// Set(gamepad.leftButton, 1);
        /// </code>
        /// </example>
        public void Set <TValue>(InputControl <TValue> control, TValue state)
            where TValue : struct
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            if (!control.device.added)
            {
                throw new ArgumentException(
                          string.Format("Device of control '{0}' has not been added to the system", control), "control");
            }

            InputEventPtr eventPtr;

            using (StateEvent.From(control.device, out eventPtr))
            {
                control.WriteValueInto(eventPtr, state);
                InputSystem.QueueEvent(eventPtr);
            }

            InputSystem.Update();
        }