2019-07-21 22:08:23 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Utilities
|
|
|
|
{
|
|
|
|
|
|
|
|
public class CustomInput : MonoBehaviour
|
|
|
|
{
|
|
|
|
public static CustomInput Instance { get; private set; }
|
|
|
|
|
|
|
|
public bool IsActive { get; set; } = false;
|
|
|
|
|
|
|
|
Dictionary<string,float> axes = new Dictionary<string, float>();
|
|
|
|
Dictionary<string,bool> buttons = new Dictionary<string, bool>();
|
2019-07-22 17:16:31 +00:00
|
|
|
Dictionary<string,bool> buttonsDown = new Dictionary<string, bool>();
|
|
|
|
Dictionary<KeyCode,bool> keysDown = new Dictionary<KeyCode, bool>();
|
2019-07-21 22:08:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public float GetAxis(string name){
|
|
|
|
if (!this.IsActive)
|
|
|
|
return Input.GetAxis(name);
|
|
|
|
float value = 0;
|
2019-07-22 15:28:58 +00:00
|
|
|
if (axes.TryGetValue (name, out value))
|
|
|
|
return value;
|
|
|
|
return Input.GetAxis(name);
|
2019-07-21 22:08:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 17:16:31 +00:00
|
|
|
public float GetAxisRaw(string name){
|
|
|
|
if (!this.IsActive)
|
|
|
|
return Input.GetAxisRaw(name);
|
|
|
|
float value = 0;
|
|
|
|
if (axes.TryGetValue (name, out value))
|
|
|
|
return value;
|
|
|
|
return Input.GetAxisRaw(name);
|
|
|
|
}
|
|
|
|
|
2019-07-21 22:08:23 +00:00
|
|
|
public void SetAxis(string name, float value){
|
|
|
|
axes [name] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetButton(string name){
|
|
|
|
if (!this.IsActive)
|
|
|
|
return Input.GetButton(name);
|
|
|
|
bool value = false;
|
2019-07-22 15:28:58 +00:00
|
|
|
if (buttons.TryGetValue (name, out value))
|
|
|
|
return value;
|
|
|
|
return Input.GetButton(name);
|
2019-07-21 22:08:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 17:16:31 +00:00
|
|
|
public bool GetButtonDown(string name){
|
|
|
|
if (!this.IsActive)
|
|
|
|
return Input.GetButtonDown(name);
|
|
|
|
bool value = false;
|
|
|
|
if (buttonsDown.TryGetValue (name, out value))
|
|
|
|
return value;
|
|
|
|
return Input.GetButtonDown(name);
|
|
|
|
}
|
|
|
|
|
2019-07-21 22:08:23 +00:00
|
|
|
public void SetButton(string name, bool pressed){
|
|
|
|
buttons [name] = pressed;
|
|
|
|
}
|
|
|
|
|
2019-07-22 17:16:31 +00:00
|
|
|
public void SetButtonDown(string name, bool pressed){
|
|
|
|
buttonsDown [name] = pressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetKeyDown(KeyCode keyCode){
|
|
|
|
if (!this.IsActive)
|
|
|
|
return Input.GetKeyDown(keyCode);
|
|
|
|
bool value = false;
|
|
|
|
if (keysDown.TryGetValue (keyCode, out value))
|
|
|
|
return value;
|
|
|
|
return Input.GetKeyDown(keyCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetKeyDown(KeyCode keyCode, bool pressed)
|
|
|
|
{
|
|
|
|
keysDown [keyCode] = pressed;
|
|
|
|
}
|
|
|
|
|
2019-07-21 22:08:23 +00:00
|
|
|
public void ResetAllInput()
|
|
|
|
{
|
|
|
|
axes.Clear();
|
|
|
|
buttons.Clear();
|
2019-07-22 17:16:31 +00:00
|
|
|
buttonsDown.Clear();
|
2019-07-21 22:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|