//#define GET_AXIS_USE_MOVE_TOWARDS using SimpleInputNamespace; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SimpleInput : MonoBehaviour { private enum InputState { None, Pressed, Held, Released }; #region Helper Classes private class Axis { public readonly string name; public readonly List inputs; public float value = 0f; public float valueRaw = 0f; public Axis( string axis ) { name = axis; inputs = new List(); } } private class Button { public readonly string button; public readonly List inputs; public InputState state = InputState.None; public Button( string button ) { this.button = button; inputs = new List(); } } private class MouseButton { public readonly int button; public readonly List inputs; public InputState state = InputState.None; public MouseButton( int button ) { this.button = button; inputs = new List(); } } private class Key { public readonly KeyCode key; public readonly List inputs; public InputState state = InputState.None; public Key( KeyCode key ) { this.key = key; inputs = new List(); } } [System.Serializable] public class AxisInput : BaseInput { public AxisInput() : base() { } public AxisInput( string key ) : base( key ) { } public override bool IsKeyValid() { return !string.IsNullOrEmpty( Key ); } protected override bool KeysEqual( string key1, string key2 ) { return key1 == key2; } protected override void RegisterInput() { RegisterAxis( this ); } protected override void UnregisterInput() { UnregisterAxis( this ); } } [System.Serializable] public class ButtonInput : BaseInput { public ButtonInput() : base() { } public ButtonInput( string key ) : base( key ) { } public override bool IsKeyValid() { return !string.IsNullOrEmpty( Key ); } protected override bool KeysEqual( string key1, string key2 ) { return key1 == key2; } protected override void RegisterInput() { RegisterButton( this ); } protected override void UnregisterInput() { UnregisterButton( this ); } } [System.Serializable] public class MouseButtonInput : BaseInput { public MouseButtonInput() : base() { } public MouseButtonInput( int key ) : base( key ) { } protected override bool KeysEqual( int key1, int key2 ) { return key1 == key2; } protected override void RegisterInput() { RegisterMouseButton( this ); } protected override void UnregisterInput() { UnregisterMouseButton( this ); } } [System.Serializable] public class KeyInput : BaseInput { public KeyInput() : base() { } public KeyInput( KeyCode key ) : base( key ) { } protected override bool KeysEqual( KeyCode key1, KeyCode key2 ) { return key1 == key2; } protected override void RegisterInput() { RegisterKey( this ); } protected override void UnregisterInput() { UnregisterKey( this ); } } #endregion #if GET_AXIS_USE_MOVE_TOWARDS /// /// Speed to move SimpleInput.GetAxis' value towards SimpleInput.GetAxisRaw's value in units per second /// public static float GetAxisSensitivity = 3f; #else /// /// Lerp modifier to move SimpleInput.GetAxis' value towards SimpleInput.GetAxisRaw's value /// public static float GetAxisSensitivity = 20f; #endif /// /// When SimpleInput.GetAxisRaw's value is 0f and SimpleInput.GetAxis' value is within this range, SimpleInput.GetAxis' value will snap to 0f /// public static float GetAxisDeadZone = 0.025f; /// /// If set to true and the values of SimpleInput.GetAxis and SimpleInput.GetAxisRaw have different signs, SimpleInput.GetAxis will jump to 0f and continue from there /// public static bool GetAxisSnapValue = true; /// /// Sets whether or not Time.timeScale should affect SimpleInput.GetAxis' sensitivity /// public static bool GetAxisTimeScaleDependent = true; private static bool m_trackUnityInput = true; public static bool TrackUnityInput { get { return m_trackUnityInput; } set { if( m_trackUnityInput != value ) { m_trackUnityInput = value; if( !m_trackUnityInput ) { for( int i = 0; i < trackedUnityAxes.Count; i++ ) trackedUnityAxes[i].ResetValue(); for( int i = 0; i < trackedUnityButtons.Count; i++ ) trackedUnityButtons[i].ResetValue(); for( int i = 0; i < trackedUnityMouseButtons.Count; i++ ) trackedUnityMouseButtons[i].ResetValue(); } } } } // Singleton instance private static SimpleInput instance; private static Dictionary axes = new Dictionary(); private static List axesList = new List(); private static List trackedUnityAxes = new List(); private static List trackedTemporaryAxes = new List(); private static Dictionary buttons = new Dictionary(); private static List