/// <summary> /// Registers the provided virtual axis /// </summary> /// <param name="virtualAxis">Virtual axis to register</param> public static void RegisterVirtualAxis(VirtualAxis virtualAxis) { // If it's the first such virtual axis, create a new list for that axis name if (!Instance._virtualAxisDictionary.ContainsKey(virtualAxis.Name)) { Instance._virtualAxisDictionary[virtualAxis.Name] = new List<VirtualAxis>(); } Instance._virtualAxisDictionary[virtualAxis.Name].Add(virtualAxis); }
/// <summary> /// Unregisters the provided virtual axis /// </summary> /// <param name="virtualAxis">Virtual axis to unregister</param> public static void UnregisterVirtualAxis(VirtualAxis virtualAxis) { // If it's the first such virtual axis, create a new list for that axis name if (Instance._virtualAxisDictionary.ContainsKey(virtualAxis.Name)) { if (!Instance._virtualAxisDictionary[virtualAxis.Name].Remove(virtualAxis)) { Debug.LogError("Requested axis " + virtualAxis.Name + " exists, but there's no such virtual axis that you're trying to unregister"); } } else { Debug.LogError("Trying to unregister an axis " + virtualAxis.Name + " that was never registered"); } }
private void OnEnable() { // When we enable, we get our virtual axis HorizintalAxis = HorizintalAxis ?? new VirtualAxis(HorizontalAxisName); VerticalAxis = VerticalAxis ?? new VirtualAxis(VerticalAxisName); // And register them in our input system XInput.RegisterVirtualAxis(HorizintalAxis); XInput.RegisterVirtualAxis(VerticalAxis); }