Add AxisChanged event to InputAxis.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace FlaxEngine
|
namespace FlaxEngine
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -23,11 +25,17 @@ namespace FlaxEngine
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float ValueRaw => Input.GetAxisRaw(Name);
|
public float ValueRaw => Input.GetAxisRaw(Name);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when axis is changed. Called before scripts update.
|
||||||
|
/// </summary>
|
||||||
|
public event Action ValueChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="InputAxis"/> class.
|
/// Initializes a new instance of the <see cref="InputAxis"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public InputAxis()
|
public InputAxis()
|
||||||
{
|
{
|
||||||
|
Input.AxisChanged += Handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -36,7 +44,31 @@ namespace FlaxEngine
|
|||||||
/// <param name="name">The axis name.</param>
|
/// <param name="name">The axis name.</param>
|
||||||
public InputAxis(string name)
|
public InputAxis(string name)
|
||||||
{
|
{
|
||||||
|
Input.AxisChanged += Handler;
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Handler(string name)
|
||||||
|
{
|
||||||
|
if (string.Equals(Name, name, StringComparison.OrdinalIgnoreCase))
|
||||||
|
ValueChanged?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finalizes an instance of the <see cref="InputAxis"/> class.
|
||||||
|
/// </summary>
|
||||||
|
~InputAxis()
|
||||||
|
{
|
||||||
|
Input.AxisChanged -= Handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases this object.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Input.AxisChanged -= Handler;
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ Delegate<const Float2&, int32> Input::TouchDown;
|
|||||||
Delegate<const Float2&, int32> Input::TouchMove;
|
Delegate<const Float2&, int32> Input::TouchMove;
|
||||||
Delegate<const Float2&, int32> Input::TouchUp;
|
Delegate<const Float2&, int32> Input::TouchUp;
|
||||||
Delegate<StringView, const InputActionState&> Input::ActionTriggered;
|
Delegate<StringView, const InputActionState&> Input::ActionTriggered;
|
||||||
|
Delegate<StringView> Input::AxisChanged;
|
||||||
Array<ActionConfig> Input::ActionMappings;
|
Array<ActionConfig> Input::ActionMappings;
|
||||||
Array<AxisConfig> Input::AxisMappings;
|
Array<AxisConfig> Input::AxisMappings;
|
||||||
|
|
||||||
@@ -1020,6 +1021,14 @@ void InputService::Update()
|
|||||||
// Send events for the active actions (send events only in play mode)
|
// Send events for the active actions (send events only in play mode)
|
||||||
if (!Time::GetGamePaused())
|
if (!Time::GetGamePaused())
|
||||||
{
|
{
|
||||||
|
for (auto i = Axes.Begin(); i.IsNotEnd(); ++i)
|
||||||
|
{
|
||||||
|
if (Math::NotNearEqual(i->Value.Value, i->Value.PrevKeyValue))
|
||||||
|
{
|
||||||
|
Input::AxisChanged(i->Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto i = Actions.Begin(); i.IsNotEnd(); ++i)
|
for (auto i = Actions.Begin(); i.IsNotEnd(); ++i)
|
||||||
{
|
{
|
||||||
if (i->Value.State != InputActionState::Waiting)
|
if (i->Value.State != InputActionState::Waiting)
|
||||||
|
|||||||
@@ -295,6 +295,12 @@ public:
|
|||||||
/// <seealso cref="InputEvent"/>
|
/// <seealso cref="InputEvent"/>
|
||||||
API_EVENT() static Delegate<StringView, const InputActionState&> ActionTriggered;
|
API_EVENT() static Delegate<StringView, const InputActionState&> ActionTriggered;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event fired when virtual input axis is changed. Called before scripts update. See <see cref="AxisMappings"/> to edit configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="InputAxis"/>
|
||||||
|
API_EVENT() static Delegate<StringView> AxisChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the value of the virtual action identified by name. Use <see cref="ActionMappings"/> to get the current config.
|
/// Gets the value of the virtual action identified by name. Use <see cref="ActionMappings"/> to get the current config.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user