输入映射
基于框架最基本事件系统,额外提供了三种自动将鼠标或键盘之类的输入映射为事件的类。
输入事件类
BoolInputGameEvent
此类用来将鼠标或者键盘之类的输入映射为一个bool值,比如当某个特定的按键按下时,此类中的bool value将变为true。
此事件在收到符合条件的输入(鼠标/键盘等等)时,会自动进行传播,不需要手动调用Propagate,因此只需要往里面添加Callback即可。
此类对应的配置文件是BoolInputGameEventConfig。

配置界面如上图所示,其中输入动作组这个列表里的元素是或的关系,而输入动作里的元素是且的关系,比如上面的配置界面的意思就是说:
当按下Left Shift+T或者按下Q时,此事件将会传播。
这个Left Shift和T是且的关系,也就是说必须同时满足正在按压Left Shift且按下T的瞬间时,事件才会传播。
而Left Shift+T和Q是或的关系,这两个任意一个满足时,事件都会传播。
FloatInputGameEvent
与 BoolInputGameEvent类似,将输入映射为一个float值。
一般用于2D里的人物移动。
Vector2InputGameEvent
与 BoolInputGameEvent类似,将输入映射为一个Vector2。
一般用于3D里的人物移动。
大量创建输入事件
可以使用
GamePrefabIDAutoRegisterAttribute
将输入事件的ID都写到一个类,这样方便看。
下面是一个示例:
https://github.com/VMware233/VMFramework/blob/main/Assets/Examples/GameEvents/PlayerGameEvents.cs
using VMFramework.GameEvents;
using VMFramework.GameLogicArchitecture;
namespace VMFramework.Examples
{
public static class PlayerGameEvents
{
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string DASH = "player_dash_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string JUMP = "player_jump_event";
[GamePrefabIDAutoRegister(typeof(FloatInputGameEventConfig))]
public const string MOVE = "player_move_event";
[GamePrefabIDAutoRegister(typeof(Vector2InputGameEventConfig))]
public const string DIRECTION = "player_direction_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string FLY = "player_fly_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string FLY_CANCEL = "player_fly_cancel_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string CROUCH = "player_crouch_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string CROUCH_CANCEL = "player_crouch_cancel_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string SPELL_ONE_CAST = "player_spell_one_cast_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string SPELL_TWO_CAST = "player_spell_two_cast_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string SPELL_THREE_CAST = "player_spell_three_cast_event";
[GamePrefabIDAutoRegister(typeof(BoolInputGameEventConfig))]
public const string SPELL_FOUR_CAST = "player_spell_four_cast_event";
}
}
最后更新于
这有帮助吗?