Merge branch 'input' of https://github.com/Tryibion/FlaxEngine into Tryibion-input
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
/// <summary>
|
||||
@@ -23,11 +25,17 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
public float ValueRaw => Input.GetAxisRaw(Name);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when axis is changed. Called before scripts update.
|
||||
/// </summary>
|
||||
public event Action ValueChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InputAxis"/> class.
|
||||
/// </summary>
|
||||
public InputAxis()
|
||||
{
|
||||
Input.AxisValueChanged += Handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -36,7 +44,31 @@ namespace FlaxEngine
|
||||
/// <param name="name">The axis name.</param>
|
||||
public InputAxis(string name)
|
||||
{
|
||||
Input.AxisValueChanged += Handler;
|
||||
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.AxisValueChanged -= Handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases this object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Input.AxisValueChanged -= Handler;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,36 @@ namespace FlaxEngine
|
||||
public string Name;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the event has been triggered during the current frame (e.g. user pressed a key). Use <see cref="Triggered"/> to catch events without active waiting.
|
||||
/// Returns true if the event has been triggered during the current frame (e.g. user pressed a key). Use <see cref="Pressed"/> to catch events without active waiting.
|
||||
/// </summary>
|
||||
public bool Active => Input.GetAction(Name);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the event state. Use Use <see cref="Pressed"/>, <see cref="Pressing"/>, <see cref="Released"/> to catch events without active waiting.
|
||||
/// </summary>
|
||||
public InputActionState State => Input.GetActionState(Name);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when event is triggered (e.g. user pressed a key). Called before scripts update.
|
||||
/// </summary>
|
||||
[System.Obsolete("Depreciated in 1.7, use Pressed Action.")]
|
||||
public event Action Triggered;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when event is pressed (e.g. user pressed a key). Called before scripts update.
|
||||
/// </summary>
|
||||
public event Action Pressed;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when event is being pressing (e.g. user pressing a key). Called before scripts update.
|
||||
/// </summary>
|
||||
public event Action Pressing;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when event is released (e.g. user releases a key). Called before scripts update.
|
||||
/// </summary>
|
||||
public event Action Released;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InputEvent"/> class.
|
||||
/// </summary>
|
||||
@@ -51,10 +72,26 @@ namespace FlaxEngine
|
||||
Input.ActionTriggered -= Handler;
|
||||
}
|
||||
|
||||
private void Handler(string name)
|
||||
private void Handler(string name, InputActionState state)
|
||||
{
|
||||
if (string.Equals(name, Name, StringComparison.OrdinalIgnoreCase))
|
||||
if (!string.Equals(name, Name, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
switch (state)
|
||||
{
|
||||
case InputActionState.None: break;
|
||||
case InputActionState.Waiting: break;
|
||||
case InputActionState.Pressing:
|
||||
Pressing?.Invoke();
|
||||
break;
|
||||
case InputActionState.Press:
|
||||
Triggered?.Invoke();
|
||||
Pressed?.Invoke();
|
||||
break;
|
||||
case InputActionState.Release:
|
||||
Released?.Invoke();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user