示例#1
0
        // Migrate state data for all devices from a previous set of buffers to the current set of buffers.
        // Copies all state from their old locations to their new locations and bakes the new offsets into
        // the control hierarchies of the given devices.
        // NOTE: oldDeviceIndices is only required if devices have been removed; otherwise it can be null.
        public void MigrateAll(InputDevice[] devices, uint[] newStateBlockOffsets, InputStateBuffers oldBuffers, int[] oldDeviceIndices)
        {
            // If we have old data, perform migration.
            // Note that the enabled update types don't need to match between the old set of buffers
            // and the new set of buffers.
            if (oldBuffers.totalSize > 0)
            {
                MigrateDoubleBuffer(m_DynamicUpdateBuffers, devices, newStateBlockOffsets, oldBuffers.m_DynamicUpdateBuffers,
                                    oldDeviceIndices);
                MigrateDoubleBuffer(m_FixedUpdateBuffers, devices, newStateBlockOffsets, oldBuffers.m_FixedUpdateBuffers,
                                    oldDeviceIndices);

#if UNITY_EDITOR
                MigrateDoubleBuffer(m_EditorUpdateBuffers, devices, newStateBlockOffsets, oldBuffers.m_EditorUpdateBuffers,
                                    oldDeviceIndices);
#endif

                MigrateSingleBuffer(defaultStateBuffer, devices, newStateBlockOffsets, oldBuffers.defaultStateBuffer);
                MigrateSingleBuffer(noiseBitmaskBuffer, devices, newStateBlockOffsets, oldBuffers.noiseBitmaskBuffer);
            }

            // Assign state blocks.
            for (var i = 0; i < devices.Length; ++i)
            {
                var newOffset = newStateBlockOffsets[i];
                var device    = devices[i];
                var oldOffset = device.m_StateBlock.byteOffset;

                if (oldOffset == InputStateBlock.kInvalidOffset)
                {
                    device.m_StateBlock.byteOffset = 0;
                    if (newOffset != 0)
                    {
                        device.BakeOffsetIntoStateBlockRecursive(newOffset);
                    }
                }
                else
                {
                    var delta = newOffset - oldOffset;
                    if (delta != 0)
                    {
                        device.BakeOffsetIntoStateBlockRecursive(delta);
                    }
                }
            }
        }
示例#2
0
 // Switch the current set of buffers used by the system.
 public static void SwitchTo(InputStateBuffers buffers, InputUpdateType update)
 {
     s_CurrentBuffers = buffers.GetDoubleBuffersFor(update);
 }