Пример #1
0
    public static void SampleInput(World world, Entity localPlayer, bool userInputEnabled, float deltaTime, int renderTick)
    {
        var localPlayerState = world.EntityManager.GetComponentData <LocalPlayer>(localPlayer);

        // Only sample input when cursor is locked to avoid affecting multiple clients running on same machine (TODO: find better handling of selected window)
        if (userInputEnabled)
        {
            InputSystem.AccumulateInput(ref localPlayerState.command, deltaTime);
        }
        else
        {
            InputSystem.ClearInput(ref localPlayerState.command); // make sure no keys are stuck in 'down' when user input disabled
        }
        if (m_debugMove.IntValue == 1)
        {
            localPlayerState.command.moveMagnitude = 1;
            localPlayerState.command.lookYaw      += 70 * deltaTime;
        }

        if (m_debugMove.IntValue == 2 || world.EntityManager.HasComponent <FakeLocalPlayer>(localPlayer))
        {
            localPlayerState.m_debugMoveDuration += deltaTime;

            var fireDuration = 2.0f;
            var maxTurn      = 70.0f;

            if (localPlayerState.m_debugMoveDuration > localPlayerState.m_debugMovePhaseDuration)
            {
                localPlayerState.m_debugMoveDuration      = 0;
                localPlayerState.m_debugMovePhaseDuration = 4 + 2 * Random.value;
                localPlayerState.m_debugMoveTurnSpeed     = maxTurn * 0.9f + Random.value * maxTurn * 0.1f;

                localPlayerState.m_debugMoveMag = Random.value > 0.5f ? 1.0f : 0.0f;
            }

            localPlayerState.command.moveMagnitude = localPlayerState.m_debugMoveMag;
            localPlayerState.command.lookYaw      += localPlayerState.m_debugMoveTurnSpeed * deltaTime;
            localPlayerState.command.lookYaw       = localPlayerState.command.lookYaw % 360;
            while (localPlayerState.command.lookYaw < 0.0f)
            {
                localPlayerState.command.lookYaw += 360.0f;
            }
            var firePrimary = localPlayerState.m_debugMoveDuration < fireDuration;
            //localPlayerState.command.buttons.Set(UserCommand.Button.PrimaryFire, firePrimary);
            //localPlayerState.command.buttons.Set(UserCommand.Button.SecondaryFire, !firePrimary);
            //localPlayerState.command.buttons.Set(UserCommand.Button.Jump, localPlayerState.m_debugMoveDuration < jumpDuration);
        }

        localPlayerState.command.renderTick = renderTick;

        world.EntityManager.SetComponentData(localPlayer, localPlayerState);
    }
Пример #2
0
    public void ResetInput(bool userInputEnabled)
    {
        var localPlayerState = m_world.EntityManager.GetComponentData <LocalPlayer>(m_LocalPlayer);

        // Clear keys and resample to make sure released keys gets detected.
        // Pass in 0 as deltaTime to make mouse input and view stick do nothing
        InputSystem.ClearInput(ref localPlayerState.command);

        if (userInputEnabled)
        {
            InputSystem.AccumulateInput(ref localPlayerState.command, 0.0f);
        }

        m_world.EntityManager.SetComponentData(m_LocalPlayer, localPlayerState);
    }