public InputSource(InputSourceType sourceType, Interactable interactable) { SourceType = sourceType; Interactable = interactable; }
public static string Interactable2String(LanguageTable languageTable, InputSourceType sourceType, Interactable interactable, Maybe <UnityInputDeviceProfile> currentControllerProfile) { var l = languageTable.Table; if (interactable is Interactable.Key) { var key = ((Interactable.Key)interactable).Id; if (key == KeyCode.UpArrow) { return("↑"); } else if (key == KeyCode.DownArrow) { return("↓"); } else if (key == KeyCode.LeftArrow) { return("←"); } else if (key == KeyCode.RightArrow) { return("→"); } else if (key == KeyCode.Return) { return("Enter"); } else { return(EnumUtils.ToPrettyString(key)); } } else if (interactable is Interactable.MouseButton) { var mouseButtonId = ((Interactable.MouseButton)interactable).Id; if (mouseButtonId == MouseButtonId.Left) { return(l["left_mouse_button"]); } else if (mouseButtonId == MouseButtonId.Right) { return(l["right_mouse_button"]); } else if (mouseButtonId == MouseButtonId.Middle) { return(l["middle_mouse_button"]); } else { return(l["mouse_button_n"].Replace("$n", ((int)mouseButtonId).ToString())); } } else if (interactable is Interactable.Button) { var buttonId = ((Interactable.Button)interactable).Id; string customMappingStr = null; // TODO Factor into a function if (currentControllerProfile.IsJust) { var inputSources = UnityInputDeviceProfiles.InputSources[currentControllerProfile.Value.GetType()]; InputControlMapping inputControlMapping; if (inputSources.TryGetValue(new InputControlSource.Button(buttonId), out inputControlMapping)) { customMappingStr = inputControlMapping.Handle; } } if (customMappingStr == null) { return(l[(sourceType.Peripheral.ToString().ToLower() + "_button_n")].Replace("$n", buttonId.ToString())); } return(customMappingStr); } else if (interactable is Interactable.JoystickAxis) { var axisId = ((Interactable.JoystickAxis)interactable).Id; string customMappingStr = null; // TODO Factor into a function if (currentControllerProfile.IsJust) { var inputSources = UnityInputDeviceProfiles.InputSources[currentControllerProfile.Value.GetType()]; InputControlMapping inputControlMapping; if (inputSources.TryGetValue(new InputControlSource.Axis(axisId), out inputControlMapping)) { customMappingStr = inputControlMapping.Handle; } } if (customMappingStr == null) { return(l["joystick_axis_n"].Replace("$n", axisId.ToString())); } return(customMappingStr); } else if (interactable is Interactable.XInputAxis) { var axisId = ((Interactable.XInputAxis)interactable).Id; return(EnumUtils.ToPrettyString(axisId)); } else if (interactable is Interactable.XInputButton) { var buttonId = ((Interactable.XInputButton)interactable).Id; return(EnumUtils.ToPrettyString(buttonId)); } else if (interactable is Interactable.MouseAxis) { var axisId = ((Interactable.MouseAxis)interactable).Id; return(l["mouse_axis_n"].Replace("$n", axisId.ToString())); } else if (interactable is Interactable.PolarizedAxis) { var polarizedInteractable = (Interactable.PolarizedAxis)interactable; // TODO Factor into a function if (currentControllerProfile.IsJust && polarizedInteractable.Axis is Interactable.JoystickAxis) { var joystickAxisId = polarizedInteractable.Axis as Interactable.JoystickAxis; var inputSources = UnityInputDeviceProfiles.InputSources[currentControllerProfile.Value.GetType()]; InputControlMapping inputControlMapping; if (inputSources.TryGetValue(new InputControlSource.Axis(joystickAxisId.Id), out inputControlMapping)) { var customMappingStr = inputControlMapping.Handle; var polarity = inputControlMapping.Invert ? polarizedInteractable.Polarity.Invert() : polarizedInteractable.Polarity; if (polarity == AxisPolarity.Positive) { return(customMappingStr .ReplaceLast("Y", "Up") .ReplaceLast("X", "Right")); } return(customMappingStr .ReplaceLast("Y", "Down") .ReplaceLast("X", "Left")); } } return(Interactable2String(languageTable, sourceType, polarizedInteractable.Axis, currentControllerProfile) + (polarizedInteractable.Polarity == AxisPolarity.Positive ? "+" : "-")); } else { throw new Exception("Unknown interactable type " + interactable.GetType()); } }
public InputSource(Peripheral peripheral, InputType inputType, Interactable interactable) { SourceType = new InputSourceType(peripheral, inputType); Interactable = interactable; }