Initial setup
This commit is contained in:
@@ -263,6 +263,31 @@ API_ENUM() enum class InputActionMode
|
||||
Release = 2,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The input action event trigger modes.
|
||||
/// </summary>
|
||||
API_ENUM() enum class InputActionPhase
|
||||
{
|
||||
/// <summary>
|
||||
/// User is pressing the key/button.
|
||||
/// </summary>
|
||||
Pressing = 0,
|
||||
|
||||
/// <summary>
|
||||
/// User pressed the key/button (but wasn't pressing it in the previous frame).
|
||||
/// </summary>
|
||||
Press = 1,
|
||||
|
||||
/// <summary>
|
||||
/// User released the key/button (was pressing it in the previous frame).
|
||||
/// </summary>
|
||||
Release = 2,
|
||||
|
||||
Waiting = 3,
|
||||
|
||||
None = 4,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The input gamepad index.
|
||||
/// </summary>
|
||||
|
||||
@@ -29,11 +29,13 @@ struct ActionData
|
||||
{
|
||||
bool Active;
|
||||
uint64 FrameIndex;
|
||||
InputActionPhase Phase;
|
||||
|
||||
ActionData()
|
||||
{
|
||||
Active = false;
|
||||
FrameIndex = 0;
|
||||
Phase = InputActionPhase::None;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -597,6 +599,16 @@ bool Input::GetAction(const StringView& name)
|
||||
return e ? e->Active : false;
|
||||
}
|
||||
|
||||
InputActionPhase Input::GetActionPhase(const StringView& name)
|
||||
{
|
||||
const auto e = Actions.TryGet(name);
|
||||
if (e != nullptr)
|
||||
{
|
||||
return e->Phase;
|
||||
}
|
||||
return InputActionPhase::None;
|
||||
}
|
||||
|
||||
float Input::GetAxis(const StringView& name)
|
||||
{
|
||||
const auto e = Axes.TryGet(name);
|
||||
@@ -806,6 +818,7 @@ void InputService::Update()
|
||||
ActionData& data = Actions[name];
|
||||
|
||||
data.Active = false;
|
||||
data.Phase = InputActionPhase::Waiting;
|
||||
|
||||
// Mark as updated in this frame
|
||||
data.FrameIndex = frame;
|
||||
@@ -830,6 +843,13 @@ void InputService::Update()
|
||||
isActive = Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton);
|
||||
}
|
||||
|
||||
if (Input::GetKeyDown(config.Key) || Input::GetMouseButtonDown(config.MouseButton) || Input::GetGamepadButtonDown(config.Gamepad, config.GamepadButton))
|
||||
data.Phase = InputActionPhase::Press;
|
||||
else if (Input::GetKey(config.Key) || Input::GetMouseButton(config.MouseButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadButton))
|
||||
data.Phase = InputActionPhase::Pressing;
|
||||
else if (Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton))
|
||||
data.Phase = InputActionPhase::Release;
|
||||
|
||||
data.Active |= isActive;
|
||||
}
|
||||
|
||||
|
||||
@@ -309,6 +309,14 @@ public:
|
||||
/// <seealso cref="ActionMappings"/>
|
||||
API_FUNCTION() static bool GetAction(const StringView& name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the virtual action identified by name. Use <see cref="ActionMappings"/> to get the current config.
|
||||
/// </summary>
|
||||
/// <param name="name">The action name.</param>
|
||||
/// <returns>True if action has been triggered in the current frame (e.g. button pressed), otherwise false.</returns>
|
||||
/// <seealso cref="ActionMappings"/>
|
||||
API_FUNCTION() static InputActionPhase GetActionPhase(const StringView& name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the virtual axis identified by name. Use <see cref="AxisMappings"/> to get the current config.
|
||||
/// </summary>
|
||||
|
||||
@@ -48,6 +48,9 @@ API_STRUCT() struct ActionConfig
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(40)")
|
||||
InputGamepadIndex Gamepad;
|
||||
|
||||
API_FIELD(Attributes = "EditorOrder(50)")
|
||||
InputActionMode Phase;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user