Пример #1
0
 public void OnUpdate(InputUpdateType updateType)
 {
     if (updateType == InputUpdateType.Dynamic)
     {
         var isButton1Pressed = Time.frameCount % 100 == 0;
         if (isButton1Pressed)
         {
             InputSystem.QueueStateEvent(this, new MyDeviceState {
                 buttons = 1
             });
         }
         else
         {
             InputSystem.QueueStateEvent(this, new MyDeviceState());
         }
     }
 }
Пример #2
0
        public DoubleBuffers GetDoubleBuffersFor(InputUpdateType updateType)
        {
            switch (updateType)
            {
            case InputUpdateType.BeforeRender:
            case InputUpdateType.Fixed:
            case InputUpdateType.Dynamic:
            case InputUpdateType.Manual:
                return(m_PlayerStateBuffers);

#if UNITY_EDITOR
            case InputUpdateType.Editor:
                return(m_EditorStateBuffers);
#endif
            }

            throw new ArgumentException("Unrecognized InputUpdateType: " + updateType, nameof(updateType));
        }
Пример #3
0
        public static InputUpdateType GetUpdateTypeForPlayer(this InputUpdateType mask)
        {
            if ((mask & InputUpdateType.Manual) != 0)
            {
                return(InputUpdateType.Manual);
            }

            if ((mask & InputUpdateType.Dynamic) != 0)
            {
                return(InputUpdateType.Dynamic);
            }

            if ((mask & InputUpdateType.Fixed) != 0)
            {
                return(InputUpdateType.Fixed);
            }

            return(InputUpdateType.None);
        }
        void FireDefaultState(InputUpdateType obj)
        {
            InputSystem.onAfterUpdate -= FireDefaultState;

            m_State.Slider1 = 0.5f;
            m_State.Slider2 = 0.5f;
            m_State.Slider3 = 0.5f;
            m_State.Slider4 = 0.5f;
            m_State.Slider5 = 0.5f;
            m_State.Slider6 = 0.5f;
            m_State.Slider7 = 0.5f;
            m_State.Slider8 = 0.5f;

            m_State.PanDevice1 = 0.5f;
            m_State.PanDevice2 = 0.5f;
            m_State.PanDevice3 = 0.5f;
            m_State.PanDevice4 = 0.5f;
            m_State.PanDevice5 = 0.5f;
            m_State.PanDevice6 = 0.5f;
            m_State.PanDevice7 = 0.5f;
            m_State.PanDevice8 = 0.5f;

            m_State.SendA1 = 0.5f;
            m_State.SendA2 = 0.5f;
            m_State.SendA3 = 0.5f;
            m_State.SendA4 = 0.5f;
            m_State.SendA5 = 0.5f;
            m_State.SendA6 = 0.5f;
            m_State.SendA7 = 0.5f;
            m_State.SendA8 = 0.5f;

            m_State.SendB1 = 0.5f;
            m_State.SendB2 = 0.5f;
            m_State.SendB3 = 0.5f;
            m_State.SendB4 = 0.5f;
            m_State.SendB5 = 0.5f;
            m_State.SendB6 = 0.5f;
            m_State.SendB7 = 0.5f;
            m_State.SendB8 = 0.5f;

            InputSystem.QueueStateEvent(this, m_State);
        }
Пример #5
0
        internal static void OnUpdate(InputUpdateType type)
        {
            s_LastUpdateType = type;
            switch (type)
            {
            case InputUpdateType.Dynamic:
            case InputUpdateType.Manual:
            case InputUpdateType.Fixed:
                s_PlayerUpdateStepCount.OnUpdate();
                s_UpdateStepCount = s_PlayerUpdateStepCount.value;
                break;

                #if UNITY_EDITOR
            case InputUpdateType.Editor:
                s_EditorUpdateStepCount.OnUpdate();
                s_UpdateStepCount = s_EditorUpdateStepCount.value;
                break;
                #endif
            }
        }
