public static string GetSteamControllerInputType(InputAction action) { if (action == null) { throw new ArgumentNullException("action"); } // Make sure we have an expected control layout. var expectedControlLayout = action.expectedControlLayout; if (string.IsNullOrEmpty(expectedControlLayout)) { throw new Exception(string.Format( "Cannot determine Steam input type for action '{0}' that has no associated expected control layout", action)); } // Try to fetch the layout. var layout = EditorInputControlLayoutCache.TryGetLayout(expectedControlLayout); if (layout == null) { throw new Exception(string.Format( "Cannot determine Steam input type for action '{0}'; cannot find layout '{1}'", action, expectedControlLayout)); } // Map our supported control types. var controlType = layout.type; if (typeof(ButtonControl).IsAssignableFrom(controlType)) { return("Button"); } if (typeof(InputControl <float>).IsAssignableFrom(controlType)) { return("AnalogTrigger"); } if (typeof(Vector2Control).IsAssignableFrom(controlType)) { return("StickPadGyro"); } // Everything else throws. throw new Exception(string.Format( "Cannot determine Steam input type for action '{0}'; layout '{1}' with control type '{2}' has no known representation in the Steam controller API", action, expectedControlLayout, controlType.Name)); }
private static void ConvertInputActionToVDF(InputAction action, StringBuilder builder, Dictionary <string, string> localizationStrings) { builder.Append("\t\t\t\t\""); builder.Append(action.name); var mapIdentifier = CSharpCodeHelpers.MakeIdentifier(action.actionMap.name); var actionIdentifier = CSharpCodeHelpers.MakeIdentifier(action.name); var titleId = "Action_" + mapIdentifier + "_" + actionIdentifier; localizationStrings[titleId] = action.name; // StickPadGyros are objects. Everything else is just strings. var inputType = GetSteamControllerInputType(action); if (inputType == "StickPadGyro") { builder.Append("\"\n"); builder.Append("\t\t\t\t{\n"); // Title. builder.Append("\t\t\t\t\t\"title\"\t\"#"); builder.Append(titleId); builder.Append("\"\n"); // Decide on "input_mode". Assume "absolute_mouse" by default and take // anything built on StickControl as "joystick_move". var inputMode = "absolute_mouse"; var controlType = EditorInputControlLayoutCache.TryGetLayout(action.expectedControlType).type; if (typeof(StickControl).IsAssignableFrom(controlType)) { inputMode = "joystick_move"; } builder.Append("\t\t\t\t\t\"input_mode\"\t\""); builder.Append(inputMode); builder.Append("\"\n"); builder.Append("\t\t\t\t}\n"); } else { builder.Append("\"\t\""); builder.Append(titleId); builder.Append("\"\n"); } }