49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Invector
|
|
{
|
|
public static class vMobileInputActions
|
|
{
|
|
private sealed class State
|
|
{
|
|
public bool pressed;
|
|
public int down;
|
|
public int up;
|
|
public int readDown;
|
|
public int readUp;
|
|
}
|
|
|
|
private static readonly Dictionary<string, State> states = new Dictionary<string, State>();
|
|
|
|
public static void SetButton(string actionName, bool pressed)
|
|
{
|
|
if (!states.TryGetValue(actionName, out var state))
|
|
{
|
|
state = new State();
|
|
states.Add(actionName, state);
|
|
}
|
|
|
|
if (state.pressed == pressed) return;
|
|
state.pressed = pressed;
|
|
if (pressed) state.down++;
|
|
else state.up++;
|
|
}
|
|
|
|
public static bool GetButton(string actionName) => states.TryGetValue(actionName, out var state) && state.pressed;
|
|
|
|
public static bool GetButtonDown(string actionName)
|
|
{
|
|
if (!states.TryGetValue(actionName, out var state) || state.down == state.readDown) return false;
|
|
state.readDown = state.down;
|
|
return true;
|
|
}
|
|
|
|
public static bool GetButtonUp(string actionName)
|
|
{
|
|
if (!states.TryGetValue(actionName, out var state) || state.up == state.readUp) return false;
|
|
state.readUp = state.up;
|
|
return true;
|
|
}
|
|
}
|
|
}
|