/// <summary> /// /// </summary> /// <param name="state"></param> /// <param name="value">Value for <paramref name="control"/> to write into <paramref name="state"/>.</param> /// <typeparam name="TState"></typeparam> /// <exception cref="ArgumentNullException"><paramref name="control"/> is null.</exception> /// <exception cref="ArgumentException">Control's value does not fit within the memory of <paramref name="state"/>.</exception> /// <exception cref="NotSupportedException"><paramref name="control"/> does not support writing.</exception> public static unsafe void WriteValueIntoState <TValue, TState>(this InputControl <TValue> control, TValue value, ref TState state) where TValue : struct where TState : struct, IInputStateTypeInfo { if (control == null) { throw new ArgumentNullException("control"); } // Make sure the control's state actually fits within the given state. var sizeOfState = UnsafeUtility.SizeOf <TState>(); if (control.stateOffsetRelativeToDeviceRoot + control.m_StateBlock.alignedSizeInBytes >= sizeOfState) { throw new ArgumentException( string.Format( "Control {0} with offset {1} and size of {2} bits is out of bounds for state of type {3} with size {4}", control.path, control.stateOffsetRelativeToDeviceRoot, control.m_StateBlock.sizeInBits, typeof(TState).Name, sizeOfState), "state"); } // Write value. var statePtr = (byte *)UnsafeUtility.AddressOf(ref state); control.WriteValueIntoState(value, statePtr); }
protected unsafe void AccumulateDelta(void *oldStatePtr, void *newStatePtr, InputControl <float> control) { ////FIXME: if there's processors on the delta, this is junk var oldDelta = control.ReadValueFromState(oldStatePtr); var newDelta = control.ReadValueFromState(newStatePtr); control.WriteValueIntoState(oldDelta + newDelta, newStatePtr); }
public static unsafe void WriteValueIntoState <TValue>(this InputControl <TValue> control, void *statePtr) where TValue : struct { if (control == null) { throw new ArgumentNullException(nameof(control)); } control.WriteValueIntoState(control.ReadValue(), statePtr); }
protected unsafe bool ResetDelta(void *statePtr, InputControl <float> control) { ////FIXME: this should compare to default *state* (not value) and write default *state* (not value) var value = control.ReadValueFromState(statePtr); if (Mathf.Approximately(0f, value)) { return(false); } control.WriteValueIntoState(0f, statePtr); return(true); }
public static unsafe void WriteValueIntoEvent <TValue>(this InputControl <TValue> control, TValue value, InputEventPtr eventPtr) where TValue : struct { if (control == null) { throw new ArgumentNullException(nameof(control)); } if (!eventPtr.valid) { throw new ArgumentNullException(nameof(eventPtr)); } var statePtr = control.GetStatePtrFromStateEvent(eventPtr); if (statePtr == null) { return; } control.WriteValueIntoState(value, statePtr); }