/// <summary> /// Changes key in runtime to access listener in all dictionaries. /// </summary> /// <param name="listener">Input listener to be changed</param> /// <param name="from">Old key</param> /// <param name="to">New key</param> public void ChangeKey(string listener, KeyCode from, KeyCode to) { InputListener temp; Pressed.TryGetValue(from, out temp); if (temp != null && temp.Name == listener && !Pressed.ContainsKey(to)) { Pressed.Remove(from); Pressed.Add(to, temp); } JustPressed.TryGetValue(from, out temp); if (temp != null && temp.Name == listener && !JustPressed.ContainsKey(to)) { JustPressed.Remove(from); JustPressed.Add(to, temp); } JustReleased.TryGetValue(from, out temp); if (temp != null && temp.Name == listener && !JustReleased.ContainsKey(to)) { JustReleased.Remove(from); JustReleased.Add(to, temp); } SaveHandler(); }
public Func <RegisterA> WasPressed(U8 buttons) => () => JustPressed.And(buttons);
/// <summary> /// Fills dictionaries with InputListeners from the saving file. /// If file doesn't exist - with default data filled from the Editor. /// <remark> Called from InputManager Awake() </remark> /// </summary> public bool Init() { if (_inited) { return(false); } List <InputListener> JustPressedSource; List <InputListener> PressedSource; List <InputListener> JustReleasedSource; var savedHandler = InputSaver.ReadHandler(this.Name); if (savedHandler != null) { JustPressedSource = savedHandler.JustPressed; PressedSource = savedHandler.Pressed; JustReleasedSource = savedHandler.JustReleased; _axes = savedHandler.Axes; } else { JustPressedSource = JustPressedTemplate; PressedSource = PressedTemplate; JustReleasedSource = JustReleasedTemplate; } foreach (var l in JustPressedSource) { if (l.Positive != KeyCode.None) { JustPressed.Add(l.Positive, l); } if (l.Alternative != KeyCode.None) { JustPressed.Add(l.Alternative, l); } if (!AllListeners.ContainsKey(l.Name)) { AllListeners.Add(l.Name, l); } } foreach (var l in PressedSource) { if (l.Positive != KeyCode.None) { Pressed.Add(l.Positive, l); } if (l.Alternative != KeyCode.None) { Pressed.Add(l.Alternative, l); } if (!AllListeners.ContainsKey(l.Name)) { AllListeners.Add(l.Name, l); } } foreach (var l in JustReleasedSource) { if (l.Positive != KeyCode.None) { JustReleased.Add(l.Positive, l); } if (l.Alternative != KeyCode.None) { JustReleased.Add(l.Alternative, l); } if (!AllListeners.ContainsKey(l.Name)) { AllListeners.Add(l.Name, l); } } _inited = true; if (savedHandler == null) { SaveHandler(); } return(true); }
public RegisterA Pressed(U8 buttons) => JustPressed.And(buttons);