前面一篇大致简单的介绍了下Input System,并且通过官方的 SimpleDemo_UsingPlayerInput 来了解了PlayerInput组件的使用。接下来让我们通过其他几个Demo来了解下Input System的其他几种使用方法。
SimpleDemo_UsingActionAsset Demo
这个Demo,相比SimpleDemo_UsingPlayerInput,会发现在这个Demo中并没有使用到Player Input组件,而在SimpleController_UsingActionAsset.cs中,多了一个SimpleControls的类。
我们来看下SimpleControls内部,首先有个Json格式的字符串,大致看下内容会发现其就是SimpleDemo_UsingPlayerInput中PlayerInput通过Create Action生成的SimpleControls.inputactions文件的内容。再往后便是声明inputactions文件中配置的Actions等等。
使用起来也不需要在Player Input组件中去绑定事件,只需要使用代码来绑定即可,例如:
m_Controls = new SimpleControls();
m_Controls.gameplay.fire.performed +=
ctx =>
{
//to something
};
m_Controls.gameplay.fire.started +=
ctx =>
{
//to something
};
而要读取输入设备的值也很方便,例如
public void Update()
{
var look = m_Controls.gameplay.