private void AddDefaultMappingsForNewActions(Player player, List <UserDataStore_PlayerPrefs.SavedControllerMapData> savedData, ControllerType controllerType, int controllerId) { if (player == null || savedData == null) { return; } List <int> allActionIds = this.GetAllActionIds(); for (int i = 0; i < savedData.Count; i++) { UserDataStore_PlayerPrefs.SavedControllerMapData savedControllerMapData = savedData[i]; if (savedControllerMapData != null) { if (savedControllerMapData.knownActionIds != null && savedControllerMapData.knownActionIds.Count != 0) { ControllerMap controllerMap = ControllerMap.CreateFromXml(controllerType, savedData[i].xml); if (controllerMap != null) { ControllerMap map = player.controllers.maps.GetMap(controllerType, controllerId, controllerMap.categoryId, controllerMap.layoutId); if (map != null) { ControllerMap controllerMapInstance = ReInput.mapping.GetControllerMapInstance(ReInput.controllers.GetController(controllerType, controllerId), controllerMap.categoryId, controllerMap.layoutId); if (controllerMapInstance != null) { List <int> list = new List <int>(); foreach (int item in allActionIds) { if (!savedControllerMapData.knownActionIds.Contains(item)) { list.Add(item); } } if (list.Count != 0) { foreach (ActionElementMap actionElementMap in controllerMapInstance.AllMaps) { if (list.Contains(actionElementMap.actionId)) { if (!map.DoesElementAssignmentConflict(actionElementMap)) { ElementAssignment elementAssignment = new ElementAssignment(controllerType, actionElementMap.elementType, actionElementMap.elementIdentifierId, actionElementMap.axisRange, actionElementMap.keyCode, actionElementMap.modifierKeyFlags, actionElementMap.actionId, actionElementMap.axisContribution, actionElementMap.invert); map.CreateElementMap(elementAssignment); } } } } } } } } } } }
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); } } }