| using UnityEngine.InputSystem.LowLevel; |
| using UnityEngine.InputSystem.Utilities; |
|
|
| |
|
|
| namespace UnityEngine.InputSystem.Controls |
| { |
| |
| |
| |
| public class IntegerControl : InputControl<int> |
| { |
| |
| |
| |
| public IntegerControl() |
| { |
| m_StateBlock.format = InputStateBlock.FormatInt; |
| } |
|
|
| |
| public override unsafe int ReadUnprocessedValueFromState(void* statePtr) |
| { |
| switch (m_OptimizedControlDataType) |
| { |
| case InputStateBlock.kFormatInt: |
| return *(int*)((byte*)statePtr + (int)m_StateBlock.byteOffset); |
| default: |
| return m_StateBlock.ReadInt(statePtr); |
| } |
| } |
|
|
| |
| public override unsafe void WriteValueIntoState(int value, void* statePtr) |
| { |
| switch (m_OptimizedControlDataType) |
| { |
| case InputStateBlock.kFormatInt: |
| *(int*)((byte*)statePtr + (int)m_StateBlock.byteOffset) = value; |
| break; |
| default: |
| m_StateBlock.WriteInt(statePtr, value); |
| break; |
| } |
| } |
|
|
| protected override FourCC CalculateOptimizedControlDataType() |
| { |
| if (m_StateBlock.format == InputStateBlock.FormatInt && |
| m_StateBlock.sizeInBits == 32 && |
| m_StateBlock.bitOffset == 0) |
| return InputStateBlock.FormatInt; |
| return InputStateBlock.FormatInvalid; |
| } |
| } |
| } |
|
|