private void AddDefaultMappingsForNewActions(Player player, List <SavedControllerMapData> savedData, ControllerType controllerType, int controllerId) { if (player == null || savedData == null) { return; } // Check for new Actions added to the default mappings that didn't exist when the Controller Map was saved List <int> allActionIds = GetAllActionIds(); for (int i = 0; i < savedData.Count; i++) { SavedControllerMapData data = savedData[i]; if (data == null) { continue; } if (data.knownActionIds == null || data.knownActionIds.Count == 0) { continue; } // Create a map from the Xml so we can get information ControllerMap mapFromXml = ControllerMap.CreateFromXml(controllerType, savedData[i].xml); if (mapFromXml == null) { continue; } // Load the map that was added to the Player ControllerMap mapInPlayer = player.controllers.maps.GetMap(controllerType, controllerId, mapFromXml.categoryId, mapFromXml.layoutId); if (mapInPlayer == null) { continue; } // Load default map for comparison ControllerMap defaultMap = ReInput.mapping.GetControllerMapInstance(ReInput.controllers.GetController(controllerType, controllerId), mapFromXml.categoryId, mapFromXml.layoutId); if (defaultMap == null) { continue; } // Find any new Action ids that didn't exist when the Controller Map was saved List <int> unknownActionIds = new List <int>(); foreach (int id in allActionIds) { if (data.knownActionIds.Contains(id)) { continue; } unknownActionIds.Add(id); } if (unknownActionIds.Count == 0) { continue; // no new Action ids } // Add all mappings in the default map for previously unknown Action ids foreach (ActionElementMap aem in defaultMap.AllMaps) { if (!unknownActionIds.Contains(aem.actionId)) { continue; } // Skip this ActionElementMap if there's a conflict within the loaded map if (mapInPlayer.DoesElementAssignmentConflict(aem)) { continue; } // Create an assignment ElementAssignment assignment = new ElementAssignment( controllerType, aem.elementType, aem.elementIdentifierId, aem.axisRange, aem.keyCode, aem.modifierKeyFlags, aem.actionId, aem.axisContribution, aem.invert ); // Assign it mapInPlayer.CreateElementMap(assignment); } } }
private int LoadControllerMaps(int playerId, ControllerType controllerType, int controllerId) { int count = 0; Player player = ReInput.players.GetPlayer(playerId); if (player == null) { return(count); } Controller controller = ReInput.controllers.GetController(controllerType, controllerId); if (controller == null) { return(count); } // Load the controller maps first and make sure we have them to load List <SavedControllerMapData> savedData = GetAllControllerMapsXml(player, true, controller); if (savedData.Count == 0) { return(count); } // Load Joystick Maps count += player.controllers.maps.AddMapsFromXml(controllerType, controllerId, SavedControllerMapData.GetXmlStringList(savedData)); // load controller maps // Analyze the saved data and compare to defaults to find bindings for newly created Actions AddDefaultMappingsForNewActions(player, savedData, controllerType, controllerId); return(count); }