Пример #6
0
        public void Update(InputUpdateType updateType)
        {
            if ((updateType & InputUpdateType.Dynamic) == InputUpdateType.Dynamic)
            {
                NativeInputSystem.Update(NativeInputUpdateType.Dynamic);
            }
            if ((updateType & InputUpdateType.Fixed) == InputUpdateType.Fixed)
            {
                NativeInputSystem.Update(NativeInputUpdateType.Fixed);
            }
            if ((updateType & InputUpdateType.BeforeRender) == InputUpdateType.BeforeRender)
            {
                NativeInputSystem.Update(NativeInputUpdateType.BeforeRender);
            }
#if UNITY_EDITOR
            if ((updateType & InputUpdateType.Editor) == InputUpdateType.Editor)
            {
                NativeInputSystem.Update(NativeInputUpdateType.Editor);
            }
#endif
        }
Пример #7
0
        public unsafe void Update(InputUpdateType type)
        {
            if (!onShouldRunUpdate.Invoke(type))
            {
                return;
            }

            lock (m_Lock)
            {
                if (m_NewDeviceDiscoveries != null && m_NewDeviceDiscoveries.Count > 0)
                {
                    if (onDeviceDiscovered != null)
                    {
                        foreach (var entry in m_NewDeviceDiscoveries)
                        {
                            onDeviceDiscovered(entry.Key, entry.Value);
                        }
                    }
                    m_NewDeviceDiscoveries.Clear();
                }

                onBeforeUpdate?.Invoke(type);

                // Advance time *after* onBeforeUpdate so that events generated from onBeforeUpdate
                // don't get bumped into the following update.
                if (type == InputUpdateType.Dynamic)
                {
                    currentTime += advanceTimeEachDynamicUpdate;
                }

                if (onUpdate != null)
                {
                    var buffer = new InputEventBuffer(
                        (InputEvent *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(m_EventBuffer),
                        m_EventCount, m_EventWritePosition, m_EventBuffer.Length);

                    onUpdate(type, ref buffer);

                    #if UNITY_2019_1_OR_NEWER
                    m_EventCount         = buffer.eventCount;
                    m_EventWritePosition = (int)buffer.sizeInBytes;
                    if (NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(buffer.data) !=
                        NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(m_EventBuffer))
                    {
                        m_EventBuffer = buffer.data;
                    }
                    #else
                    if (type != InputUpdateType.BeforeRender)
                    {
                        m_EventCount         = 0;
                        m_EventWritePosition = 0;
                    }
                    #endif
                }
                else
                {
                    m_EventCount         = 0;
                    m_EventWritePosition = 0;
                }

                ++frameCount;
            }
        }
Пример #8
0
 public static bool IsEditorUpdate(this InputUpdateType updateType)
 {
     return(updateType == InputUpdateType.Editor);
 }
Пример #9
0
 private static void ReEnableAfterDomainReload(InputUpdateType updateType)
 {
     OnSettingsChanged();
     InputSystem.onBeforeUpdate -= ReEnableAfterDomainReload;
 }
Пример #10
0
 public void Update(InputUpdateType updateType)
 {
     NativeInputSystem.Update((NativeInputUpdateType)updateType);
 }
Пример #11
0
        private static void OnUpdate(InputUpdateType updateType)
        {
            if (api == null)
            {
                return;
            }

            // Update controller state.
            api.RunFrame();

            // Check if we have any new controllers have appeared.
            if (s_ConnectedControllers == null)
            {
                s_ConnectedControllers = new SteamHandle <SteamController> [STEAM_CONTROLLER_MAX_COUNT];
            }
            var numConnectedControllers = api.GetConnectedControllers(s_ConnectedControllers);

            for (var i = 0; i < numConnectedControllers; ++i)
            {
                var handle = s_ConnectedControllers[i];

                // See if we already have a device for this one.
                if (s_InputDevices != null)
                {
                    SteamController existingDevice = null;
                    for (var n = 0; n < s_InputDeviceCount; ++n)
                    {
                        if (s_InputDevices[n].steamControllerHandle == handle)
                        {
                            existingDevice = s_InputDevices[n];
                            break;
                        }
                    }

                    // Yes, we do.
                    if (existingDevice != null)
                    {
                        continue;
                    }
                }

                ////FIXME: this should not create garbage
                // No, so create a new device.
                var controllerLayouts = InputSystem.ListLayoutsBasedOn("SteamController");
                foreach (var layout in controllerLayouts)
                {
                    // Rather than directly creating a device with the layout, let it go through
                    // the usual matching process.
                    var device = InputSystem.AddDevice(new InputDeviceDescription
                    {
                        interfaceName = SteamController.kSteamInterface,
                        product       = layout
                    });

                    // Make sure it's a SteamController we got.
                    var steamDevice = device as SteamController;
                    if (steamDevice == null)
                    {
                        Debug.LogError(string.Format(
                                           "InputDevice created from layout '{0}' based on the 'SteamController' layout is not a SteamController",
                                           device.layout));
                        continue;
                    }

                    // Resolve the controller's actions.
                    steamDevice.InvokeResolveSteamActions();

                    // Assign it the Steam controller handle.
                    steamDevice.steamControllerHandle = handle;

                    ArrayHelpers.AppendWithCapacity(ref s_InputDevices, ref s_InputDeviceCount, steamDevice);
                }
            }

            // Update all controllers we have.
            for (var i = 0; i < s_InputDeviceCount; ++i)
            {
                var device = s_InputDevices[i];
                var handle = device.steamControllerHandle;

                // Check if the device still exists.
                var stillExists = false;
                for (var n = 0; n < numConnectedControllers; ++n)
                {
                    if (s_ConnectedControllers[n] == handle)
                    {
                        stillExists = true;
                        break;
                    }
                }

                // If not, remove it.
                if (!stillExists)
                {
                    ArrayHelpers.EraseAtByMovingTail(s_InputDevices, ref s_InputDeviceCount, i);
                    ////REVIEW: should this rather queue a device removal event?
                    InputSystem.RemoveDevice(device);
                    --i;
                    continue;
                }

                ////TODO: support polling Steam controllers on an async polling thread adhering to InputSystem.pollingFrequency
                // Otherwise, update it.
                device.InvokeUpdate();
            }
        }
Пример #12
0
        // Allocates all buffers to serve the given updates and comes up with a spot
        // for the state block of each device. Returns the new state blocks for the
        // devices (it will *NOT* install them on the devices).
        public unsafe uint[] AllocateAll(InputUpdateType updateMask, InputDevice[] devices)
        {
            uint[] newDeviceOffsets = null;
            sizePerBuffer = ComputeSizeOfSingleBufferAndOffsetForEachDevice(devices, ref newDeviceOffsets);
            if (sizePerBuffer == 0)
            {
                return(null);
            }

            var isDynamicUpdateEnabled = (updateMask & InputUpdateType.Dynamic) == InputUpdateType.Dynamic;
            var isFixedUpdateEnabled   = (updateMask & InputUpdateType.Fixed) == InputUpdateType.Fixed;

            // Determine how much memory we need.
            var deviceCount = devices.Length;
            var mappingTableSizePerBuffer = (uint)(deviceCount * sizeof(void *) * 2);

            if (isDynamicUpdateEnabled)
            {
                totalSize += sizePerBuffer * 2;
                totalSize += mappingTableSizePerBuffer;
            }
            if (isFixedUpdateEnabled)
            {
                totalSize += sizePerBuffer * 2;
                totalSize += mappingTableSizePerBuffer;
            }
            // Before render doesn't have its own buffers.

#if UNITY_EDITOR
            totalSize += sizePerBuffer * 2;
            totalSize += mappingTableSizePerBuffer;
#endif

            // Allocate.
            m_AllBuffers = UnsafeUtility.Malloc(totalSize, 4, Allocator.Persistent);
            UnsafeUtility.MemClear(m_AllBuffers, totalSize);

            // Set up device to buffer mappings.
            var ptr = m_AllBuffers;
            if (isDynamicUpdateEnabled)
            {
                m_DynamicUpdateBuffers =
                    SetUpDeviceToBufferMappings(devices, ref ptr, sizePerBuffer, mappingTableSizePerBuffer);
            }
            if (isFixedUpdateEnabled)
            {
                m_FixedUpdateBuffers =
                    SetUpDeviceToBufferMappings(devices, ref ptr, sizePerBuffer, mappingTableSizePerBuffer);
            }

            if (!isFixedUpdateEnabled)
            {
                m_FixedUpdateBuffers = m_DynamicUpdateBuffers;
            }
            if (!isDynamicUpdateEnabled)
            {
                m_DynamicUpdateBuffers = m_FixedUpdateBuffers;
            }

#if UNITY_EDITOR
            m_EditorUpdateBuffers =
                SetUpDeviceToBufferMappings(devices, ref ptr, sizePerBuffer, mappingTableSizePerBuffer);
#endif

            return(newDeviceOffsets);
        }
Пример #13
0
        public unsafe void Update(InputUpdateType type)
        {
            if (!onShouldRunUpdate.Invoke(type))
            {
                return;
            }

            lock (m_Lock)
            {
                if (type == InputUpdateType.Dynamic && !dontAdvanceUnscaledGameTimeNextDynamicUpdate)
                {
                    unscaledGameTime += 1 / 30f;
                    dontAdvanceUnscaledGameTimeNextDynamicUpdate = false;
                }

                if (m_NewDeviceDiscoveries != null && m_NewDeviceDiscoveries.Count > 0)
                {
                    if (onDeviceDiscovered != null)
                    {
                        foreach (var entry in m_NewDeviceDiscoveries)
                        {
                            onDeviceDiscovered(entry.Key, entry.Value);
                        }
                    }
                    m_NewDeviceDiscoveries.Clear();
                }

                onBeforeUpdate?.Invoke(type);

                // Advance time *after* onBeforeUpdate so that events generated from onBeforeUpdate
                // don't get bumped into the following update.
                if (type == InputUpdateType.Dynamic && !dontAdvanceTimeNextDynamicUpdate)
                {
                    currentTime += advanceTimeEachDynamicUpdate;
                    dontAdvanceTimeNextDynamicUpdate = false;
                }

                if (onUpdate != null)
                {
                    var buffer = new InputEventBuffer(
                        (InputEvent *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(m_EventBuffer),
                        m_EventCount, m_EventWritePosition, m_EventBuffer.Length);

                    try
                    {
                        onUpdate(type, ref buffer);
                    }
                    catch (Exception e)
                    {
                        // Same order as in NativeInputRuntime
                        Debug.LogException(e);
                        Debug.LogError($"{e.GetType().Name} during event processing of {type} update; resetting event buffer");

                        // Rethrow exception for test runtime to enable us to assert against it in tests.
                        m_EventCount         = 0;
                        m_EventWritePosition = 0;
                        throw;
                    }

                    m_EventCount         = buffer.eventCount;
                    m_EventWritePosition = (int)buffer.sizeInBytes;

                    if (NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(buffer.data) !=
                        NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(m_EventBuffer))
                    {
                        m_EventBuffer = buffer.data;
                    }
                }
                else
                {
                    m_EventCount         = 0;
                    m_EventWritePosition = 0;
                }
            }
        }
Пример #14
0
 // Switch the current set of buffers used by the system.
 public static void SwitchTo(InputStateBuffers buffers, InputUpdateType update)
 {
     s_CurrentBuffers = buffers.GetDoubleBuffersFor(update);
 }
Пример #15
0
 public NexoDeviceInputUpdate() : base(MessageCategoryEnumeration.InputUpdate)
 {
     RequestItem = new InputUpdateType();
     ReplyItem   = null;
 }
Пример #16
0
        // Allocates all buffers to serve the given updates and comes up with a spot
        // for the state block of each device. Returns the new state blocks for the
        // devices (it will *NOT* install them on the devices).
        public unsafe uint[] AllocateAll(InputUpdateType updateMask, InputDevice[] devices, int deviceCount)
        {
            uint[] newDeviceOffsets = null;
            sizePerBuffer = ComputeSizeOfSingleBufferAndOffsetForEachDevice(devices, deviceCount, ref newDeviceOffsets);
            if (sizePerBuffer == 0)
            {
                return(null);
            }
            sizePerBuffer = NumberHelpers.AlignToMultiple(sizePerBuffer, 4);

            var isDynamicUpdateEnabled = (updateMask & InputUpdateType.Dynamic) == InputUpdateType.Dynamic;
            var isFixedUpdateEnabled   = (updateMask & InputUpdateType.Fixed) == InputUpdateType.Fixed;

            // Determine how much memory we need.
            var mappingTableSizePerBuffer = (uint)(deviceCount * sizeof(void *) * 2);

            if (isDynamicUpdateEnabled)
            {
                totalSize += sizePerBuffer * 2;
                totalSize += mappingTableSizePerBuffer;
            }
            if (isFixedUpdateEnabled)
            {
                totalSize += sizePerBuffer * 2;
                totalSize += mappingTableSizePerBuffer;
            }
            // Before render doesn't have its own buffers.

#if UNITY_EDITOR
            totalSize += sizePerBuffer * 2;
            totalSize += mappingTableSizePerBuffer;
#endif

            // Plus 2 more buffers (1 for defaults state, and one for noise filters)
            totalSize += sizePerBuffer * 2;

            // Allocate.
            m_AllBuffers = (IntPtr)UnsafeUtility.Malloc(totalSize, 4, Allocator.Persistent);
            UnsafeUtility.MemClear(m_AllBuffers.ToPointer(), totalSize);

            // Set up device to buffer mappings.
            var ptr = m_AllBuffers;
            if (isDynamicUpdateEnabled)
            {
                m_DynamicUpdateBuffers =
                    SetUpDeviceToBufferMappings(devices, deviceCount, ref ptr, sizePerBuffer, mappingTableSizePerBuffer);
            }
            if (isFixedUpdateEnabled)
            {
                m_FixedUpdateBuffers =
                    SetUpDeviceToBufferMappings(devices, deviceCount, ref ptr, sizePerBuffer, mappingTableSizePerBuffer);
            }

#if UNITY_EDITOR
            m_EditorUpdateBuffers =
                SetUpDeviceToBufferMappings(devices, deviceCount, ref ptr, sizePerBuffer, mappingTableSizePerBuffer);
#endif

            // Default state and noise filter buffers go last
            defaultStateBuffer = ptr;
            noiseBitmaskBuffer = new IntPtr(ptr.ToInt64() + sizePerBuffer);

            return(newDeviceOffsets);
        }
Пример #17
0
 public static void Restore(SerializedState state)
 {
     lastUpdateType     = state.lastUpdateType;
     dynamicUpdateCount = state.dynamicUpdateCount;
     fixedUpdateCount   = state.fixedUpdateCount;
 }
Пример #18
0
    public void EditMode_RunUpdatesInEditMode_AllowsNonEditorUpdates(InputSettings.UpdateMode updateMode, InputUpdateType updateType)
    {
#if ENABLE_XR_COMBINED_DEFINE
        runtime.isInPlayMode            = false;
        InputSystem.settings.updateMode = updateMode;
        var counter = new InputUpdateCounter();
        counter.Start();

        InputSystem.Update(InputUpdateType.Editor);
        InputSystem.Update(updateType);

        Assert.That(counter.updates.Count, Is.EqualTo(1));
        Assert.That(counter.updates[0], Is.EqualTo(InputUpdateType.Editor));
        counter.Reset();
        InputSystem.runUpdatesInEditMode = true;

        InputSystem.Update(InputUpdateType.Editor);
        InputSystem.Update(updateType);

        Assert.That(counter.updates.Count, Is.EqualTo(2));
        Assert.That(counter.updates[0], Is.EqualTo(InputUpdateType.Editor));
        Assert.That(counter.updates[1], Is.EqualTo(updateType));
        counter.Reset();

        InputSystem.runUpdatesInEditMode = false;

        runtime.isInPlayMode = true;
        counter.Stop();
#endif
    }
Пример #19
0
 internal static void RestoreStateAfterEditorUpdate()
 {
     s_LatestUpdateType = s_LatestNonEditorUpdateType;
     s_UpdateStepCount  = s_PlayerUpdateStepCount.value;
 }
Пример #20
0
    public void EnhancedTouch_SupportsInputUpdateIn(InputSettings.UpdateMode updateMode, InputUpdateType updateType)
    {
        InputSystem.settings.updateMode      = updateMode;
        InputSystem.settings.timesliceEvents = false;

        BeginTouch(1, new Vector2(0.123f, 0.234f), queueEventOnly: true);
        InputSystem.Update(updateType);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].screenPosition,
                    Is.EqualTo(new Vector2(0.123f, 0.234f)).Using(Vector2EqualityComparer.Instance));
    }
Пример #21
0
 public static void Update(InputUpdateType updateType)
 {
     s_Manager.Update(updateType);
 }