/// <summary> /// Registers the provided virtual button /// </summary> /// <param name="virtualButton">Virtual button to register</param> public static void RegisterVirtualButton(VirtualButton virtualButton) { if (!Instance._virtualButtonsDictionary.ContainsKey(virtualButton.Name)) { Instance._virtualButtonsDictionary[virtualButton.Name] = new List<VirtualButton>(); } Instance._virtualButtonsDictionary[virtualButton.Name].Add(virtualButton); }
/// <summary> /// Unregisters the provided virtual button /// </summary> /// <param name="virtualButton">Virtual button to unregister</param> public static void UnregisterVirtualButton(VirtualButton virtualButton) { if (Instance._virtualButtonsDictionary.ContainsKey(virtualButton.Name)) { if (!Instance._virtualButtonsDictionary[virtualButton.Name].Remove(virtualButton)) { Debug.LogError("Requested button axis exists, but there's no such virtual button that you're trying to unregister"); } } else { Debug.LogError("Trying to unregister a button that was never registered"); } }
/// <summary> /// It's pretty simple here /// When we enable, we register our button in the input system /// </summary> private void OnEnable() { _virtualButton = _virtualButton ?? new VirtualButton(ButtonName); XInput.RegisterVirtualButton(_virtualButton); }