Невозможно прочитать значение типа 'float' из элемента управления - PullRequest
0 голосов
/ 20 октября 2019

Я пытаюсь сопоставить свой контроллер Dual Shock 4 с новой системой ввода, но я получаю эту ошибку:

InvalidOperationException: Cannot read value of type 'float' from control '/DualShock4GamepadHID/leftStick' bound to action 'Gameplay/Movement[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d,/DualShock4GamepadHID/leftStick,/DualShock4GamepadHID/leftStick,/DualShock4GamepadHID/leftStick,/DualShock4GamepadHID/leftStick]' (control is a 'StickControl' with value type 'Vector2')
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputActionState.cs:1929)
UnityEngine.InputSystem.InputActionState.ReadCompositePartValue[TValue,TComparer] (System.Int32 bindingIndex, System.Int32 partNumber, System.Boolean* buttonValuePtr, System.Int32& controlIndex, TComparer comparer) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputActionState.cs:2010)
UnityEngine.InputSystem.InputBindingCompositeContext.ReadValueAsButton (System.Int32 partNumber) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputBindingCompositeContext.cs:252)
UnityEngine.InputSystem.Composites.Vector2Composite.ReadValue (UnityEngine.InputSystem.InputBindingCompositeContext& context) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/Composites/Vector2Composite.cs:72)
UnityEngine.InputSystem.Composites.Vector2Composite.EvaluateMagnitude (UnityEngine.InputSystem.InputBindingCompositeContext& context) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/Composites/Vector2Composite.cs:83)
UnityEngine.InputSystem.InputActionState.ComputeMagnitude (System.Int32 bindingIndex, System.Int32 controlIndex) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputActionState.cs:1826)
UnityEngine.InputSystem.InputActionState.ShouldIgnoreControlStateChange (UnityEngine.InputSystem.InputActionState+TriggerState& trigger, System.Int32 actionIndex) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputActionState.cs:984)
UnityEngine.InputSystem.InputActionState.ProcessControlStateChange (System.Int32 mapIndex, System.Int32 controlIndex, System.Int32 bindingIndex, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputActionState.cs:875)
UnityEngine.InputSystem.InputActionState.UnityEngine.InputSystem.LowLevel.IInputStateChangeMonitor.NotifyControlStateChanged (UnityEngine.InputSystem.InputControl control, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, System.Int64 mapControlAndBindingIndex) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/Actions/InputActionState.cs:783)
UnityEngine.InputSystem.InputManager.FireStateChangeNotifications (System.Int32 deviceIndex, System.Double internalTime, UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.1/InputSystem/InputManager.cs:2687)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:120)

Клавиши WASD работают, а мой контроллер - нет.

Это мой сценарий:

using UnityEngine;
using UnityEngine.InputSystem;

public class CubeMovement : MonoBehaviour, PlayerControls.IGameplayActions
{
    private PlayerControls m_PlayerControls;
    private Vector2 m_Direction;
    [SerializeField] private float movementVelocity;

    private void Awake()
    {
        m_Direction = Vector2.zero;
        m_PlayerControls = new PlayerControls();
        m_PlayerControls.Gameplay.SetCallbacks(this);
    }

    private void Update()
    {
        var direction = Time.deltaTime * new Vector3(m_Direction.x, 0, m_Direction.y);
        transform.Translate(direction);
    }

    public void OnMovement(InputAction.CallbackContext context)
    {
        m_Direction = movementVelocity * context.ReadValue<Vector2>();
    }

    private void OnEnable()
    {
        m_PlayerControls.Gameplay.Enable();
    }


    private void OnDisable()
    {
        m_PlayerControls.Gameplay.Disable();
    }
}

Это моя конфигурация:

Unity Input Action configuration


Я не могу найти ни одногорешение в сети. Похоже, я первый с этой проблемой.

enter image description here

1 Ответ

0 голосов
/ 20 октября 2019

Я нашел решение. Правильный способ сопоставления флешки - использовать простую привязку вместо двухмерного векторного композита.

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...