/// <summary> /// Set a bindings primary key /// </summary> public void SetKeySecondary(string KeyName, KeyAxis keyAxis) { HardKey key = Find(KeyName); key.Secondary = keyAxis; SaveXML(); }
/// <summary> /// Set the binding for a key. /// </summary> public static void SetKey(string KeyName, KeyAxis keyAxis, bool UseThePrimaryKey = true) { if (UseThePrimaryKey) { hardManager.Current().SetKeyPrimary(KeyName, keyAxis); } else { hardManager.Current().SetKeySecondary(KeyName, keyAxis); } }
float GetAxis(KeyAxis axis) { switch (axis) { default: return(0); case KeyAxis.MouseX: return(Input.GetAxisRaw("Mouse X")); case KeyAxis.MouseY: return(Input.GetAxisRaw("Mouse Y")); case KeyAxis.ScrollWheel: return(Input.mouseScrollDelta.y); case KeyAxis.ScrollWheelUp: return(Mathf.Clamp(Input.mouseScrollDelta.y, 0, 10)); case KeyAxis.ScrollWheelDown: return(Mathf.Clamp(0 - Input.mouseScrollDelta.y, 0, 10)); } }
public static void BindAxisInput(GameAxisID id, KeyCode positiveKey, KeyCode negativeKey) { axes[id] = new KeyAxis(positiveKey, negativeKey); PlayerPrefs.SetInt(savePref + id + "_Positive", (int)positiveKey); PlayerPrefs.SetInt(savePref + id + "_Negative", (int)negativeKey); }
internal static void Load(MachineInfo machineInfo) { try { AxisManager.MachineAxes.Clear(); ControlManager.Blocks.Clear(); // read mod version if (!machineInfo.MachineData.HasKey("ac-version")) { return; } var version = new Version(machineInfo.MachineData.ReadString("ac-version").TrimStart('v')); // version alert if (version < Assembly.GetExecutingAssembly().GetName().Version) { Debug.Log("[ACM]: " + machineInfo.Name + " was saved with mod version " + version + ".\n\tIt may not be compatible with some newer features."); } // return if no input axes are present if (!machineInfo.MachineData.HasKey("ac-axislist")) { return; } var axes = machineInfo.MachineData.ReadStringArray("ac-axislist"); // load all axes foreach (var name in axes) { InputAxis axis = null; if (!machineInfo.MachineData.HasKey("axis-" + name + "-type")) { continue; } var type = machineInfo.MachineData.ReadString("axis-" + name + "-type"); if (type == AxisType.Chain.ToString()) { axis = new ChainAxis(name); } if (type == AxisType.Controller.ToString()) { axis = new ControllerAxis(name); } if (type == AxisType.Custom.ToString()) { axis = new CustomAxis(name); } if (type == AxisType.Standard.ToString() || // backwards compatibility type == AxisType.Inertial.ToString() || // backwards compatibility type == AxisType.Key.ToString()) { axis = new KeyAxis(name); } if (type == AxisType.Mouse.ToString()) { axis = new MouseAxis(name); } if (axis != null) { axis?.Load(machineInfo); AxisManager.AddMachineAxis(axis); } } // refresh chain axis links foreach (var entry in AxisManager.MachineAxes) { if (entry.Value.Type == AxisType.Chain) { (entry.Value as ChainAxis).RefreshLinks(); } } // resolve from foreign controllers AxisManager.ResolveMachineAxes(); // load all controls foreach (BlockInfo blockInfo in machineInfo.Blocks) { if (!blockInfo.BlockData.HasKey("ac-controllist")) { continue; } var control_list = ControlManager.GetBlockControls(blockInfo.ID, blockInfo.Guid); var control_names = blockInfo.BlockData.ReadStringArray("ac-controllist"); foreach (string name in control_names) { foreach (Control c in control_list) { if (name == c.Name) { c.Load(blockInfo); } } } } ACM.Instance.LoadedMachine = true; } catch (Exception e) { Debug.Log("[ACM]: Error loading machine's controls:"); Debug.LogException(e); } }
/// <summary> /// Returns a prettier, formatted string for display in game to show what button a key is bound to. /// </summary> public static string MakeKeycodePretty(string KeyName, bool GetPrimary = true) { HardKey key = hardManager.Current().Find(KeyName); string name = key.Primary.ToString(); KeyCode keycode = key.PrimaryKey; KeyController keycontroller = key.PrimaryCont; KeyAxis keyaxis = key.PrimaryAxis; if (GetPrimary) { name = key.Primary.ToString(); } else { name = key.Secondary.ToString(); keycode = key.SecondaryKey; keycontroller = key.SecondaryCont; keyaxis = key.SecondaryAxis; } if (key.CheckPrimary(typeof(KeyCode)) && GetPrimary || key.CheckSecondary(typeof(KeyCode)) && !GetPrimary) { if (name.Contains("Alpha")) { return(name.Replace("Alpha", "")); } else if (name.Contains("Keypad")) { return(name.Replace("Keypad", "Keypad ")); } else if (name.Contains("Left")) { return(name.Replace("Left", "Left ")); } else if (name.Contains("Right")) { return(name.Replace("Right", "Right ")); } else if (name.Contains("Up")) { return(name.Replace("Up", "Up ")); } else if (name.Contains("Down")) { return(name.Replace("Down", "Down ")); } else if (name.Contains("Mouse0")) { return("Left Mouse"); } else if (name.Contains("Mouse1")) { return("Right Mouse"); } else if (name.Contains("Mouse2")) { return("Middle Mouse"); } else if (name.Contains("Mouse")) { return("Mouse " + name.Replace("Mouse", "")); } } else if (key.CheckPrimary(typeof(KeyAxis)) && GetPrimary || key.CheckSecondary(typeof(KeyAxis)) && !GetPrimary) { if (keyaxis == KeyAxis.MouseX) { return("Mouse X"); } else if (keyaxis == KeyAxis.MouseY) { return("Mouse Y"); } else if (keyaxis == KeyAxis.ScrollWheel) { return("Scroll Wheel"); } else if (keyaxis == KeyAxis.ScrollWheelDown) { return("Scroll Wheel Down"); } else if (keyaxis == KeyAxis.ScrollWheelUp) { return("Scroll Wheel Up"); } } else if (key.CheckPrimary(typeof(KeyController)) && GetPrimary || key.CheckSecondary(typeof(KeyController)) && !GetPrimary) { switch (keycontroller) { case KeyController.LeftStickX: return("Left Stick X"); case KeyController.LeftStickY: return("Left Stick Y"); case KeyController.RightStickX: return("Right Stick X"); case KeyController.RightStickY: return("Right Stick Y"); case KeyController.DPadX: return("D-PAD X"); case KeyController.DPadY: return("D-PAD Y"); case KeyController.LeftTrigger: return("Left Trigger"); case KeyController.RightTrigger: return("Right Trigger"); case KeyController.LeftStickUp: return("Left Stick Up"); case KeyController.LeftStickDown: return("Left Stick Down"); case KeyController.LeftStickLeft: return("Left Stick Left"); case KeyController.LeftStickRight: return("Left Stick Right"); case KeyController.RightStickUp: return("Right Stick Up"); case KeyController.RightStickDown: return("Right Stick Down"); case KeyController.RightStickLeft: return("Right Stick Left"); case KeyController.RightStickRight: return("Right Stick Right"); case KeyController.DPadUp: return("D-PAD Up"); case KeyController.DPadDown: return("D-PAD Down"); case KeyController.DPadLeft: return("D-PAD Left"); case KeyController.DPadRight: return("D-PAD Right"); } } return(name); }
public float GetAxis(KeyAxis axis, bool raw = true) { return(raw ? UnityEngine.Input.GetAxisRaw(KEY_AXIS[(int)axis]) : UnityEngine.Input.GetAxis(KEY_AXIS[(int)axis])); }
internal static void Load() { try { // load mod configuration ACM.Instance.ModEnabled = spaar.ModLoader.Configuration.GetBool("acm-enabled", true); ACM.Instance.ModUpdaterEnabled = spaar.ModLoader.Configuration.GetBool("mod-updater-enabled", true); ACM.Instance.DBUpdaterEnabled = spaar.ModLoader.Configuration.GetBool("db-updater-enabled", true); // read input axes int count = spaar.ModLoader.Configuration.GetInt("number-of-axes", 0); for (int i = 0; i < count; i++) { string name = spaar.ModLoader.Configuration.GetString("axis-" + i + "-name", null); InputAxis axis = null; if (name != null) { var type = spaar.ModLoader.Configuration.GetString("axis-" + name + "-type", null); if (type == AxisType.Chain.ToString()) { axis = new ChainAxis(name); } if (type == AxisType.Controller.ToString()) { axis = new ControllerAxis(name); } if (type == AxisType.Custom.ToString()) { axis = new CustomAxis(name); } if (type == AxisType.Standard.ToString() || // backwards compatibility type == AxisType.Inertial.ToString() || // backwards compatibility type == AxisType.Key.ToString()) { axis = new KeyAxis(name); } if (type == AxisType.Mouse.ToString()) { axis = new MouseAxis(name); } } if (axis != null) { axis?.Load(); AxisManager.AddLocalAxis(axis); } } // refresh chain axis links foreach (var entry in AxisManager.LocalAxes) { if (entry.Value.Type == AxisType.Chain) { (entry.Value as ChainAxis).RefreshLinks(); } } } catch (Exception e) { Debug.Log("[ACM]: Error loading saved axes:"); Debug.LogException(e); } }