51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
// GameInputBinding.cs
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(fileName = "InputBinding", menuName = "RiftMayhem/Input/Input Binding")]
|
|
public class GameInputBinding : ScriptableObject
|
|
{
|
|
public string bindingName;
|
|
public KeyCode keyboardKey;
|
|
public string gamepadButton;
|
|
public string gamepadAxis;
|
|
public bool isAxis;
|
|
public float axisDeadzone = 0.2f;
|
|
|
|
public float GetValue()
|
|
{
|
|
if (isAxis && !string.IsNullOrEmpty(gamepadAxis))
|
|
{
|
|
float axisValue = Input.GetAxis(gamepadAxis);
|
|
return Mathf.Abs(axisValue) > axisDeadzone ? axisValue : 0f;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(bindingName) && Input.GetButton(bindingName))
|
|
return 1f;
|
|
|
|
return Input.GetKey(keyboardKey) ? 1f : 0f;
|
|
}
|
|
|
|
public bool GetButtonDown()
|
|
{
|
|
if (!string.IsNullOrEmpty(bindingName) && Input.GetButtonDown(bindingName))
|
|
return true;
|
|
|
|
return Input.GetKeyDown(keyboardKey);
|
|
}
|
|
|
|
public bool GetButton()
|
|
{
|
|
if (!string.IsNullOrEmpty(bindingName) && Input.GetButton(bindingName))
|
|
return true;
|
|
|
|
return Input.GetKey(keyboardKey);
|
|
}
|
|
|
|
public bool GetButtonUp()
|
|
{
|
|
if (!string.IsNullOrEmpty(bindingName) && Input.GetButtonUp(bindingName))
|
|
return true;
|
|
|
|
return Input.GetKeyUp(keyboardKey);
|
|
}
|
|
} |