public void SaveAllMaps() { IList <Player> allPlayers = ReInput.players.AllPlayers; for (int i = 0; i < allPlayers.Count; i++) { Player player = allPlayers[i]; PlayerSaveData saveData = player.GetSaveData(true); InputBehavior[] inputBehaviors = saveData.inputBehaviors; for (int j = 0; j < inputBehaviors.Length; j++) { InputBehavior inputBehavior = inputBehaviors[j]; string inputBehaviorPlayerPrefsKey = this.GetInputBehaviorPlayerPrefsKey(player, inputBehavior); PlayerPrefs.SetString(inputBehaviorPlayerPrefsKey, inputBehavior.ToXmlString()); } foreach (ControllerMapSaveData current in saveData.AllControllerMapSaveData) { string controllerMapPlayerPrefsKey = this.GetControllerMapPlayerPrefsKey(player, current); PlayerPrefs.SetString(controllerMapPlayerPrefsKey, current.map.ToXmlString()); } } foreach (Rewired.Joystick current2 in ReInput.controllers.Joysticks) { JoystickCalibrationMapSaveData calibrationMapSaveData = current2.GetCalibrationMapSaveData(); string joystickCalibrationMapPlayerPrefsKey = this.GetJoystickCalibrationMapPlayerPrefsKey(calibrationMapSaveData); PlayerPrefs.SetString(joystickCalibrationMapPlayerPrefsKey, calibrationMapSaveData.map.ToXmlString()); } PlayerPrefs.Save(); InputMappingIcons.RefreshMappings(); }
public void LoadAllMaps() { Debug.Log("Reloading Input Mapping"); 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 current in player.controllers.Joysticks) { List <string> allControllerMapsXml3 = this.GetAllControllerMapsXml(player, true, ControllerType.Joystick, current); list.Add(allControllerMapsXml3); if (allControllerMapsXml3.Count > 0) { flag = true; } } if (allControllerMapsXml.Count > 0) { player.controllers.maps.ClearMaps(ControllerType.Keyboard, true); } player.controllers.maps.AddMapsFromXml(ControllerType.Keyboard, 0, allControllerMapsXml); if (flag) { player.controllers.maps.ClearMaps(ControllerType.Joystick, true); } int num = 0; foreach (Rewired.Joystick current2 in player.controllers.Joysticks) { player.controllers.maps.AddMapsFromXml(ControllerType.Joystick, current2.id, list[num]); num++; } if (allControllerMapsXml2.Count > 0) { player.controllers.maps.ClearMaps(ControllerType.Mouse, true); } player.controllers.maps.AddMapsFromXml(ControllerType.Mouse, 0, allControllerMapsXml2); } foreach (Rewired.Joystick current3 in ReInput.controllers.Joysticks) { current3.ImportCalibrationMapFromXmlString(this.GetJoystickCalibrationMapXml(current3)); } InputMappingIcons.RefreshMappings(); }
public static UISprite RegisterIcon(Transform target, InputMappingIcons.Actions action, ActionIconSystem.CurrentViewOptions currentViewOption = ActionIconSystem.CurrentViewOptions.AllowInWorld) { if (ActionIconSystem.Instance && !ActionIconSystem.Instance._activeIcons.ContainsKey(target)) { ActionIcon actionIcon; if (!InputMappingIcons.UsesText(action)) { if (ActionIconSystem.Instance._spriteIconPool.Count > 0) { actionIcon = ActionIconSystem.Instance._spriteIconPool.Dequeue(); actionIcon.gameObject.SetActive(true); ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption); } else { actionIcon = UnityEngine.Object.Instantiate<ActionIcon>(ActionIconSystem.Instance._spriteIconPrefab); ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption); actionIcon.transform.localScale = ActionIconSystem.Instance._spriteIconPrefab.transform.localScale; } actionIcon._sprite.spriteName = InputMappingIcons.GetMappingFor(action); UISpriteData atlasSprite = actionIcon._sprite.GetAtlasSprite(); if (atlasSprite == null) { ActionIconSystem.Instance.DisableActionIcon(actionIcon); return null; } actionIcon._sprite.width = Mathf.RoundToInt((float)atlasSprite.width / (float)atlasSprite.height * (float)actionIcon._sprite.height); } else { if (ActionIconSystem.Instance._textIconPool.Count > 0) { actionIcon = ActionIconSystem.Instance._textIconPool.Dequeue(); actionIcon.gameObject.SetActive(true); ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption); } else { actionIcon = UnityEngine.Object.Instantiate<ActionIcon>(ActionIconSystem.Instance._textIconPrefab); ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption); actionIcon.transform.localScale = ActionIconSystem.Instance._textIconPrefab.transform.localScale; } actionIcon._label.text = InputMappingIcons.GetMappingFor(action); } actionIcon._follow._target = target; actionIcon._fillSprite.gameObject.SetActive(false); actionIcon._follow._inBook = (currentViewOption == ActionIconSystem.CurrentViewOptions.AllowInBook); ActionIconSystem.Instance._activeIcons.Add(target, actionIcon); return actionIcon._fillSprite; } return null; }
public static void ForceRefreshState() { if (ForestVR.Enabled) { VRControllerDisplayManager.ForceRefresh(); } if (Input.GetState(InputState.SavingMaps)) { Input.SetMappingExclusive(KeyMapCategory.Default); InputMappingIcons.RefreshMappings(); return; } if (Input.GetState(InputState.Locked)) { Input.SetMappingExclusive(KeyMapCategory.None); InputMappingIcons.RefreshMappings(); return; } if (Input.GetState(InputState.Chat)) { Input.SetMappingExclusive(KeyMapCategory.Chat); InputMappingIcons.RefreshMappings(); return; } if (Input.GetState(InputState.Menu)) { Input.SetMappingExclusive(KeyMapCategory.Menu); InputMappingIcons.RefreshMappings(); return; } if (Input.GetState(InputState.RadialWorld)) { Input.SetMappingExclusive(KeyMapCategory.RadialWorld); InputMappingIcons.RefreshMappings(); return; } if (Input.GetState(InputState.Book)) { Input.SetMappingExclusive(KeyMapCategory.Book); InputMappingIcons.RefreshMappings(); return; } if (Input.GetState(InputState.Inventory)) { Input.SetMappingExclusive(KeyMapCategory.Inventory); InputMappingIcons.RefreshMappings(); return; } Input.SetMappingExclusive(KeyMapCategory.Default); InputMappingIcons.RefreshMappings(); }
public void SaveAllMaps(bool enableBeforeSave = true) { IList <Player> allPlayers = ReInput.players.AllPlayers; for (int i = 0; i < allPlayers.Count; i++) { Player player = allPlayers[i]; PlayerSaveData saveData = player.GetSaveData(true); foreach (InputBehavior inputBehavior in saveData.inputBehaviors) { string inputBehaviorPlayerPrefsKey = this.GetInputBehaviorPlayerPrefsKey(player, inputBehavior); PlayerPrefs.SetString(inputBehaviorPlayerPrefsKey, inputBehavior.ToXmlString()); } foreach (ControllerMapSaveData controllerMapSaveData in saveData.AllControllerMapSaveData) { bool enabled = controllerMapSaveData.map.enabled; if (!enabled && enableBeforeSave) { controllerMapSaveData.map.enabled = true; } string controllerMapPlayerPrefsKey = this.GetControllerMapPlayerPrefsKey(player, controllerMapSaveData); PlayerPrefs.SetString(controllerMapPlayerPrefsKey, controllerMapSaveData.map.ToXmlString()); if (!enabled) { controllerMapSaveData.map.enabled = false; } } } foreach (Rewired.Joystick joystick in ReInput.controllers.Joysticks) { JoystickCalibrationMapSaveData calibrationMapSaveData = joystick.GetCalibrationMapSaveData(); string joystickCalibrationMapPlayerPrefsKey = this.GetJoystickCalibrationMapPlayerPrefsKey(calibrationMapSaveData); PlayerPrefs.SetString(joystickCalibrationMapPlayerPrefsKey, calibrationMapSaveData.map.ToXmlString()); } PlayerPrefs.Save(); InputMappingIcons.RefreshMappings(); }
public void LoadAllMaps() { Debug.Log("Reloading Input Mapping"); 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) { player.controllers.maps.ClearMaps(ControllerType.Keyboard, true); } player.controllers.maps.AddMapsFromXml(ControllerType.Keyboard, 0, allControllerMapsXml); 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); player.controllers.maps.SetMapsEnabled(true, ControllerType.Joystick, "Default"); player.controllers.maps.SetMapsEnabled(true, ControllerType.Keyboard, "Default"); } foreach (Rewired.Joystick joystick2 in ReInput.controllers.Joysticks) { joystick2.ImportCalibrationMapFromXmlString(this.GetJoystickCalibrationMapXml(joystick2)); } InputMappingIcons.RefreshMappings(); }