/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Input
{
using UnityEngine;
///
/// Uses Unity's input system to detect input related actions.
///
public class StandaloneInput : InputBase
{
///
/// Returns if the button is true with the specified ButtonAction.
///
/// The name of the button.
/// The type of action to check.
/// The status of the action.
public override bool GetButton(string name, ButtonAction action)
{
#if UNITY_EDITOR
try {
switch (action) {
case ButtonAction.GetButton:
return UnityEngine.Input.GetButton(name);
case ButtonAction.GetButtonDown:
return UnityEngine.Input.GetButtonDown(name);
case ButtonAction.GetButtonUp:
return UnityEngine.Input.GetButtonUp(name);
}
}
catch (System.Exception /*e*/) {
Debug.LogError("Button \"" + name + "\" is not setup. Please create a button mapping within the Unity Input Manager.");
}
#else
switch (action) {
case ButtonAction.GetButton:
return UnityEngine.Input.GetButton(name);
case ButtonAction.GetButtonDown:
return UnityEngine.Input.GetButtonDown(name);
case ButtonAction.GetButtonUp:
return UnityEngine.Input.GetButtonUp(name);
}
#endif
return false;
}
///
/// Return the value of the axis with the specified name.
///
/// The name of the axis.
/// The value of the axis.
public override float GetAxis(string name)
{
#if UNITY_EDITOR
try {
return UnityEngine.Input.GetAxis(name);
}
catch (UnityException /*e*/) {
Debug.LogError("Axis \"" + name + "\" is not setup. Please create an axis mapping within the Unity Input Manager.");
}
return 0;
#else
return UnityEngine.Input.GetAxis(name);
#endif
}
///
/// Return the value of theraw axis with the specified name.
///
/// The name of the axis.
/// The value of the raw axis.
public override float GetAxisRaw(string name)
{
#if UNITY_EDITOR
try {
return UnityEngine.Input.GetAxisRaw(name);
} catch (UnityException /*e*/) {
Debug.LogError("Axis \"" + name + "\" is not setup. Please create an axis mapping within the Unity Input Manager.");
}
return 0;
#else
return UnityEngine.Input.GetAxisRaw(name);
#endif
}
}
}