private List <UserDataStore_PlayerPrefs.SavedControllerMapData> GetAllControllerMapsXml(Player player, bool userAssignableMapsOnly, Controller controller) { List <UserDataStore_PlayerPrefs.SavedControllerMapData> list = new List <UserDataStore_PlayerPrefs.SavedControllerMapData>(); IList <InputMapCategory> mapCategories = ReInput.mapping.MapCategories; for (int i = 0; i < mapCategories.Count; i++) { InputMapCategory inputMapCategory = mapCategories[i]; if (!userAssignableMapsOnly || inputMapCategory.userAssignable) { IList <InputLayout> list2 = ReInput.mapping.MapLayouts(controller.type); for (int j = 0; j < list2.Count; j++) { InputLayout inputLayout = list2[j]; string controllerMapXml = this.GetControllerMapXml(player, controller, inputMapCategory.id, inputLayout.id); if (!(controllerMapXml == string.Empty)) { List <int> controllerMapKnownActionIds = this.GetControllerMapKnownActionIds(player, controller, inputMapCategory.id, inputLayout.id); list.Add(new UserDataStore_PlayerPrefs.SavedControllerMapData(controllerMapXml, controllerMapKnownActionIds)); } } } } return(list); }
private List <SavedControllerMapData> GetAllControllerMapsXml(Player player, bool userAssignableMapsOnly, Controller controller) { // Because player prefs does not allow us to search for partial keys, we have to check all possible category ids and layout ids to find the maps to load List <SavedControllerMapData> data = new List <SavedControllerMapData>(); IList <InputMapCategory> categories = ReInput.mapping.MapCategories; for (int i = 0; i < categories.Count; i++) { InputMapCategory cat = categories[i]; if (userAssignableMapsOnly && !cat.userAssignable) { continue; // skip map because not user-assignable } IList <InputLayout> layouts = ReInput.mapping.MapLayouts(controller.type); for (int j = 0; j < layouts.Count; j++) { InputLayout layout = layouts[j]; string xml = GetControllerMapXml(player, controller, cat.id, layout.id); if (xml == string.Empty) { continue; } List <int> knownActionIds = GetControllerMapKnownActionIds(player, controller, cat.id, layout.id); data.Add(new SavedControllerMapData(xml, knownActionIds)); } } return(data); }
void UpdateText() { if (m_Player == null) { return; } m_StringBuilder.Length = 0; foreach (ControllerType type in System.Enum.GetValues(typeof(ControllerType))) { List <ControllerMap> maps = new List <ControllerMap>(); m_Player.controllers.maps.GetAllMaps(type, maps); if (maps.Count > 0) { m_StringBuilder.AppendFormat("{0} ({1})\n", type, maps.Count); foreach (ControllerMap map in maps) { InputMapCategory category = ReInput.mapping.GetMapCategory(map.categoryId); InputLayout layout = ReInput.mapping.GetLayout(type, map.layoutId); m_StringBuilder.AppendFormat(" {0} {1}\t {2}\n", category.name, layout.name, map.enabled ? "Enable" : "Disable"); } m_StringBuilder.AppendLine(); } } m_Text.text = m_StringBuilder.ToString(); }
public override string GetMapCategoryName(int id) { InputMapCategory category = ReInput.mapping.GetMapCategory(id); if (category == null) { throw new ArgumentException("Invalid map category id: " + id); } return(category.descriptiveName); }
private static void CaptureExistingActionElementRelationships(InputMapCategory sourceCategory, Player player, out Dictionary <int[], List <ActionElementMap> > elementSourceActionLinks, out Dictionary <int, ActionElementMap> storedElementMaps) { Player.ControllerHelper controllers = player.controllers; elementSourceActionLinks = new Dictionary <int[], List <ActionElementMap> >(); storedElementMaps = new Dictionary <int, ActionElementMap>(); IEnumerable <ControllerMap> enumerable = controllers.maps.GetAllMaps(ControllerType.Keyboard); if (enumerable == null) { enumerable = new List <ControllerMap>(); } foreach (ControllerMap controllerMap in enumerable) { if (controllerMap.categoryId == sourceCategory.id) { IList <ActionElementMap> allMaps = controllerMap.AllMaps; foreach (ActionElementMap actionElementMap in allMaps) { elementSourceActionLinks.Add(new int[] { actionElementMap.elementIdentifierId, actionElementMap.actionId, actionElementMap.id }, new List <ActionElementMap>()); if (!storedElementMaps.ContainsKey(actionElementMap.id)) { storedElementMaps.Add(actionElementMap.id, actionElementMap); } } } } foreach (ControllerMap controllerMap2 in enumerable) { bool flag = controllerMap2.categoryId == sourceCategory.id; if (!flag) { IList <ActionElementMap> allMaps2 = controllerMap2.AllMaps; foreach (ActionElementMap actionElementMap2 in allMaps2) { foreach (int[] array in elementSourceActionLinks.Keys) { int num = array[0]; int num2 = array[1]; bool flag2 = num2 == actionElementMap2.actionId; bool flag3 = num == actionElementMap2.elementIdentifierId; if (flag3 && flag2) { elementSourceActionLinks[array].Add(actionElementMap2); } } } } } }
/// <summary> /// Set all action inside a mapping to enabled /// </summary> /// <param name="categoryName"></param> public void ActivateAllActionsOfMap(string categoryName) { foreach (ControllerMap map in Player1Inputs.controllers.maps.GetAllMaps()) { InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(map.categoryId); if (mapCategory.name == categoryName) { foreach (ActionElementMap aem in map.AllMaps) { aem.enabled = true; } } } }
private void ClearAllControllerMapsXml(Player player, bool userAssignableMapsOnly, ControllerType controllerType, Controller controller) { List <string> list = new List <string>(); IList <InputMapCategory> mapCategories = ReInput.mapping.MapCategories; for (int i = 0; i < mapCategories.Count; i++) { InputMapCategory inputMapCategory = mapCategories[i]; if (!userAssignableMapsOnly || inputMapCategory.userAssignable) { IList <InputLayout> list2 = ReInput.mapping.MapLayouts(controllerType); for (int j = 0; j < list2.Count; j++) { InputLayout inputLayout = list2[j]; this.ClearControllerMapXml(player, controllerType, inputMapCategory.id, inputLayout.id, controller); } } } }
private List<string> GetAllControllerMapsXml(Player player, bool userAssignableMapsOnly, ControllerType controllerType, Controller controller) { // Because player prefs does not allow us to search for partial keys, we have to check all possible category ids and layout ids to find the maps to load List<string> mapsXml = new List<string>(); IList<InputMapCategory> categories = ReInput.mapping.MapCategories; for(int i = 0; i < categories.Count; i++) { InputMapCategory cat = categories[i]; if(userAssignableMapsOnly && !cat.userAssignable) continue; // skip map because not user-assignable IList<InputLayout> layouts = ReInput.mapping.MapLayouts(controllerType); for(int j = 0; j < layouts.Count; j++) { InputLayout layout = layouts[j]; string xml = GetControllerMapXml(player, controllerType, cat.id, layout.id, controller); if(xml == string.Empty) continue; mapsXml.Add(xml); } } return mapsXml; }
private List <string> GetAllControllerMapsXml(Player player, bool userAssignableMapsOnly, ControllerType controllerType, Controller controller) { List <string> list = new List <string>(); IList <InputMapCategory> mapCategories = ReInput.mapping.MapCategories; for (int i = 0; i < mapCategories.Count; i++) { InputMapCategory inputMapCategory = mapCategories[i]; if (!userAssignableMapsOnly || inputMapCategory.userAssignable) { IList <InputLayout> list2 = ReInput.mapping.MapLayouts(controllerType); for (int j = 0; j < list2.Count; j++) { InputLayout inputLayout = list2[j]; string controllerMapXml = this.GetControllerMapXml(player, controllerType, inputMapCategory.id, inputLayout.id, controller); if (!(controllerMapXml == string.Empty)) { list.Add(controllerMapXml); } } } } return(list); }
/// <summary> /// Method overload /// </summary> public void EnableMap(int categoryId, bool reactivateAllActions = true) { InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(categoryId); EnableMap(mapCategory.name, reactivateAllActions); }
private static void UpdateActionElementRelationships(Dictionary <int[], List <ActionElementMap> > elementSourceActionLinks, Dictionary <int, ActionElementMap> storedElementMaps, InputMapCategory sourceCategory, Player player) { foreach (KeyValuePair <int[], List <ActionElementMap> > keyValuePair in elementSourceActionLinks) { if (keyValuePair.Value.SafeCount <ActionElementMap>() != 0) { int key = keyValuePair.Key[2]; ActionElementMap oldElementMap = storedElementMaps[key]; KeyboardMap firstMapInCategory = player.controllers.maps.GetFirstMapInCategory <KeyboardMap>(0, sourceCategory.id); if (firstMapInCategory == null) { Debug.LogError("newControllerMap is null!"); } else { ActionElementMap firstElementMapMatch = firstMapInCategory.GetFirstElementMapMatch((ActionElementMap searchMap) => searchMap.actionId == oldElementMap.actionId); if (firstElementMapMatch == null) { Debug.LogError("sourceMap is null!"); } else { foreach (ActionElementMap actionElementMap in keyValuePair.Value) { ControllerMap controllerMap = actionElementMap.controllerMap; ElementAssignment elementAssignment = new ElementAssignment(ControllerType.Keyboard, firstElementMapMatch.elementType, firstElementMapMatch.elementIdentifierId, firstElementMapMatch.axisRange, firstElementMapMatch.keyCode, firstElementMapMatch.modifierKeyFlags, firstElementMapMatch.actionId, firstElementMapMatch.axisContribution, firstElementMapMatch.invert, actionElementMap.id); bool flag = controllerMap.DeleteElementMap(actionElementMap.id); ActionElementMap actionElementMap2; if (!flag || !controllerMap.CreateElementMap(elementAssignment, out actionElementMap2)) { Debug.Log("Failed to remap secondary actions"); } } } } } } }
public void LoadAllMaps() { Debug.Log("Reloading Input Mapping"); if (!ReInput.isReady) { return; } if (ReInput.players == null || ReInput.players.AllPlayers == null) { return; } IList <Player> allPlayers = ReInput.players.AllPlayers; for (int i = 0; i < allPlayers.Count; i++) { Player player = allPlayers[i]; IList <InputBehavior> inputBehaviors = ReInput.mapping.GetInputBehaviors(player.id); for (int j = 0; j < inputBehaviors.Count; j++) { string inputBehaviorXml = this.GetInputBehaviorXml(player, inputBehaviors[j].id); if (inputBehaviorXml != null && !(inputBehaviorXml == string.Empty)) { inputBehaviors[j].ImportXmlString(inputBehaviorXml); } } List <string> allControllerMapsXml = this.GetAllControllerMapsXml(player, true, ControllerType.Keyboard, ReInput.controllers.Keyboard); List <string> allControllerMapsXml2 = this.GetAllControllerMapsXml(player, true, ControllerType.Mouse, ReInput.controllers.Mouse); bool flag = false; List <List <string> > list = new List <List <string> >(); Debug.Log("Joystick count= " + player.controllers.Joysticks.Count); foreach (Rewired.Joystick controller in player.controllers.Joysticks) { List <string> allControllerMapsXml3 = this.GetAllControllerMapsXml(player, true, ControllerType.Joystick, controller); list.Add(allControllerMapsXml3); if (allControllerMapsXml3.Count > 0) { flag = true; } } if (allControllerMapsXml.Count > 0) { if (!allControllerMapsXml[0].Contains("<actionId>48</actionId>")) { allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>48</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>49</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!allControllerMapsXml[0].Contains("<actionId>49</actionId>")) { allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>49</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>50</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!allControllerMapsXml[0].Contains("<actionId>50</actionId>")) { allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>50</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>51</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!allControllerMapsXml[0].Contains("<actionId>51</actionId>")) { allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>51</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>52</keyboardKeyCode></ActionElementMap></buttonMaps>"); } } if (allControllerMapsXml.Count > 0) { InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(0); Dictionary <int[], List <ActionElementMap> > elementSourceActionLinks; Dictionary <int, ActionElementMap> storedElementMaps; InputMapping.CaptureExistingActionElementRelationships(mapCategory, player, out elementSourceActionLinks, out storedElementMaps); player.controllers.maps.ClearMaps(ControllerType.Keyboard, true); player.controllers.maps.AddMapsFromXml(ControllerType.Keyboard, 0, allControllerMapsXml); InputMapping.UpdateActionElementRelationships(elementSourceActionLinks, storedElementMaps, mapCategory, player); } if (flag) { player.controllers.maps.ClearMaps(ControllerType.Joystick, true); } int num = 0; foreach (Rewired.Joystick joystick in player.controllers.Joysticks) { bool flag2 = joystick.name.Contains("DualShock") || joystick.GetExtension <DualShock4Extension>() != null; if (list[num].Count > 0) { if (flag2) { if (!list[num][0].Contains("<actionId>48</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>48</actionId><elementType>1</elementType><elementIdentifierId>21</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>49</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>49</actionId><elementType>1</elementType><elementIdentifierId>20</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>50</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>50</actionId><elementType>1</elementType><elementIdentifierId>19</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>51</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>51</actionId><elementType>1</elementType><elementIdentifierId>18</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>53</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>53</actionId><elementType>1</elementType><elementIdentifierId>4</elementIdentifierId><axisRange>0</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>54</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>54</actionId><elementType>1</elementType><elementIdentifierId>6</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } } else { if (!list[num][0].Contains("<actionId>48</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>48</actionId><elementType>1</elementType><elementIdentifierId>19</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>49</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>49</actionId><elementType>1</elementType><elementIdentifierId>18</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>50</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>50</actionId><elementType>1</elementType><elementIdentifierId>17</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>51</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>51</actionId><elementType>1</elementType><elementIdentifierId>16</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>53</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>53</actionId><elementType>1</elementType><elementIdentifierId>4</elementIdentifierId><axisRange>0</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } if (!list[num][0].Contains("<actionId>54</actionId>")) { list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>54</actionId><elementType>1</elementType><elementIdentifierId>6</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>"); } } } player.controllers.maps.AddMapsFromXml(ControllerType.Joystick, joystick.id, list[num]); num++; } if (allControllerMapsXml2.Count > 0) { player.controllers.maps.ClearMaps(ControllerType.Mouse, true); } player.controllers.maps.AddMapsFromXml(ControllerType.Mouse, 0, allControllerMapsXml2); if (ForestVR.Enabled) { this.ProcessVRInputMappings(player); } } foreach (Rewired.Joystick joystick2 in ReInput.controllers.Joysticks) { joystick2.ImportCalibrationMapFromXmlString(this.GetJoystickCalibrationMapXml(joystick2)); } Input.ForceRefreshState(); InputMappingIcons.RefreshMappings(); }
void ShowKeybindingTables(int selectedCategoryId, ControllerMap selectedMap) { InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(selectedCategoryId); if (mapCategory == null) { DebugHelper.Log("不存在"); return; } InputCategory actionCategory = ReInput.mapping.GetActionCategory(mapCategory.name); if (actionCategory == null) { DebugHelper.Log("不存在"); return; } GameObject bd = Instantiate(keysBdPrefab, rootBd.transform); int siblingIndex = 0; if (controllerType == ControllerType.Joystick) { siblingIndex = 3; } else if (controllerType == ControllerType.Keyboard) { siblingIndex = 2; } bd.transform.SetSiblingIndex(bd.transform.parent.childCount - siblingIndex); keysBdList.Add(bd); foreach (InputAction inputAction in ReInput.mapping.ActionsInCategory(mapCategory.name)) { string keyName = inputAction.descriptiveName != string.Empty ? inputAction.descriptiveName : inputAction.name; var list = new List <ActionElementMap>(selectedMap.AllMaps); // list.Sort((x, y) => x.actionId.CompareTo(y.actionId)); if (inputAction.type == InputActionType.Button) { foreach (ActionElementMap ele in list) { if (ele.actionId != inputAction.id || !inputAction.userAssignable) { continue; } OneKeyBinding kb = Instantiate(keyBindingPrefab, bd.transform); kb.HandleListening += HandleListening; kb.RenderKey(playerId, inputAction, AxisRange.Positive, selectedMap.controllerType, selectedMap, ele); keyBindingList.Add(kb); } } else if (inputAction.type == InputActionType.Axis) { if (controllerType == ControllerType.Joystick) { continue; } foreach (ActionElementMap ele in selectedMap.AllMaps) { if (ele.actionId != inputAction.id || !inputAction.userAssignable) { continue; } if (ele.axisType == AxisType.Normal) { continue; } if (ele.axisContribution != Pole.Positive && ele.axisContribution != Pole.Negative) { continue; } AxisRange axisRange = ele.axisContribution == Pole.Positive ? AxisRange.Positive : AxisRange.Negative; OneKeyBinding kb = Instantiate(keyBindingPrefab, bd.transform); kb.HandleListening += HandleListening; kb.RenderKey(playerId, inputAction, axisRange, selectedMap.controllerType, selectedMap, ele); keyBindingList.Add(kb); } } else { DebugHelper.Log("意外的InputActionType"); } } }