C# Unity新输入系统未显示序列化字段
我正在使用Unity 2019.1.4f1,刚刚从软件包管理器获得了新的Unity输入系统。我无法在打算使用它的MonoBehavior中看到用于链接生成的C#类的序列化字段 我已经公开并向实例添加了[SerializeField]属性,但它不会在检查器中显示该字段。 因此,我尝试在Monobehavior中以编程方式创建实例,但它不起作用。未调用我的SelectDestination方法C# Unity新输入系统未显示序列化字段,c#,unity3d,input,C#,Unity3d,Input,我正在使用Unity 2019.1.4f1,刚刚从软件包管理器获得了新的Unity输入系统。我无法在打算使用它的MonoBehavior中看到用于链接生成的C#类的序列化字段 我已经公开并向实例添加了[SerializeField]属性,但它不会在检查器中显示该字段。 因此,我尝试在Monobehavior中以编程方式创建实例,但它不起作用。未调用我的SelectDestination方法 public class PlayerInputManager : MonoBehaviour {
public class PlayerInputManager : MonoBehaviour
{
[SerializeField]
public PlayerInput Input;
private void Awake()
{
Input = new PlayerInput();
Input.Enable();
}
void OnEnable()
{
Input.Player.SelectDestination.performed += ctx => SelectDestination();
Input.Player.SelectTarget.performed += ctx => SelectDestination();
Input.Player.W.performed += ctx => SelectDestination();
Input.Player.Enable();
}
void OnDisable()
{
Input.Player.SelectDestination.performed -= ctx => SelectDestination();
Input.Player.SelectTarget.performed -= ctx => SelectDestination();
Input.Player.W.performed -= ctx => SelectDestination();
Input.Player.Disable();
}
void SelectDestination()
{
Debug.Log("BLA");
}
}
当按下W、左键单击或右键单击时,应记录“BLA”
如果使用此选项,Unity将根据我的播放器输入导入设置生成以下代码:
// GENERATED AUTOMATICALLY FROM 'Assets/Player/Input/PlayerInput.inputactions'
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class PlayerInput : IInputActionCollection
{
private InputActionAsset asset;
public PlayerInput()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""PlayerInput"",
""maps"": [
{
""name"": ""Player"",
""id"": ""5bcdf4ef-1e0a-4aa8-b012-545024ebcf4b"",
""actions"": [
{
""name"": ""Select Destination"",
""id"": ""1d0574dd-8a36-47cf-9987-1ee778cc187b"",
""expectedControlLayout"": """",
""continuous"": false,
""passThrough"": false,
""initialStateCheck"": false,
""processors"": """",
""interactions"": """",
""bindings"": []
},
{
""name"": ""Select Target"",
""id"": ""a1a64f6a-ab46-42f5-854c-2bcf2c2a462b"",
""expectedControlLayout"": """",
""continuous"": false,
""passThrough"": false,
""initialStateCheck"": false,
""processors"": """",
""interactions"": """",
""bindings"": []
},
{
""name"": ""W"",
""id"": ""c0d92aea-cab2-4277-b6a7-89dfa0944f83"",
""expectedControlLayout"": """",
""continuous"": false,
""passThrough"": false,
""initialStateCheck"": false,
""processors"": """",
""interactions"": """",
""bindings"": []
}
],
""bindings"": [
{
""name"": """",
""id"": ""539fd2ab-5081-4f91-b1c6-ed9db7833b61"",
""path"": ""<Mouse>/rightButton"",
""interactions"": """",
""processors"": """",
""groups"": ""PC"",
""action"": ""Select Destination"",
""isComposite"": false,
""isPartOfComposite"": false,
""modifiers"": """"
},
{
""name"": """",
""id"": ""61673484-a2cd-49e3-8352-aa0e5f791bc5"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": ""PC"",
""action"": ""Select Target"",
""isComposite"": false,
""isPartOfComposite"": false,
""modifiers"": """"
},
{
""name"": """",
""id"": ""8c4c3c98-65b7-4c0b-80cc-0e25d2a59567"",
""path"": ""<Keyboard>/w"",
""interactions"": """",
""processors"": """",
""groups"": "";PC"",
""action"": ""W"",
""isComposite"": false,
""isPartOfComposite"": false,
""modifiers"": """"
}
]
}
],
""controlSchemes"": [
{
""name"": ""PC"",
""basedOn"": """",
""bindingGroup"": ""PC"",
""devices"": [
{
""devicePath"": ""<Keyboard>"",
""isOptional"": false,
""isOR"": false
},
{
""devicePath"": ""<Mouse>"",
""isOptional"": false,
""isOR"": false
}
]
}
]
}");
// Player
m_Player = asset.GetActionMap("Player");
m_Player_SelectDestination = m_Player.GetAction("Select Destination");
m_Player_SelectTarget = m_Player.GetAction("Select Target");
m_Player_W = m_Player.GetAction("W");
}
~PlayerInput()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes
{
get => asset.controlSchemes;
}
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
// Player
private InputActionMap m_Player;
private IPlayerActions m_PlayerActionsCallbackInterface;
private InputAction m_Player_SelectDestination;
private InputAction m_Player_SelectTarget;
private InputAction m_Player_W;
public struct PlayerActions
{
private PlayerInput m_Wrapper;
public PlayerActions(PlayerInput wrapper) { m_Wrapper = wrapper; }
public InputAction @SelectDestination { get { return m_Wrapper.m_Player_SelectDestination; } }
public InputAction @SelectTarget { get { return m_Wrapper.m_Player_SelectTarget; } }
public InputAction @W { get { return m_Wrapper.m_Player_W; } }
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled { get { return Get().enabled; } }
public InputActionMap Clone() { return Get().Clone(); }
public static implicit operator InputActionMap(PlayerActions set) { return set.Get(); }
public void SetCallbacks(IPlayerActions instance)
{
if (m_Wrapper.m_PlayerActionsCallbackInterface != null)
{
SelectDestination.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnSelectDestination;
SelectDestination.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnSelectDestination;
SelectDestination.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnSelectDestination;
SelectTarget.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnSelectTarget;
SelectTarget.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnSelectTarget;
SelectTarget.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnSelectTarget;
W.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnW;
W.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnW;
W.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnW;
}
m_Wrapper.m_PlayerActionsCallbackInterface = instance;
if (instance != null)
{
SelectDestination.started += instance.OnSelectDestination;
SelectDestination.performed += instance.OnSelectDestination;
SelectDestination.canceled += instance.OnSelectDestination;
SelectTarget.started += instance.OnSelectTarget;
SelectTarget.performed += instance.OnSelectTarget;
SelectTarget.canceled += instance.OnSelectTarget;
W.started += instance.OnW;
W.performed += instance.OnW;
W.canceled += instance.OnW;
}
}
}
public PlayerActions @Player
{
get
{
return new PlayerActions(this);
}
}
private int m_PCSchemeIndex = -1;
public InputControlScheme PCScheme
{
get
{
if (m_PCSchemeIndex == -1) m_PCSchemeIndex = asset.GetControlSchemeIndex("PC");
return asset.controlSchemes[m_PCSchemeIndex];
}
}
public interface IPlayerActions
{
void OnSelectDestination(InputAction.CallbackContext context);
void OnSelectTarget(InputAction.CallbackContext context);
void OnW(InputAction.CallbackContext context);
}
}
//从“Assets/Player/Input/PlayerInput.inputations”自动生成
使用制度;
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.InputSystem;
使用UnityEngine.InputSystem.Utilities;
公共类PlayerInput:IInputActionCollection
{
私人投入资产;
公共播放机put()
{
asset=InputActionAsset.FromJson(@){
“名称”:“PlayerInput”,
“地图”:[
{
“姓名”:“玩家”,
“id”:“5bcdf4ef-1e0a-4aa8-b012-545024ebcf4b”,
“行动”:[
{
“”名称“”:“”选择目标“”,
“id”:“1d0574dd-8a36-47cf-9987-1ee778cc187b”,
“expectedControlLayout”“:”“”,
“continuous”:false,
“passThrough”:false,
“initialStateCheck”:false,
“处理器”:“处理器”,
“”交互“”:“”“”,
“”绑定“”:[]
},
{
“名称”:“选择目标”,
“id”:“a1a64f6a-ab46-42f5-854c-2BCF2C462A62B”,
“expectedControlLayout”“:”“”,
“continuous”:false,
“passThrough”:false,
“initialStateCheck”:false,
“处理器”:“处理器”,
“”交互“”:“”“”,
“”绑定“”:[]
},
{
“名称”:“W”,
“id”:“c0d92aea-cab2-4277-b6a7-89dfa0944f83”,
“expectedControlLayout”“:”“”,
“continuous”:false,
“passThrough”:false,
“initialStateCheck”:false,
“处理器”:“处理器”,
“”交互“”:“”“”,
“”绑定“”:[]
}
],
“绑定”:[
{
“”名称“”:“”“”,
“id”:“539fd2ab-5081-4f91-b1c6-ed9db7833b61”,
“路径”“:”“/rightButton”“,
“”交互“”:“”“”,
“处理器”:“处理器”,
“组”:“PC”,
“”操作“”:“”选择目标“”,
“isComposite”:false,
“isPartOfComposite”:false,
“修饰符”:“
},
{
“”名称“”:“”“”,
“id”:“61673484-a2cd-49e3-8352-aa0e5f791bc5”,
“路径”:“/leftButton”,
“”交互“”:“”“”,
“处理器”:“处理器”,
“组”:“PC”,
“”操作“”:“”选择目标“”,
“isComposite”:false,
“isPartOfComposite”:false,
“修饰符”:“
},
{
“”名称“”:“”“”,
“id”:“8c4c3c98-65b7-4c0b-80cc-0e25d2a59567”,
“路径”:“/w”,
“”交互“”:“”“”,
“处理器”:“处理器”,
“组”:“PC”,
“动作”:“W”,
“isComposite”:false,
“isPartOfComposite”:false,
“修饰符”:“
}
]
}
],
“控制计划”:[
{
“名称”:“电脑”,
“basedOn”:“basedOn”,
“”绑定组“”:“”PC“”,
“设备”:[
{
“设备路径”:”,
“等民族性”:假,
“isOR”:false
},
{
“设备路径”:”,
“等民族性”:假,
“isOR”:false
}
]
}
]
}");
//玩家
m_Player=asset.GetActionMap(“播放器”);
m_Player\u SelectDestination=m_Player.GetAction(“选择目的地”);
m_Player\u SelectTarget=m_Player.GetAction(“选择目标”);
m_Player_W=m_Player.GetAction(“W”);
}
~PlayerInput()
{
单元引擎。对象。销毁(资产);
}
公共输入绑定?绑定掩码
{
get=>asset.bindingMask;
set=>asset.bindingMask=value;
}
公共ReadOnlyRay?设备
{
get=>asset.devices;
set=>asset.devices=值;
}
公共只读阵列控制方案
{
get=>asset.controlSchemes;
}
公共布尔包含(输入操作)
{
返回资产。包含(操作);
}
公共IEnumerator GetEnumerator()
{
返回asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
返回GetEnumerator();
}
公共作废启用()
{
asset.Enable();
}
公共无效禁用()
{
asset.Disable();
}
//玩家
私有输入映射m_播放器;
私有IPlayerActions m_PlayerActionsCallbackInterface;
私人输入
public class PlayerInputManager : MonoBehaviour
{
[SerializeField]
public PlayerInput Input;
private void Awake()
{
Input = new PlayerInput(); <<<<<<<<<<<
Input.Enable();
}
...
}