From c5f145786f4c6d2fe4bea831dfc16e52228920a5 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 19 May 2024 16:05:01 +0800 Subject: * move --- Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs | 1358 --------------- .../ControllerUIEffect.cs | 57 - .../ControllerUIElement.cs | 186 -- .../GamepadTemplateUI.cs | 417 ----- Rewired/Rewired.Demos/Bullet.cs | 30 - Rewired/Rewired.Demos/ControlRemappingDemo1.cs | 1797 -------------------- Rewired/Rewired.Demos/CustomControllerDemo.cs | 144 -- .../Rewired.Demos/CustomControllerDemo_Player.cs | 58 - Rewired/Rewired.Demos/CustomControllersTiltDemo.cs | 47 - .../DualShock4SpecialFeaturesExample.cs | 219 --- .../Rewired.Demos/EightPlayersExample_Player.cs | 71 - .../FallbackJoystickIdentificationDemo.cs | 114 -- Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs | 116 -- .../PlayerPointerEventHandlerExample.cs | 138 -- .../PressAnyButtonToJoinExample_Assigner.cs | 57 - .../PressAnyButtonToJoinExample_GamePlayer.cs | 67 - .../PressStartToJoinExample_Assigner.cs | 87 - .../PressStartToJoinExample_GamePlayer.cs | 57 - .../SimpleCombinedKeyboardMouseRemapping.cs | 225 --- Rewired/Rewired.Demos/SimpleControlRemapping.cs | 257 --- Rewired/Rewired.Demos/TouchButtonExample.cs | 52 - Rewired/Rewired.Demos/TouchJoystickExample.cs | 110 -- Rewired/Rewired.Demos/UIPointer.cs | 98 -- .../PlayerPointerEventData.cs | 41 - .../PointerEventType.cs | 7 - .../RewiredEventSystem.cs | 49 - .../RewiredPointerInputModule.cs | 781 --------- .../RewiredStandaloneInputModule.cs | 1415 --------------- .../Rewired.Internal/ControllerTemplateFactory.cs | 59 - Rewired/Rewired.Utils/ExternalTools.cs | 171 -- Rewired/Rewired/FlightPedalsTemplate.cs | 25 - Rewired/Rewired/FlightYokeTemplate.cs | 265 --- Rewired/Rewired/GamepadTemplate.cs | 149 -- Rewired/Rewired/HOTASTemplate.cs | 525 ------ Rewired/Rewired/IFlightPedalsTemplate.cs | 10 - Rewired/Rewired/IFlightYokeTemplate.cs | 102 -- Rewired/Rewired/IGamepadTemplate.cs | 62 - Rewired/Rewired/IHOTASTemplate.cs | 180 -- Rewired/Rewired/IRacingWheelTemplate.cs | 88 - Rewired/Rewired/ISixDofControllerTemplate.cs | 86 - Rewired/Rewired/InputManager.cs | 81 - Rewired/Rewired/RacingWheelTemplate.cs | 189 -- Rewired/Rewired/SixDofControllerTemplate.cs | 229 --- 43 files changed, 10276 deletions(-) delete mode 100644 Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs delete mode 100644 Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs delete mode 100644 Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs delete mode 100644 Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs delete mode 100644 Rewired/Rewired.Demos/Bullet.cs delete mode 100644 Rewired/Rewired.Demos/ControlRemappingDemo1.cs delete mode 100644 Rewired/Rewired.Demos/CustomControllerDemo.cs delete mode 100644 Rewired/Rewired.Demos/CustomControllerDemo_Player.cs delete mode 100644 Rewired/Rewired.Demos/CustomControllersTiltDemo.cs delete mode 100644 Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs delete mode 100644 Rewired/Rewired.Demos/EightPlayersExample_Player.cs delete mode 100644 Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs delete mode 100644 Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs delete mode 100644 Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs delete mode 100644 Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs delete mode 100644 Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs delete mode 100644 Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs delete mode 100644 Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs delete mode 100644 Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs delete mode 100644 Rewired/Rewired.Demos/SimpleControlRemapping.cs delete mode 100644 Rewired/Rewired.Demos/TouchButtonExample.cs delete mode 100644 Rewired/Rewired.Demos/TouchJoystickExample.cs delete mode 100644 Rewired/Rewired.Demos/UIPointer.cs delete mode 100644 Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs delete mode 100644 Rewired/Rewired.Integration.UnityUI/PointerEventType.cs delete mode 100644 Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs delete mode 100644 Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs delete mode 100644 Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs delete mode 100644 Rewired/Rewired.Internal/ControllerTemplateFactory.cs delete mode 100644 Rewired/Rewired.Utils/ExternalTools.cs delete mode 100644 Rewired/Rewired/FlightPedalsTemplate.cs delete mode 100644 Rewired/Rewired/FlightYokeTemplate.cs delete mode 100644 Rewired/Rewired/GamepadTemplate.cs delete mode 100644 Rewired/Rewired/HOTASTemplate.cs delete mode 100644 Rewired/Rewired/IFlightPedalsTemplate.cs delete mode 100644 Rewired/Rewired/IFlightYokeTemplate.cs delete mode 100644 Rewired/Rewired/IGamepadTemplate.cs delete mode 100644 Rewired/Rewired/IHOTASTemplate.cs delete mode 100644 Rewired/Rewired/IRacingWheelTemplate.cs delete mode 100644 Rewired/Rewired/ISixDofControllerTemplate.cs delete mode 100644 Rewired/Rewired/InputManager.cs delete mode 100644 Rewired/Rewired/RacingWheelTemplate.cs delete mode 100644 Rewired/Rewired/SixDofControllerTemplate.cs (limited to 'Rewired') diff --git a/Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs b/Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs deleted file mode 100644 index b5a933b..0000000 --- a/Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs +++ /dev/null @@ -1,1358 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using Rewired.Utils.Libraries.TinyJson; -using UnityEngine; - -namespace Rewired.Data; - -public class UserDataStore_PlayerPrefs : UserDataStore -{ - private class ControllerAssignmentSaveInfo - { - public class PlayerInfo - { - public int id; - - public bool hasKeyboard; - - public bool hasMouse; - - public JoystickInfo[] joysticks; - - public int joystickCount - { - get - { - if (joysticks == null) - { - return 0; - } - return joysticks.Length; - } - } - - public int IndexOfJoystick(int joystickId) - { - for (int i = 0; i < joystickCount; i++) - { - if (joysticks[i] != null && joysticks[i].id == joystickId) - { - return i; - } - } - return -1; - } - - public bool ContainsJoystick(int joystickId) - { - return IndexOfJoystick(joystickId) >= 0; - } - } - - public class JoystickInfo - { - public Guid instanceGuid; - - public string hardwareIdentifier; - - public int id; - } - - public PlayerInfo[] players; - - public int playerCount - { - get - { - if (players == null) - { - return 0; - } - return players.Length; - } - } - - public ControllerAssignmentSaveInfo() - { - } - - public ControllerAssignmentSaveInfo(int playerCount) - { - players = new PlayerInfo[playerCount]; - for (int i = 0; i < playerCount; i++) - { - players[i] = new PlayerInfo(); - } - } - - public int IndexOfPlayer(int playerId) - { - for (int i = 0; i < playerCount; i++) - { - if (players[i] != null && players[i].id == playerId) - { - return i; - } - } - return -1; - } - - public bool ContainsPlayer(int playerId) - { - return IndexOfPlayer(playerId) >= 0; - } - } - - private class JoystickAssignmentHistoryInfo - { - public readonly Joystick joystick; - - public readonly int oldJoystickId; - - public JoystickAssignmentHistoryInfo(Joystick joystick, int oldJoystickId) - { - if (joystick == null) - { - throw new ArgumentNullException("joystick"); - } - this.joystick = joystick; - this.oldJoystickId = oldJoystickId; - } - } - - private const string thisScriptName = "UserDataStore_PlayerPrefs"; - - private const string logPrefix = "Rewired: "; - - private const string editorLoadedMessage = "\n***IMPORTANT:*** Changes made to the Rewired Input Manager configuration after the last time XML data was saved WILL NOT be used because the loaded old saved data has overwritten these values. If you change something in the Rewired Input Manager such as a Joystick Map or Input Behavior settings, you will not see these changes reflected in the current configuration. Clear PlayerPrefs using the inspector option on the UserDataStore_PlayerPrefs component."; - - private const string playerPrefsKeySuffix_controllerAssignments = "ControllerAssignments"; - - private const int controllerMapPPKeyVersion_original = 0; - - private const int controllerMapPPKeyVersion_includeDuplicateJoystickIndex = 1; - - private const int controllerMapPPKeyVersion_supportDisconnectedControllers = 2; - - private const int controllerMapPPKeyVersion_includeFormatVersion = 2; - - private const int controllerMapPPKeyVersion = 2; - - [Tooltip("Should this script be used? If disabled, nothing will be saved or loaded.")] - [SerializeField] - private bool isEnabled = true; - - [Tooltip("Should saved data be loaded on start?")] - [SerializeField] - private bool loadDataOnStart = true; - - [Tooltip("Should Player Joystick assignments be saved and loaded? This is not totally reliable for all Joysticks on all platforms. Some platforms/input sources do not provide enough information to reliably save assignments from session to session and reboot to reboot.")] - [SerializeField] - private bool loadJoystickAssignments = true; - - [Tooltip("Should Player Keyboard assignments be saved and loaded?")] - [SerializeField] - private bool loadKeyboardAssignments = true; - - [Tooltip("Should Player Mouse assignments be saved and loaded?")] - [SerializeField] - private bool loadMouseAssignments = true; - - [Tooltip("The PlayerPrefs key prefix. Change this to change how keys are stored in PlayerPrefs. Changing this will make saved data already stored with the old key no longer accessible.")] - [SerializeField] - private string playerPrefsKeyPrefix = "RewiredSaveData"; - - [NonSerialized] - private bool allowImpreciseJoystickAssignmentMatching = true; - - [NonSerialized] - private bool deferredJoystickAssignmentLoadPending; - - [NonSerialized] - private bool wasJoystickEverDetected; - - [NonSerialized] - private List __allActionIds; - - [NonSerialized] - private string __allActionIdsString; - - public bool IsEnabled - { - get - { - return isEnabled; - } - set - { - isEnabled = value; - } - } - - public bool LoadDataOnStart - { - get - { - return loadDataOnStart; - } - set - { - loadDataOnStart = value; - } - } - - public bool LoadJoystickAssignments - { - get - { - return loadJoystickAssignments; - } - set - { - loadJoystickAssignments = value; - } - } - - public bool LoadKeyboardAssignments - { - get - { - return loadKeyboardAssignments; - } - set - { - loadKeyboardAssignments = value; - } - } - - public bool LoadMouseAssignments - { - get - { - return loadMouseAssignments; - } - set - { - loadMouseAssignments = value; - } - } - - public string PlayerPrefsKeyPrefix - { - get - { - return playerPrefsKeyPrefix; - } - set - { - playerPrefsKeyPrefix = value; - } - } - - private string playerPrefsKey_controllerAssignments => string.Format("{0}_{1}", playerPrefsKeyPrefix, "ControllerAssignments"); - - private bool loadControllerAssignments - { - get - { - if (!loadKeyboardAssignments && !loadMouseAssignments) - { - return loadJoystickAssignments; - } - return true; - } - } - - private List allActionIds - { - get - { - if (__allActionIds != null) - { - return __allActionIds; - } - List list = new List(); - IList actions = ReInput.mapping.Actions; - for (int i = 0; i < actions.Count; i++) - { - list.Add(actions[i].id); - } - __allActionIds = list; - return list; - } - } - - private string allActionIdsString - { - get - { - if (!string.IsNullOrEmpty(__allActionIdsString)) - { - return __allActionIdsString; - } - StringBuilder stringBuilder = new StringBuilder(); - List list = allActionIds; - for (int i = 0; i < list.Count; i++) - { - if (i > 0) - { - stringBuilder.Append(","); - } - stringBuilder.Append(list[i]); - } - __allActionIdsString = stringBuilder.ToString(); - return __allActionIdsString; - } - } - - public override void Save() - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); - } - else - { - SaveAll(); - } - } - - public override void SaveControllerData(int playerId, ControllerType controllerType, int controllerId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); - } - else - { - SaveControllerDataNow(playerId, controllerType, controllerId); - } - } - - public override void SaveControllerData(ControllerType controllerType, int controllerId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); - } - else - { - SaveControllerDataNow(controllerType, controllerId); - } - } - - public override void SavePlayerData(int playerId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); - } - else - { - SavePlayerDataNow(playerId); - } - } - - public override void SaveInputBehavior(int playerId, int behaviorId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); - } - else - { - SaveInputBehaviorNow(playerId, behaviorId); - } - } - - public override void Load() - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); - } - else - { - LoadAll(); - } - } - - public override void LoadControllerData(int playerId, ControllerType controllerType, int controllerId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); - } - else - { - LoadControllerDataNow(playerId, controllerType, controllerId); - } - } - - public override void LoadControllerData(ControllerType controllerType, int controllerId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); - } - else - { - LoadControllerDataNow(controllerType, controllerId); - } - } - - public override void LoadPlayerData(int playerId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); - } - else - { - LoadPlayerDataNow(playerId); - } - } - - public override void LoadInputBehavior(int playerId, int behaviorId) - { - if (!isEnabled) - { - Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); - } - else - { - LoadInputBehaviorNow(playerId, behaviorId); - } - } - - protected override void OnInitialize() - { - if (loadDataOnStart) - { - Load(); - if (loadControllerAssignments && ReInput.controllers.joystickCount > 0) - { - wasJoystickEverDetected = true; - SaveControllerAssignments(); - } - } - } - - protected override void OnControllerConnected(ControllerStatusChangedEventArgs args) - { - if (isEnabled && args.controllerType == ControllerType.Joystick) - { - LoadJoystickData(args.controllerId); - if (loadDataOnStart && loadJoystickAssignments && !wasJoystickEverDetected) - { - StartCoroutine(LoadJoystickAssignmentsDeferred()); - } - if (loadJoystickAssignments && !deferredJoystickAssignmentLoadPending) - { - SaveControllerAssignments(); - } - wasJoystickEverDetected = true; - } - } - - protected override void OnControllerPreDisconnect(ControllerStatusChangedEventArgs args) - { - if (isEnabled && args.controllerType == ControllerType.Joystick) - { - SaveJoystickData(args.controllerId); - } - } - - protected override void OnControllerDisconnected(ControllerStatusChangedEventArgs args) - { - if (isEnabled && loadControllerAssignments) - { - SaveControllerAssignments(); - } - } - - public override void SaveControllerMap(int playerId, ControllerMap controllerMap) - { - if (controllerMap != null) - { - Player player = ReInput.players.GetPlayer(playerId); - if (player != null) - { - SaveControllerMap(player, controllerMap); - } - } - } - - public override ControllerMap LoadControllerMap(int playerId, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) - { - Player player = ReInput.players.GetPlayer(playerId); - if (player == null) - { - return null; - } - return LoadControllerMap(player, controllerIdentifier, categoryId, layoutId); - } - - private int LoadAll() - { - int num = 0; - if (loadControllerAssignments && LoadControllerAssignmentsNow()) - { - num++; - } - IList allPlayers = ReInput.players.AllPlayers; - for (int i = 0; i < allPlayers.Count; i++) - { - num += LoadPlayerDataNow(allPlayers[i]); - } - return num + LoadAllJoystickCalibrationData(); - } - - private int LoadPlayerDataNow(int playerId) - { - return LoadPlayerDataNow(ReInput.players.GetPlayer(playerId)); - } - - private int LoadPlayerDataNow(Player player) - { - if (player == null) - { - return 0; - } - int num = 0; - num += LoadInputBehaviors(player.id); - num += LoadControllerMaps(player.id, ControllerType.Keyboard, 0); - num += LoadControllerMaps(player.id, ControllerType.Mouse, 0); - foreach (Joystick joystick in player.controllers.Joysticks) - { - num += LoadControllerMaps(player.id, ControllerType.Joystick, joystick.id); - } - RefreshLayoutManager(player.id); - return num; - } - - private int LoadAllJoystickCalibrationData() - { - int num = 0; - IList joysticks = ReInput.controllers.Joysticks; - for (int i = 0; i < joysticks.Count; i++) - { - num += LoadJoystickCalibrationData(joysticks[i]); - } - return num; - } - - private int LoadJoystickCalibrationData(Joystick joystick) - { - if (joystick == null) - { - return 0; - } - if (!joystick.ImportCalibrationMapFromXmlString(GetJoystickCalibrationMapXml(joystick))) - { - return 0; - } - return 1; - } - - private int LoadJoystickCalibrationData(int joystickId) - { - return LoadJoystickCalibrationData(ReInput.controllers.GetJoystick(joystickId)); - } - - private int LoadJoystickData(int joystickId) - { - int num = 0; - IList allPlayers = ReInput.players.AllPlayers; - for (int i = 0; i < allPlayers.Count; i++) - { - Player player = allPlayers[i]; - if (player.controllers.ContainsController(ControllerType.Joystick, joystickId)) - { - num += LoadControllerMaps(player.id, ControllerType.Joystick, joystickId); - RefreshLayoutManager(player.id); - } - } - return num + LoadJoystickCalibrationData(joystickId); - } - - private int LoadControllerDataNow(int playerId, ControllerType controllerType, int controllerId) - { - int num = 0 + LoadControllerMaps(playerId, controllerType, controllerId); - RefreshLayoutManager(playerId); - return num + LoadControllerDataNow(controllerType, controllerId); - } - - private int LoadControllerDataNow(ControllerType controllerType, int controllerId) - { - int num = 0; - if (controllerType == ControllerType.Joystick) - { - num += LoadJoystickCalibrationData(controllerId); - } - return num; - } - - private int LoadControllerMaps(int playerId, ControllerType controllerType, int controllerId) - { - int num = 0; - Player player = ReInput.players.GetPlayer(playerId); - if (player == null) - { - return num; - } - Controller controller = ReInput.controllers.GetController(controllerType, controllerId); - if (controller == null) - { - return num; - } - IList mapCategories = ReInput.mapping.MapCategories; - for (int i = 0; i < mapCategories.Count; i++) - { - InputMapCategory inputMapCategory = mapCategories[i]; - if (!inputMapCategory.userAssignable) - { - continue; - } - IList list = ReInput.mapping.MapLayouts(controller.type); - for (int j = 0; j < list.Count; j++) - { - InputLayout inputLayout = list[j]; - ControllerMap controllerMap = LoadControllerMap(player, controller.identifier, inputMapCategory.id, inputLayout.id); - if (controllerMap != null) - { - player.controllers.maps.AddMap(controller, controllerMap); - num++; - } - } - } - return num; - } - - private ControllerMap LoadControllerMap(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) - { - if (player == null) - { - return null; - } - string controllerMapXml = GetControllerMapXml(player, controllerIdentifier, categoryId, layoutId); - if (string.IsNullOrEmpty(controllerMapXml)) - { - return null; - } - ControllerMap controllerMap = ControllerMap.CreateFromXml(controllerIdentifier.controllerType, controllerMapXml); - if (controllerMap == null) - { - return null; - } - List controllerMapKnownActionIds = GetControllerMapKnownActionIds(player, controllerIdentifier, categoryId, layoutId); - AddDefaultMappingsForNewActions(controllerIdentifier, controllerMap, controllerMapKnownActionIds); - return controllerMap; - } - - private int LoadInputBehaviors(int playerId) - { - Player player = ReInput.players.GetPlayer(playerId); - if (player == null) - { - return 0; - } - int num = 0; - IList inputBehaviors = ReInput.mapping.GetInputBehaviors(player.id); - for (int i = 0; i < inputBehaviors.Count; i++) - { - num += LoadInputBehaviorNow(player, inputBehaviors[i]); - } - return num; - } - - private int LoadInputBehaviorNow(int playerId, int behaviorId) - { - Player player = ReInput.players.GetPlayer(playerId); - if (player == null) - { - return 0; - } - InputBehavior inputBehavior = ReInput.mapping.GetInputBehavior(playerId, behaviorId); - if (inputBehavior == null) - { - return 0; - } - return LoadInputBehaviorNow(player, inputBehavior); - } - - private int LoadInputBehaviorNow(Player player, InputBehavior inputBehavior) - { - if (player == null || inputBehavior == null) - { - return 0; - } - string inputBehaviorXml = GetInputBehaviorXml(player, inputBehavior.id); - if (inputBehaviorXml == null || inputBehaviorXml == string.Empty) - { - return 0; - } - if (!inputBehavior.ImportXmlString(inputBehaviorXml)) - { - return 0; - } - return 1; - } - - private bool LoadControllerAssignmentsNow() - { - try - { - ControllerAssignmentSaveInfo controllerAssignmentSaveInfo = LoadControllerAssignmentData(); - if (controllerAssignmentSaveInfo == null) - { - return false; - } - if (loadKeyboardAssignments || loadMouseAssignments) - { - LoadKeyboardAndMouseAssignmentsNow(controllerAssignmentSaveInfo); - } - if (loadJoystickAssignments) - { - LoadJoystickAssignmentsNow(controllerAssignmentSaveInfo); - } - } - catch - { - } - return true; - } - - private bool LoadKeyboardAndMouseAssignmentsNow(ControllerAssignmentSaveInfo data) - { - try - { - if (data == null && (data = LoadControllerAssignmentData()) == null) - { - return false; - } - foreach (Player allPlayer in ReInput.players.AllPlayers) - { - if (data.ContainsPlayer(allPlayer.id)) - { - ControllerAssignmentSaveInfo.PlayerInfo playerInfo = data.players[data.IndexOfPlayer(allPlayer.id)]; - if (loadKeyboardAssignments) - { - allPlayer.controllers.hasKeyboard = playerInfo.hasKeyboard; - } - if (loadMouseAssignments) - { - allPlayer.controllers.hasMouse = playerInfo.hasMouse; - } - } - } - } - catch - { - } - return true; - } - - private bool LoadJoystickAssignmentsNow(ControllerAssignmentSaveInfo data) - { - try - { - if (ReInput.controllers.joystickCount == 0) - { - return false; - } - if (data == null && (data = LoadControllerAssignmentData()) == null) - { - return false; - } - foreach (Player allPlayer in ReInput.players.AllPlayers) - { - allPlayer.controllers.ClearControllersOfType(ControllerType.Joystick); - } - List list = (loadJoystickAssignments ? new List() : null); - foreach (Player allPlayer2 in ReInput.players.AllPlayers) - { - if (!data.ContainsPlayer(allPlayer2.id)) - { - continue; - } - ControllerAssignmentSaveInfo.PlayerInfo playerInfo = data.players[data.IndexOfPlayer(allPlayer2.id)]; - for (int i = 0; i < playerInfo.joystickCount; i++) - { - ControllerAssignmentSaveInfo.JoystickInfo joystickInfo2 = playerInfo.joysticks[i]; - if (joystickInfo2 == null) - { - continue; - } - Joystick joystick = FindJoystickPrecise(joystickInfo2); - if (joystick != null) - { - if (list.Find((JoystickAssignmentHistoryInfo x) => x.joystick == joystick) == null) - { - list.Add(new JoystickAssignmentHistoryInfo(joystick, joystickInfo2.id)); - } - allPlayer2.controllers.AddController(joystick, removeFromOtherPlayers: false); - } - } - } - if (allowImpreciseJoystickAssignmentMatching) - { - foreach (Player allPlayer3 in ReInput.players.AllPlayers) - { - if (!data.ContainsPlayer(allPlayer3.id)) - { - continue; - } - ControllerAssignmentSaveInfo.PlayerInfo playerInfo2 = data.players[data.IndexOfPlayer(allPlayer3.id)]; - for (int j = 0; j < playerInfo2.joystickCount; j++) - { - ControllerAssignmentSaveInfo.JoystickInfo joystickInfo = playerInfo2.joysticks[j]; - if (joystickInfo == null) - { - continue; - } - Joystick joystick2 = null; - int num = list.FindIndex((JoystickAssignmentHistoryInfo x) => x.oldJoystickId == joystickInfo.id); - if (num >= 0) - { - joystick2 = list[num].joystick; - } - else - { - if (!TryFindJoysticksImprecise(joystickInfo, out var matches)) - { - continue; - } - foreach (Joystick match in matches) - { - if (list.Find((JoystickAssignmentHistoryInfo x) => x.joystick == match) == null) - { - joystick2 = match; - break; - } - } - if (joystick2 == null) - { - continue; - } - list.Add(new JoystickAssignmentHistoryInfo(joystick2, joystickInfo.id)); - } - allPlayer3.controllers.AddController(joystick2, removeFromOtherPlayers: false); - } - } - } - } - catch - { - } - if (ReInput.configuration.autoAssignJoysticks) - { - ReInput.controllers.AutoAssignJoysticks(); - } - return true; - } - - private ControllerAssignmentSaveInfo LoadControllerAssignmentData() - { - try - { - if (!PlayerPrefs.HasKey(playerPrefsKey_controllerAssignments)) - { - return null; - } - string @string = PlayerPrefs.GetString(playerPrefsKey_controllerAssignments); - if (string.IsNullOrEmpty(@string)) - { - return null; - } - ControllerAssignmentSaveInfo controllerAssignmentSaveInfo = JsonParser.FromJson(@string); - if (controllerAssignmentSaveInfo == null || controllerAssignmentSaveInfo.playerCount == 0) - { - return null; - } - return controllerAssignmentSaveInfo; - } - catch - { - return null; - } - } - - private IEnumerator LoadJoystickAssignmentsDeferred() - { - deferredJoystickAssignmentLoadPending = true; - yield return new WaitForEndOfFrame(); - if (ReInput.isReady) - { - LoadJoystickAssignmentsNow(null); - SaveControllerAssignments(); - deferredJoystickAssignmentLoadPending = false; - } - } - - private void SaveAll() - { - IList allPlayers = ReInput.players.AllPlayers; - for (int i = 0; i < allPlayers.Count; i++) - { - SavePlayerDataNow(allPlayers[i]); - } - SaveAllJoystickCalibrationData(); - if (loadControllerAssignments) - { - SaveControllerAssignments(); - } - PlayerPrefs.Save(); - } - - private void SavePlayerDataNow(int playerId) - { - SavePlayerDataNow(ReInput.players.GetPlayer(playerId)); - PlayerPrefs.Save(); - } - - private void SavePlayerDataNow(Player player) - { - if (player != null) - { - PlayerSaveData saveData = player.GetSaveData(userAssignableMapsOnly: true); - SaveInputBehaviors(player, saveData); - SaveControllerMaps(player, saveData); - } - } - - private void SaveAllJoystickCalibrationData() - { - IList joysticks = ReInput.controllers.Joysticks; - for (int i = 0; i < joysticks.Count; i++) - { - SaveJoystickCalibrationData(joysticks[i]); - } - } - - private void SaveJoystickCalibrationData(int joystickId) - { - SaveJoystickCalibrationData(ReInput.controllers.GetJoystick(joystickId)); - } - - private void SaveJoystickCalibrationData(Joystick joystick) - { - if (joystick != null) - { - JoystickCalibrationMapSaveData calibrationMapSaveData = joystick.GetCalibrationMapSaveData(); - PlayerPrefs.SetString(GetJoystickCalibrationMapPlayerPrefsKey(joystick), calibrationMapSaveData.map.ToXmlString()); - } - } - - private void SaveJoystickData(int joystickId) - { - IList allPlayers = ReInput.players.AllPlayers; - for (int i = 0; i < allPlayers.Count; i++) - { - Player player = allPlayers[i]; - if (player.controllers.ContainsController(ControllerType.Joystick, joystickId)) - { - SaveControllerMaps(player.id, ControllerType.Joystick, joystickId); - } - } - SaveJoystickCalibrationData(joystickId); - } - - private void SaveControllerDataNow(int playerId, ControllerType controllerType, int controllerId) - { - SaveControllerMaps(playerId, controllerType, controllerId); - SaveControllerDataNow(controllerType, controllerId); - PlayerPrefs.Save(); - } - - private void SaveControllerDataNow(ControllerType controllerType, int controllerId) - { - if (controllerType == ControllerType.Joystick) - { - SaveJoystickCalibrationData(controllerId); - } - PlayerPrefs.Save(); - } - - private void SaveControllerMaps(Player player, PlayerSaveData playerSaveData) - { - foreach (ControllerMapSaveData allControllerMapSaveDatum in playerSaveData.AllControllerMapSaveData) - { - SaveControllerMap(player, allControllerMapSaveDatum.map); - } - } - - private void SaveControllerMaps(int playerId, ControllerType controllerType, int controllerId) - { - Player player = ReInput.players.GetPlayer(playerId); - if (player == null || !player.controllers.ContainsController(controllerType, controllerId)) - { - return; - } - ControllerMapSaveData[] mapSaveData = player.controllers.maps.GetMapSaveData(controllerType, controllerId, userAssignableMapsOnly: true); - if (mapSaveData != null) - { - for (int i = 0; i < mapSaveData.Length; i++) - { - SaveControllerMap(player, mapSaveData[i].map); - } - } - } - - private void SaveControllerMap(Player player, ControllerMap controllerMap) - { - PlayerPrefs.SetString(GetControllerMapPlayerPrefsKey(player, controllerMap.controller.identifier, controllerMap.categoryId, controllerMap.layoutId, 2), controllerMap.ToXmlString()); - PlayerPrefs.SetString(GetControllerMapKnownActionIdsPlayerPrefsKey(player, controllerMap.controller.identifier, controllerMap.categoryId, controllerMap.layoutId, 2), allActionIdsString); - } - - private void SaveInputBehaviors(Player player, PlayerSaveData playerSaveData) - { - if (player != null) - { - InputBehavior[] inputBehaviors = playerSaveData.inputBehaviors; - for (int i = 0; i < inputBehaviors.Length; i++) - { - SaveInputBehaviorNow(player, inputBehaviors[i]); - } - } - } - - private void SaveInputBehaviorNow(int playerId, int behaviorId) - { - Player player = ReInput.players.GetPlayer(playerId); - if (player != null) - { - InputBehavior inputBehavior = ReInput.mapping.GetInputBehavior(playerId, behaviorId); - if (inputBehavior != null) - { - SaveInputBehaviorNow(player, inputBehavior); - PlayerPrefs.Save(); - } - } - } - - private void SaveInputBehaviorNow(Player player, InputBehavior inputBehavior) - { - if (player != null && inputBehavior != null) - { - PlayerPrefs.SetString(GetInputBehaviorPlayerPrefsKey(player, inputBehavior.id), inputBehavior.ToXmlString()); - } - } - - private bool SaveControllerAssignments() - { - try - { - ControllerAssignmentSaveInfo controllerAssignmentSaveInfo = new ControllerAssignmentSaveInfo(ReInput.players.allPlayerCount); - for (int i = 0; i < ReInput.players.allPlayerCount; i++) - { - Player player = ReInput.players.AllPlayers[i]; - ControllerAssignmentSaveInfo.PlayerInfo playerInfo = new ControllerAssignmentSaveInfo.PlayerInfo(); - controllerAssignmentSaveInfo.players[i] = playerInfo; - playerInfo.id = player.id; - playerInfo.hasKeyboard = player.controllers.hasKeyboard; - playerInfo.hasMouse = player.controllers.hasMouse; - ControllerAssignmentSaveInfo.JoystickInfo[] array = (playerInfo.joysticks = new ControllerAssignmentSaveInfo.JoystickInfo[player.controllers.joystickCount]); - for (int j = 0; j < player.controllers.joystickCount; j++) - { - Joystick joystick = player.controllers.Joysticks[j]; - ControllerAssignmentSaveInfo.JoystickInfo joystickInfo = new ControllerAssignmentSaveInfo.JoystickInfo(); - joystickInfo.instanceGuid = joystick.deviceInstanceGuid; - joystickInfo.id = joystick.id; - joystickInfo.hardwareIdentifier = joystick.hardwareIdentifier; - array[j] = joystickInfo; - } - } - PlayerPrefs.SetString(playerPrefsKey_controllerAssignments, JsonWriter.ToJson(controllerAssignmentSaveInfo)); - PlayerPrefs.Save(); - } - catch - { - } - return true; - } - - private bool ControllerAssignmentSaveDataExists() - { - if (!PlayerPrefs.HasKey(playerPrefsKey_controllerAssignments)) - { - return false; - } - if (string.IsNullOrEmpty(PlayerPrefs.GetString(playerPrefsKey_controllerAssignments))) - { - return false; - } - return true; - } - - private string GetBasePlayerPrefsKey(Player player) - { - return playerPrefsKeyPrefix + "|playerName=" + player.name; - } - - private string GetControllerMapPlayerPrefsKey(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId, int ppKeyVersion) - { - return string.Concat(GetBasePlayerPrefsKey(player) + "|dataType=ControllerMap", GetControllerMapPlayerPrefsKeyCommonSuffix(player, controllerIdentifier, categoryId, layoutId, ppKeyVersion)); - } - - private string GetControllerMapKnownActionIdsPlayerPrefsKey(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId, int ppKeyVersion) - { - return string.Concat(GetBasePlayerPrefsKey(player) + "|dataType=ControllerMap_KnownActionIds", GetControllerMapPlayerPrefsKeyCommonSuffix(player, controllerIdentifier, categoryId, layoutId, ppKeyVersion)); - } - - private static string GetControllerMapPlayerPrefsKeyCommonSuffix(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId, int ppKeyVersion) - { - string text = ""; - if (ppKeyVersion >= 2) - { - text = text + "|kv=" + ppKeyVersion; - } - text = text + "|controllerMapType=" + GetControllerMapType(controllerIdentifier.controllerType).Name; - text = text + "|categoryId=" + categoryId + "|layoutId=" + layoutId; - if (ppKeyVersion >= 2) - { - text = text + "|hardwareGuid=" + controllerIdentifier.hardwareTypeGuid.ToString(); - if (controllerIdentifier.hardwareTypeGuid == Guid.Empty) - { - text = text + "|hardwareIdentifier=" + controllerIdentifier.hardwareIdentifier; - } - if (controllerIdentifier.controllerType == ControllerType.Joystick) - { - text = text + "|duplicate=" + GetDuplicateIndex(player, controllerIdentifier); - } - } - else - { - text = text + "|hardwareIdentifier=" + controllerIdentifier.hardwareIdentifier; - if (controllerIdentifier.controllerType == ControllerType.Joystick) - { - text = text + "|hardwareGuid=" + controllerIdentifier.hardwareTypeGuid.ToString(); - if (ppKeyVersion >= 1) - { - text = text + "|duplicate=" + GetDuplicateIndex(player, controllerIdentifier); - } - } - } - return text; - } - - private string GetJoystickCalibrationMapPlayerPrefsKey(Joystick joystick) - { - return string.Concat(string.Concat(string.Concat(playerPrefsKeyPrefix + "|dataType=CalibrationMap", "|controllerType=", joystick.type.ToString()), "|hardwareIdentifier=", joystick.hardwareIdentifier), "|hardwareGuid=", joystick.hardwareTypeGuid.ToString()); - } - - private string GetInputBehaviorPlayerPrefsKey(Player player, int inputBehaviorId) - { - return string.Concat(GetBasePlayerPrefsKey(player) + "|dataType=InputBehavior", "|id=", inputBehaviorId.ToString()); - } - - private string GetControllerMapXml(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) - { - for (int num = 2; num >= 0; num--) - { - string controllerMapPlayerPrefsKey = GetControllerMapPlayerPrefsKey(player, controllerIdentifier, categoryId, layoutId, num); - if (PlayerPrefs.HasKey(controllerMapPlayerPrefsKey)) - { - return PlayerPrefs.GetString(controllerMapPlayerPrefsKey); - } - } - return null; - } - - private List GetControllerMapKnownActionIds(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) - { - List list = new List(); - string key = null; - bool flag = false; - for (int num = 2; num >= 0; num--) - { - key = GetControllerMapKnownActionIdsPlayerPrefsKey(player, controllerIdentifier, categoryId, layoutId, num); - if (PlayerPrefs.HasKey(key)) - { - flag = true; - break; - } - } - if (!flag) - { - return list; - } - string @string = PlayerPrefs.GetString(key); - if (string.IsNullOrEmpty(@string)) - { - return list; - } - string[] array = @string.Split(','); - for (int i = 0; i < array.Length; i++) - { - if (!string.IsNullOrEmpty(array[i]) && int.TryParse(array[i], out var result)) - { - list.Add(result); - } - } - return list; - } - - private string GetJoystickCalibrationMapXml(Joystick joystick) - { - string joystickCalibrationMapPlayerPrefsKey = GetJoystickCalibrationMapPlayerPrefsKey(joystick); - if (!PlayerPrefs.HasKey(joystickCalibrationMapPlayerPrefsKey)) - { - return string.Empty; - } - return PlayerPrefs.GetString(joystickCalibrationMapPlayerPrefsKey); - } - - private string GetInputBehaviorXml(Player player, int id) - { - string inputBehaviorPlayerPrefsKey = GetInputBehaviorPlayerPrefsKey(player, id); - if (!PlayerPrefs.HasKey(inputBehaviorPlayerPrefsKey)) - { - return string.Empty; - } - return PlayerPrefs.GetString(inputBehaviorPlayerPrefsKey); - } - - private void AddDefaultMappingsForNewActions(ControllerIdentifier controllerIdentifier, ControllerMap controllerMap, List knownActionIds) - { - if (controllerMap == null || knownActionIds == null || knownActionIds == null || knownActionIds.Count == 0) - { - return; - } - ControllerMap controllerMapInstance = ReInput.mapping.GetControllerMapInstance(controllerIdentifier, controllerMap.categoryId, controllerMap.layoutId); - if (controllerMapInstance == null) - { - return; - } - List list = new List(); - foreach (int allActionId in allActionIds) - { - if (!knownActionIds.Contains(allActionId)) - { - list.Add(allActionId); - } - } - if (list.Count == 0) - { - return; - } - foreach (ActionElementMap allMap in controllerMapInstance.AllMaps) - { - if (list.Contains(allMap.actionId) && !controllerMap.DoesElementAssignmentConflict(allMap)) - { - ElementAssignment elementAssignment = new ElementAssignment(controllerMap.controllerType, allMap.elementType, allMap.elementIdentifierId, allMap.axisRange, allMap.keyCode, allMap.modifierKeyFlags, allMap.actionId, allMap.axisContribution, allMap.invert); - controllerMap.CreateElementMap(elementAssignment); - } - } - } - - private Joystick FindJoystickPrecise(ControllerAssignmentSaveInfo.JoystickInfo joystickInfo) - { - if (joystickInfo == null) - { - return null; - } - if (joystickInfo.instanceGuid == Guid.Empty) - { - return null; - } - IList joysticks = ReInput.controllers.Joysticks; - for (int i = 0; i < joysticks.Count; i++) - { - if (joysticks[i].deviceInstanceGuid == joystickInfo.instanceGuid) - { - return joysticks[i]; - } - } - return null; - } - - private bool TryFindJoysticksImprecise(ControllerAssignmentSaveInfo.JoystickInfo joystickInfo, out List matches) - { - matches = null; - if (joystickInfo == null) - { - return false; - } - if (string.IsNullOrEmpty(joystickInfo.hardwareIdentifier)) - { - return false; - } - IList joysticks = ReInput.controllers.Joysticks; - for (int i = 0; i < joysticks.Count; i++) - { - if (string.Equals(joysticks[i].hardwareIdentifier, joystickInfo.hardwareIdentifier, StringComparison.OrdinalIgnoreCase)) - { - if (matches == null) - { - matches = new List(); - } - matches.Add(joysticks[i]); - } - } - return matches != null; - } - - private static int GetDuplicateIndex(Player player, ControllerIdentifier controllerIdentifier) - { - Controller controller = ReInput.controllers.GetController(controllerIdentifier); - if (controller == null) - { - return 0; - } - int num = 0; - foreach (Controller controller2 in player.controllers.Controllers) - { - if (controller2.type != controller.type) - { - continue; - } - bool flag = false; - if (controller.type == ControllerType.Joystick) - { - if ((controller2 as Joystick).hardwareTypeGuid != controller.hardwareTypeGuid) - { - continue; - } - if (controller.hardwareTypeGuid != Guid.Empty) - { - flag = true; - } - } - if (flag || !(controller2.hardwareIdentifier != controller.hardwareIdentifier)) - { - if (controller2 == controller) - { - return num; - } - num++; - } - } - return num; - } - - private void RefreshLayoutManager(int playerId) - { - ReInput.players.GetPlayer(playerId)?.controllers.maps.layoutManager.Apply(); - } - - private static Type GetControllerMapType(ControllerType controllerType) - { - switch (controllerType) - { - case ControllerType.Custom: - return typeof(CustomControllerMap); - case ControllerType.Joystick: - return typeof(JoystickMap); - case ControllerType.Keyboard: - return typeof(KeyboardMap); - case ControllerType.Mouse: - return typeof(MouseMap); - default: - Debug.LogWarning("Rewired: Unknown ControllerType " + controllerType); - return null; - } - } -} diff --git a/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs b/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs deleted file mode 100644 index 695aa76..0000000 --- a/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs +++ /dev/null @@ -1,57 +0,0 @@ -using UnityEngine; -using UnityEngine.UI; - -namespace Rewired.Demos.GamepadTemplateUI; - -[RequireComponent(typeof(Image))] -public class ControllerUIEffect : MonoBehaviour -{ - [SerializeField] - private Color _highlightColor = Color.white; - - private Image _image; - - private Color _color; - - private Color _origColor; - - private bool _isActive; - - private float _highlightAmount; - - private void Awake() - { - _image = GetComponent(); - _origColor = _image.color; - _color = _origColor; - } - - public void Activate(float amount) - { - amount = Mathf.Clamp01(amount); - if (!_isActive || amount != _highlightAmount) - { - _highlightAmount = amount; - _color = Color.Lerp(_origColor, _highlightColor, _highlightAmount); - _isActive = true; - RedrawImage(); - } - } - - public void Deactivate() - { - if (_isActive) - { - _color = _origColor; - _highlightAmount = 0f; - _isActive = false; - RedrawImage(); - } - } - - private void RedrawImage() - { - _image.color = _color; - _image.enabled = _isActive; - } -} diff --git a/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs b/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs deleted file mode 100644 index b59e6f8..0000000 --- a/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs +++ /dev/null @@ -1,186 +0,0 @@ -using UnityEngine; -using UnityEngine.UI; - -namespace Rewired.Demos.GamepadTemplateUI; - -[RequireComponent(typeof(Image))] -public class ControllerUIElement : MonoBehaviour -{ - [SerializeField] - private Color _highlightColor = Color.white; - - [SerializeField] - private ControllerUIEffect _positiveUIEffect; - - [SerializeField] - private ControllerUIEffect _negativeUIEffect; - - [SerializeField] - private Text _label; - - [SerializeField] - private Text _positiveLabel; - - [SerializeField] - private Text _negativeLabel; - - [SerializeField] - private ControllerUIElement[] _childElements = new ControllerUIElement[0]; - - private Image _image; - - private Color _color; - - private Color _origColor; - - private bool _isActive; - - private float _highlightAmount; - - private bool hasEffects - { - get - { - if (!(_positiveUIEffect != null)) - { - return _negativeUIEffect != null; - } - return true; - } - } - - private void Awake() - { - _image = GetComponent(); - _origColor = _image.color; - _color = _origColor; - ClearLabels(); - } - - public void Activate(float amount) - { - amount = Mathf.Clamp(amount, -1f, 1f); - if (hasEffects) - { - if (amount < 0f && _negativeUIEffect != null) - { - _negativeUIEffect.Activate(Mathf.Abs(amount)); - } - if (amount > 0f && _positiveUIEffect != null) - { - _positiveUIEffect.Activate(Mathf.Abs(amount)); - } - } - else - { - if (_isActive && amount == _highlightAmount) - { - return; - } - _highlightAmount = amount; - _color = Color.Lerp(_origColor, _highlightColor, _highlightAmount); - } - _isActive = true; - RedrawImage(); - if (_childElements.Length == 0) - { - return; - } - for (int i = 0; i < _childElements.Length; i++) - { - if (!(_childElements[i] == null)) - { - _childElements[i].Activate(amount); - } - } - } - - public void Deactivate() - { - if (!_isActive) - { - return; - } - _color = _origColor; - _highlightAmount = 0f; - if (_positiveUIEffect != null) - { - _positiveUIEffect.Deactivate(); - } - if (_negativeUIEffect != null) - { - _negativeUIEffect.Deactivate(); - } - _isActive = false; - RedrawImage(); - if (_childElements.Length == 0) - { - return; - } - for (int i = 0; i < _childElements.Length; i++) - { - if (!(_childElements[i] == null)) - { - _childElements[i].Deactivate(); - } - } - } - - public void SetLabel(string text, AxisRange labelType) - { - Text text2 = labelType switch - { - AxisRange.Full => _label, - AxisRange.Positive => _positiveLabel, - AxisRange.Negative => _negativeLabel, - _ => null, - }; - if (text2 != null) - { - text2.text = text; - } - if (_childElements.Length == 0) - { - return; - } - for (int i = 0; i < _childElements.Length; i++) - { - if (!(_childElements[i] == null)) - { - _childElements[i].SetLabel(text, labelType); - } - } - } - - public void ClearLabels() - { - if (_label != null) - { - _label.text = string.Empty; - } - if (_positiveLabel != null) - { - _positiveLabel.text = string.Empty; - } - if (_negativeLabel != null) - { - _negativeLabel.text = string.Empty; - } - if (_childElements.Length == 0) - { - return; - } - for (int i = 0; i < _childElements.Length; i++) - { - if (!(_childElements[i] == null)) - { - _childElements[i].ClearLabels(); - } - } - } - - private void RedrawImage() - { - _image.color = _color; - } -} diff --git a/Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs b/Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs deleted file mode 100644 index e56617c..0000000 --- a/Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs +++ /dev/null @@ -1,417 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace Rewired.Demos.GamepadTemplateUI; - -public class GamepadTemplateUI : MonoBehaviour -{ - private class Stick - { - private RectTransform _transform; - - private Vector2 _origPosition; - - private int _xAxisElementId = -1; - - private int _yAxisElementId = -1; - - public Vector2 position - { - get - { - if (!(_transform != null)) - { - return Vector2.zero; - } - return _transform.anchoredPosition - _origPosition; - } - set - { - if (!(_transform == null)) - { - _transform.anchoredPosition = _origPosition + value; - } - } - } - - public Stick(RectTransform transform, int xAxisElementId, int yAxisElementId) - { - if (!(transform == null)) - { - _transform = transform; - _origPosition = _transform.anchoredPosition; - _xAxisElementId = xAxisElementId; - _yAxisElementId = yAxisElementId; - } - } - - public void Reset() - { - if (!(_transform == null)) - { - _transform.anchoredPosition = _origPosition; - } - } - - public bool ContainsElement(int elementId) - { - if (_transform == null) - { - return false; - } - if (elementId != _xAxisElementId) - { - return elementId == _yAxisElementId; - } - return true; - } - - public void SetAxisPosition(int elementId, float value) - { - if (!(_transform == null)) - { - Vector2 vector = position; - if (elementId == _xAxisElementId) - { - vector.x = value; - } - else if (elementId == _yAxisElementId) - { - vector.y = value; - } - position = vector; - } - } - } - - private class UIElement - { - public int id; - - public ControllerUIElement element; - - public UIElement(int id, ControllerUIElement element) - { - this.id = id; - this.element = element; - } - } - - private const float stickRadius = 20f; - - public int playerId; - - [SerializeField] - private RectTransform leftStick; - - [SerializeField] - private RectTransform rightStick; - - [SerializeField] - private ControllerUIElement leftStickX; - - [SerializeField] - private ControllerUIElement leftStickY; - - [SerializeField] - private ControllerUIElement leftStickButton; - - [SerializeField] - private ControllerUIElement rightStickX; - - [SerializeField] - private ControllerUIElement rightStickY; - - [SerializeField] - private ControllerUIElement rightStickButton; - - [SerializeField] - private ControllerUIElement actionBottomRow1; - - [SerializeField] - private ControllerUIElement actionBottomRow2; - - [SerializeField] - private ControllerUIElement actionBottomRow3; - - [SerializeField] - private ControllerUIElement actionTopRow1; - - [SerializeField] - private ControllerUIElement actionTopRow2; - - [SerializeField] - private ControllerUIElement actionTopRow3; - - [SerializeField] - private ControllerUIElement leftShoulder; - - [SerializeField] - private ControllerUIElement leftTrigger; - - [SerializeField] - private ControllerUIElement rightShoulder; - - [SerializeField] - private ControllerUIElement rightTrigger; - - [SerializeField] - private ControllerUIElement center1; - - [SerializeField] - private ControllerUIElement center2; - - [SerializeField] - private ControllerUIElement center3; - - [SerializeField] - private ControllerUIElement dPadUp; - - [SerializeField] - private ControllerUIElement dPadRight; - - [SerializeField] - private ControllerUIElement dPadDown; - - [SerializeField] - private ControllerUIElement dPadLeft; - - private UIElement[] _uiElementsArray; - - private Dictionary _uiElements = new Dictionary(); - - private IList _tempTargetList = new List(2); - - private Stick[] _sticks; - - private Player player => ReInput.players.GetPlayer(playerId); - - private void Awake() - { - _uiElementsArray = new UIElement[23] - { - new UIElement(0, leftStickX), - new UIElement(1, leftStickY), - new UIElement(17, leftStickButton), - new UIElement(2, rightStickX), - new UIElement(3, rightStickY), - new UIElement(18, rightStickButton), - new UIElement(4, actionBottomRow1), - new UIElement(5, actionBottomRow2), - new UIElement(6, actionBottomRow3), - new UIElement(7, actionTopRow1), - new UIElement(8, actionTopRow2), - new UIElement(9, actionTopRow3), - new UIElement(14, center1), - new UIElement(15, center2), - new UIElement(16, center3), - new UIElement(19, dPadUp), - new UIElement(20, dPadRight), - new UIElement(21, dPadDown), - new UIElement(22, dPadLeft), - new UIElement(10, leftShoulder), - new UIElement(11, leftTrigger), - new UIElement(12, rightShoulder), - new UIElement(13, rightTrigger) - }; - for (int i = 0; i < _uiElementsArray.Length; i++) - { - _uiElements.Add(_uiElementsArray[i].id, _uiElementsArray[i].element); - } - _sticks = new Stick[2] - { - new Stick(leftStick, 0, 1), - new Stick(rightStick, 2, 3) - }; - ReInput.ControllerConnectedEvent += OnControllerConnected; - ReInput.ControllerDisconnectedEvent += OnControllerDisconnected; - } - - private void Start() - { - if (ReInput.isReady) - { - DrawLabels(); - } - } - - private void OnDestroy() - { - ReInput.ControllerConnectedEvent -= OnControllerConnected; - ReInput.ControllerDisconnectedEvent -= OnControllerDisconnected; - } - - private void Update() - { - if (ReInput.isReady) - { - DrawActiveElements(); - } - } - - private void DrawActiveElements() - { - for (int i = 0; i < _uiElementsArray.Length; i++) - { - _uiElementsArray[i].element.Deactivate(); - } - for (int j = 0; j < _sticks.Length; j++) - { - _sticks[j].Reset(); - } - IList actions = ReInput.mapping.Actions; - for (int k = 0; k < actions.Count; k++) - { - ActivateElements(player, actions[k].id); - } - } - - private void ActivateElements(Player player, int actionId) - { - float axis = player.GetAxis(actionId); - if (axis == 0f) - { - return; - } - IList currentInputSources = player.GetCurrentInputSources(actionId); - for (int i = 0; i < currentInputSources.Count; i++) - { - InputActionSourceData inputActionSourceData = currentInputSources[i]; - IGamepadTemplate template = inputActionSourceData.controller.GetTemplate(); - if (template == null) - { - continue; - } - template.GetElementTargets(inputActionSourceData.actionElementMap, _tempTargetList); - for (int j = 0; j < _tempTargetList.Count; j++) - { - ControllerTemplateElementTarget controllerTemplateElementTarget = _tempTargetList[j]; - int id = controllerTemplateElementTarget.element.id; - ControllerUIElement controllerUIElement = _uiElements[id]; - if (controllerTemplateElementTarget.elementType == ControllerTemplateElementType.Axis) - { - controllerUIElement.Activate(axis); - } - else if (controllerTemplateElementTarget.elementType == ControllerTemplateElementType.Button && (player.GetButton(actionId) || player.GetNegativeButton(actionId))) - { - controllerUIElement.Activate(1f); - } - GetStick(id)?.SetAxisPosition(id, axis * 20f); - } - } - } - - private void DrawLabels() - { - for (int i = 0; i < _uiElementsArray.Length; i++) - { - _uiElementsArray[i].element.ClearLabels(); - } - IList actions = ReInput.mapping.Actions; - for (int j = 0; j < actions.Count; j++) - { - DrawLabels(player, actions[j]); - } - } - - private void DrawLabels(Player player, InputAction action) - { - Controller firstControllerWithTemplate = player.controllers.GetFirstControllerWithTemplate(); - if (firstControllerWithTemplate == null) - { - return; - } - IGamepadTemplate template = firstControllerWithTemplate.GetTemplate(); - ControllerMap map = player.controllers.maps.GetMap(firstControllerWithTemplate, "Default", "Default"); - if (map != null) - { - for (int i = 0; i < _uiElementsArray.Length; i++) - { - ControllerUIElement element = _uiElementsArray[i].element; - int id = _uiElementsArray[i].id; - IControllerTemplateElement element2 = template.GetElement(id); - DrawLabel(element, action, map, template, element2); - } - } - } - - private void DrawLabel(ControllerUIElement uiElement, InputAction action, ControllerMap controllerMap, IControllerTemplate template, IControllerTemplateElement element) - { - if (element.source == null) - { - return; - } - if (element.source.type == ControllerTemplateElementSourceType.Axis) - { - IControllerTemplateAxisSource controllerTemplateAxisSource = element.source as IControllerTemplateAxisSource; - ActionElementMap firstElementMapWithElementTarget; - if (controllerTemplateAxisSource.splitAxis) - { - firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateAxisSource.positiveTarget, action.id, skipDisabledMaps: true); - if (firstElementMapWithElementTarget != null) - { - uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Positive); - } - firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateAxisSource.negativeTarget, action.id, skipDisabledMaps: true); - if (firstElementMapWithElementTarget != null) - { - uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Negative); - } - return; - } - firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateAxisSource.fullTarget, action.id, skipDisabledMaps: true); - if (firstElementMapWithElementTarget != null) - { - uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Full); - return; - } - firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(new ControllerElementTarget(controllerTemplateAxisSource.fullTarget) - { - axisRange = AxisRange.Positive - }, action.id, skipDisabledMaps: true); - if (firstElementMapWithElementTarget != null) - { - uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Positive); - } - firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(new ControllerElementTarget(controllerTemplateAxisSource.fullTarget) - { - axisRange = AxisRange.Negative - }, action.id, skipDisabledMaps: true); - if (firstElementMapWithElementTarget != null) - { - uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Negative); - } - } - else if (element.source.type == ControllerTemplateElementSourceType.Button) - { - IControllerTemplateButtonSource controllerTemplateButtonSource = element.source as IControllerTemplateButtonSource; - ActionElementMap firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateButtonSource.target, action.id, skipDisabledMaps: true); - if (firstElementMapWithElementTarget != null) - { - uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Full); - } - } - } - - private Stick GetStick(int elementId) - { - for (int i = 0; i < _sticks.Length; i++) - { - if (_sticks[i].ContainsElement(elementId)) - { - return _sticks[i]; - } - } - return null; - } - - private void OnControllerConnected(ControllerStatusChangedEventArgs args) - { - DrawLabels(); - } - - private void OnControllerDisconnected(ControllerStatusChangedEventArgs args) - { - DrawLabels(); - } -} diff --git a/Rewired/Rewired.Demos/Bullet.cs b/Rewired/Rewired.Demos/Bullet.cs deleted file mode 100644 index bb521c8..0000000 --- a/Rewired/Rewired.Demos/Bullet.cs +++ /dev/null @@ -1,30 +0,0 @@ -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class Bullet : MonoBehaviour -{ - public float lifeTime = 3f; - - private bool die; - - private float deathTime; - - private void Start() - { - if (lifeTime > 0f) - { - deathTime = Time.time + lifeTime; - die = true; - } - } - - private void Update() - { - if (die && Time.time >= deathTime) - { - Object.Destroy(base.gameObject); - } - } -} diff --git a/Rewired/Rewired.Demos/ControlRemappingDemo1.cs b/Rewired/Rewired.Demos/ControlRemappingDemo1.cs deleted file mode 100644 index b0e4f51..0000000 --- a/Rewired/Rewired.Demos/ControlRemappingDemo1.cs +++ /dev/null @@ -1,1797 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class ControlRemappingDemo1 : MonoBehaviour -{ - private class ControllerSelection - { - private int _id; - - private int _idPrev; - - private ControllerType _type; - - private ControllerType _typePrev; - - public int id - { - get - { - return _id; - } - set - { - _idPrev = _id; - _id = value; - } - } - - public ControllerType type - { - get - { - return _type; - } - set - { - _typePrev = _type; - _type = value; - } - } - - public int idPrev => _idPrev; - - public ControllerType typePrev => _typePrev; - - public bool hasSelection => _id >= 0; - - public ControllerSelection() - { - Clear(); - } - - public void Set(int id, ControllerType type) - { - this.id = id; - this.type = type; - } - - public void Clear() - { - _id = -1; - _idPrev = -1; - _type = ControllerType.Joystick; - _typePrev = ControllerType.Joystick; - } - } - - private class DialogHelper - { - public enum DialogType - { - None = 0, - JoystickConflict = 1, - ElementConflict = 2, - KeyConflict = 3, - DeleteAssignmentConfirmation = 10, - AssignElement = 11 - } - - private const float openBusyDelay = 0.25f; - - private const float closeBusyDelay = 0.1f; - - private DialogType _type; - - private bool _enabled; - - private float _busyTime; - - private bool _busyTimerRunning; - - private Action drawWindowDelegate; - - private GUI.WindowFunction drawWindowFunction; - - private WindowProperties windowProperties; - - private int currentActionId; - - private Action resultCallback; - - private float busyTimer - { - get - { - if (!_busyTimerRunning) - { - return 0f; - } - return _busyTime - Time.realtimeSinceStartup; - } - } - - public bool enabled - { - get - { - return _enabled; - } - set - { - if (value) - { - if (_type != 0) - { - StateChanged(0.25f); - } - } - else - { - _enabled = value; - _type = DialogType.None; - StateChanged(0.1f); - } - } - } - - public DialogType type - { - get - { - if (!_enabled) - { - return DialogType.None; - } - return _type; - } - set - { - if (value == DialogType.None) - { - _enabled = false; - StateChanged(0.1f); - } - else - { - _enabled = true; - StateChanged(0.25f); - } - _type = value; - } - } - - public bool busy => _busyTimerRunning; - - public DialogHelper() - { - drawWindowDelegate = DrawWindow; - drawWindowFunction = drawWindowDelegate.Invoke; - } - - public void StartModal(int queueActionId, DialogType type, WindowProperties windowProperties, Action resultCallback) - { - StartModal(queueActionId, type, windowProperties, resultCallback, -1f); - } - - public void StartModal(int queueActionId, DialogType type, WindowProperties windowProperties, Action resultCallback, float openBusyDelay) - { - currentActionId = queueActionId; - this.windowProperties = windowProperties; - this.type = type; - this.resultCallback = resultCallback; - if (openBusyDelay >= 0f) - { - StateChanged(openBusyDelay); - } - } - - public void Update() - { - Draw(); - UpdateTimers(); - } - - public void Draw() - { - if (_enabled) - { - bool flag = GUI.enabled; - GUI.enabled = true; - GUILayout.Window(windowProperties.windowId, windowProperties.rect, drawWindowFunction, windowProperties.title); - GUI.FocusWindow(windowProperties.windowId); - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - } - - public void DrawConfirmButton() - { - DrawConfirmButton("Confirm"); - } - - public void DrawConfirmButton(string title) - { - bool flag = GUI.enabled; - if (busy) - { - GUI.enabled = false; - } - if (GUILayout.Button(title)) - { - Confirm(UserResponse.Confirm); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - public void DrawConfirmButton(UserResponse response) - { - DrawConfirmButton(response, "Confirm"); - } - - public void DrawConfirmButton(UserResponse response, string title) - { - bool flag = GUI.enabled; - if (busy) - { - GUI.enabled = false; - } - if (GUILayout.Button(title)) - { - Confirm(response); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - public void DrawCancelButton() - { - DrawCancelButton("Cancel"); - } - - public void DrawCancelButton(string title) - { - bool flag = GUI.enabled; - if (busy) - { - GUI.enabled = false; - } - if (GUILayout.Button(title)) - { - Cancel(); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - public void Confirm() - { - Confirm(UserResponse.Confirm); - } - - public void Confirm(UserResponse response) - { - resultCallback(currentActionId, response); - Close(); - } - - public void Cancel() - { - resultCallback(currentActionId, UserResponse.Cancel); - Close(); - } - - private void DrawWindow(int windowId) - { - windowProperties.windowDrawDelegate(windowProperties.title, windowProperties.message); - } - - private void UpdateTimers() - { - if (_busyTimerRunning && busyTimer <= 0f) - { - _busyTimerRunning = false; - } - } - - private void StartBusyTimer(float time) - { - _busyTime = time + Time.realtimeSinceStartup; - _busyTimerRunning = true; - } - - private void Close() - { - Reset(); - StateChanged(0.1f); - } - - private void StateChanged(float delay) - { - StartBusyTimer(delay); - } - - private void Reset() - { - _enabled = false; - _type = DialogType.None; - currentActionId = -1; - resultCallback = null; - } - - private void ResetTimers() - { - _busyTimerRunning = false; - } - - public void FullReset() - { - Reset(); - ResetTimers(); - } - } - - private abstract class QueueEntry - { - public enum State - { - Waiting, - Confirmed, - Canceled - } - - private static int uidCounter; - - public int id { get; protected set; } - - public QueueActionType queueActionType { get; protected set; } - - public State state { get; protected set; } - - public UserResponse response { get; protected set; } - - protected static int nextId - { - get - { - int result = uidCounter; - uidCounter++; - return result; - } - } - - public QueueEntry(QueueActionType queueActionType) - { - id = nextId; - this.queueActionType = queueActionType; - } - - public void Confirm(UserResponse response) - { - state = State.Confirmed; - this.response = response; - } - - public void Cancel() - { - state = State.Canceled; - } - } - - private class JoystickAssignmentChange : QueueEntry - { - public int playerId { get; private set; } - - public int joystickId { get; private set; } - - public bool assign { get; private set; } - - public JoystickAssignmentChange(int newPlayerId, int joystickId, bool assign) - : base(QueueActionType.JoystickAssignment) - { - playerId = newPlayerId; - this.joystickId = joystickId; - this.assign = assign; - } - } - - private class ElementAssignmentChange : QueueEntry - { - public ElementAssignmentChangeType changeType { get; set; } - - public InputMapper.Context context { get; private set; } - - public ElementAssignmentChange(ElementAssignmentChangeType changeType, InputMapper.Context context) - : base(QueueActionType.ElementAssignment) - { - this.changeType = changeType; - this.context = context; - } - - public ElementAssignmentChange(ElementAssignmentChange other) - : this(other.changeType, other.context.Clone()) - { - } - } - - private class FallbackJoystickIdentification : QueueEntry - { - public int joystickId { get; private set; } - - public string joystickName { get; private set; } - - public FallbackJoystickIdentification(int joystickId, string joystickName) - : base(QueueActionType.FallbackJoystickIdentification) - { - this.joystickId = joystickId; - this.joystickName = joystickName; - } - } - - private class Calibration : QueueEntry - { - public int selectedElementIdentifierId; - - public bool recording; - - public Player player { get; private set; } - - public ControllerType controllerType { get; private set; } - - public Joystick joystick { get; private set; } - - public CalibrationMap calibrationMap { get; private set; } - - public Calibration(Player player, Joystick joystick, CalibrationMap calibrationMap) - : base(QueueActionType.Calibrate) - { - this.player = player; - this.joystick = joystick; - this.calibrationMap = calibrationMap; - selectedElementIdentifierId = -1; - } - } - - private struct WindowProperties - { - public int windowId; - - public Rect rect; - - public Action windowDrawDelegate; - - public string title; - - public string message; - } - - private enum QueueActionType - { - None, - JoystickAssignment, - ElementAssignment, - FallbackJoystickIdentification, - Calibrate - } - - private enum ElementAssignmentChangeType - { - Add, - Replace, - Remove, - ReassignOrRemove, - ConflictCheck - } - - public enum UserResponse - { - Confirm, - Cancel, - Custom1, - Custom2 - } - - private const float defaultModalWidth = 250f; - - private const float defaultModalHeight = 200f; - - private const float assignmentTimeout = 5f; - - private DialogHelper dialog; - - private InputMapper inputMapper = new InputMapper(); - - private InputMapper.ConflictFoundEventData conflictFoundEventData; - - private bool guiState; - - private bool busy; - - private bool pageGUIState; - - private Player selectedPlayer; - - private int selectedMapCategoryId; - - private ControllerSelection selectedController; - - private ControllerMap selectedMap; - - private bool showMenu; - - private bool startListening; - - private Vector2 actionScrollPos; - - private Vector2 calibrateScrollPos; - - private Queue actionQueue; - - private bool setupFinished; - - [NonSerialized] - private bool initialized; - - private bool isCompiling; - - private GUIStyle style_wordWrap; - - private GUIStyle style_centeredBox; - - private void Awake() - { - inputMapper.options.timeout = 5f; - inputMapper.options.ignoreMouseXAxis = true; - inputMapper.options.ignoreMouseYAxis = true; - Initialize(); - } - - private void OnEnable() - { - Subscribe(); - } - - private void OnDisable() - { - Unsubscribe(); - } - - private void Initialize() - { - dialog = new DialogHelper(); - actionQueue = new Queue(); - selectedController = new ControllerSelection(); - ReInput.ControllerConnectedEvent += JoystickConnected; - ReInput.ControllerPreDisconnectEvent += JoystickPreDisconnect; - ReInput.ControllerDisconnectedEvent += JoystickDisconnected; - ResetAll(); - initialized = true; - ReInput.userDataStore.Load(); - if (ReInput.unityJoystickIdentificationRequired) - { - IdentifyAllJoysticks(); - } - } - - private void Setup() - { - if (!setupFinished) - { - style_wordWrap = new GUIStyle(GUI.skin.label); - style_wordWrap.wordWrap = true; - style_centeredBox = new GUIStyle(GUI.skin.box); - style_centeredBox.alignment = TextAnchor.MiddleCenter; - setupFinished = true; - } - } - - private void Subscribe() - { - Unsubscribe(); - inputMapper.ConflictFoundEvent += OnConflictFound; - inputMapper.StoppedEvent += OnStopped; - } - - private void Unsubscribe() - { - inputMapper.RemoveAllEventListeners(); - } - - public void OnGUI() - { - if (initialized) - { - Setup(); - HandleMenuControl(); - if (!showMenu) - { - DrawInitialScreen(); - return; - } - SetGUIStateStart(); - ProcessQueue(); - DrawPage(); - ShowDialog(); - SetGUIStateEnd(); - busy = false; - } - } - - private void HandleMenuControl() - { - if (!dialog.enabled && Event.current.type == EventType.Layout && ReInput.players.GetSystemPlayer().GetButtonDown("Menu")) - { - if (showMenu) - { - ReInput.userDataStore.Save(); - Close(); - } - else - { - Open(); - } - } - } - - private void Close() - { - ClearWorkingVars(); - showMenu = false; - } - - private void Open() - { - showMenu = true; - } - - private void DrawInitialScreen() - { - ActionElementMap firstElementMapWithAction = ReInput.players.GetSystemPlayer().controllers.maps.GetFirstElementMapWithAction("Menu", skipDisabledMaps: true); - GUIContent content = ((firstElementMapWithAction == null) ? new GUIContent("There is no element assigned to open the menu!") : new GUIContent("Press " + firstElementMapWithAction.elementIdentifierName + " to open the menu.")); - GUILayout.BeginArea(GetScreenCenteredRect(300f, 50f)); - GUILayout.Box(content, style_centeredBox, GUILayout.ExpandHeight(expand: true), GUILayout.ExpandWidth(expand: true)); - GUILayout.EndArea(); - } - - private void DrawPage() - { - if (GUI.enabled != pageGUIState) - { - GUI.enabled = pageGUIState; - } - GUILayout.BeginArea(new Rect(((float)Screen.width - (float)Screen.width * 0.9f) * 0.5f, ((float)Screen.height - (float)Screen.height * 0.9f) * 0.5f, (float)Screen.width * 0.9f, (float)Screen.height * 0.9f)); - DrawPlayerSelector(); - DrawJoystickSelector(); - DrawMouseAssignment(); - DrawControllerSelector(); - DrawCalibrateButton(); - DrawMapCategories(); - actionScrollPos = GUILayout.BeginScrollView(actionScrollPos); - DrawCategoryActions(); - GUILayout.EndScrollView(); - GUILayout.EndArea(); - } - - private void DrawPlayerSelector() - { - if (ReInput.players.allPlayerCount == 0) - { - GUILayout.Label("There are no players."); - return; - } - GUILayout.Space(15f); - GUILayout.Label("Players:"); - GUILayout.BeginHorizontal(); - foreach (Player player in ReInput.players.GetPlayers(includeSystemPlayer: true)) - { - if (selectedPlayer == null) - { - selectedPlayer = player; - } - bool flag = ((player == selectedPlayer) ? true : false); - bool flag2 = GUILayout.Toggle(flag, (player.descriptiveName != string.Empty) ? player.descriptiveName : player.name, "Button", GUILayout.ExpandWidth(expand: false)); - if (flag2 != flag && flag2) - { - selectedPlayer = player; - selectedController.Clear(); - selectedMapCategoryId = -1; - } - } - GUILayout.EndHorizontal(); - } - - private void DrawMouseAssignment() - { - bool flag = GUI.enabled; - if (selectedPlayer == null) - { - GUI.enabled = false; - } - GUILayout.Space(15f); - GUILayout.Label("Assign Mouse:"); - GUILayout.BeginHorizontal(); - bool flag2 = ((selectedPlayer != null && selectedPlayer.controllers.hasMouse) ? true : false); - bool flag3 = GUILayout.Toggle(flag2, "Assign Mouse", "Button", GUILayout.ExpandWidth(expand: false)); - if (flag3 != flag2) - { - if (flag3) - { - selectedPlayer.controllers.hasMouse = true; - foreach (Player player in ReInput.players.Players) - { - if (player != selectedPlayer) - { - player.controllers.hasMouse = false; - } - } - } - else - { - selectedPlayer.controllers.hasMouse = false; - } - } - GUILayout.EndHorizontal(); - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DrawJoystickSelector() - { - bool flag = GUI.enabled; - if (selectedPlayer == null) - { - GUI.enabled = false; - } - GUILayout.Space(15f); - GUILayout.Label("Assign Joysticks:"); - GUILayout.BeginHorizontal(); - bool flag2 = ((selectedPlayer == null || selectedPlayer.controllers.joystickCount == 0) ? true : false); - bool flag3 = GUILayout.Toggle(flag2, "None", "Button", GUILayout.ExpandWidth(expand: false)); - if (flag3 != flag2) - { - selectedPlayer.controllers.ClearControllersOfType(ControllerType.Joystick); - ControllerSelectionChanged(); - } - if (selectedPlayer != null) - { - foreach (Joystick joystick in ReInput.controllers.Joysticks) - { - flag2 = selectedPlayer.controllers.ContainsController(joystick); - flag3 = GUILayout.Toggle(flag2, joystick.name, "Button", GUILayout.ExpandWidth(expand: false)); - if (flag3 != flag2) - { - EnqueueAction(new JoystickAssignmentChange(selectedPlayer.id, joystick.id, flag3)); - } - } - } - GUILayout.EndHorizontal(); - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DrawControllerSelector() - { - if (selectedPlayer == null) - { - return; - } - bool flag = GUI.enabled; - GUILayout.Space(15f); - GUILayout.Label("Controller to Map:"); - GUILayout.BeginHorizontal(); - if (!selectedController.hasSelection) - { - selectedController.Set(0, ControllerType.Keyboard); - ControllerSelectionChanged(); - } - bool flag2 = selectedController.type == ControllerType.Keyboard; - if (GUILayout.Toggle(flag2, "Keyboard", "Button", GUILayout.ExpandWidth(expand: false)) != flag2) - { - selectedController.Set(0, ControllerType.Keyboard); - ControllerSelectionChanged(); - } - if (!selectedPlayer.controllers.hasMouse) - { - GUI.enabled = false; - } - flag2 = selectedController.type == ControllerType.Mouse; - if (GUILayout.Toggle(flag2, "Mouse", "Button", GUILayout.ExpandWidth(expand: false)) != flag2) - { - selectedController.Set(0, ControllerType.Mouse); - ControllerSelectionChanged(); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - foreach (Joystick joystick in selectedPlayer.controllers.Joysticks) - { - flag2 = selectedController.type == ControllerType.Joystick && selectedController.id == joystick.id; - if (GUILayout.Toggle(flag2, joystick.name, "Button", GUILayout.ExpandWidth(expand: false)) != flag2) - { - selectedController.Set(joystick.id, ControllerType.Joystick); - ControllerSelectionChanged(); - } - } - GUILayout.EndHorizontal(); - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DrawCalibrateButton() - { - if (selectedPlayer == null) - { - return; - } - bool flag = GUI.enabled; - GUILayout.Space(10f); - Controller controller = (selectedController.hasSelection ? selectedPlayer.controllers.GetController(selectedController.type, selectedController.id) : null); - if (controller == null || selectedController.type != ControllerType.Joystick) - { - GUI.enabled = false; - GUILayout.Button("Select a controller to calibrate", GUILayout.ExpandWidth(expand: false)); - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - else if (GUILayout.Button("Calibrate " + controller.name, GUILayout.ExpandWidth(expand: false)) && controller is Joystick joystick) - { - CalibrationMap calibrationMap = joystick.calibrationMap; - if (calibrationMap != null) - { - EnqueueAction(new Calibration(selectedPlayer, joystick, calibrationMap)); - } - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DrawMapCategories() - { - if (selectedPlayer == null || !selectedController.hasSelection) - { - return; - } - bool flag = GUI.enabled; - GUILayout.Space(15f); - GUILayout.Label("Categories:"); - GUILayout.BeginHorizontal(); - foreach (InputMapCategory userAssignableMapCategory in ReInput.mapping.UserAssignableMapCategories) - { - if (!selectedPlayer.controllers.maps.ContainsMapInCategory(selectedController.type, userAssignableMapCategory.id)) - { - GUI.enabled = false; - } - else if (selectedMapCategoryId < 0) - { - selectedMapCategoryId = userAssignableMapCategory.id; - selectedMap = selectedPlayer.controllers.maps.GetFirstMapInCategory(selectedController.type, selectedController.id, userAssignableMapCategory.id); - } - bool flag2 = ((userAssignableMapCategory.id == selectedMapCategoryId) ? true : false); - if (GUILayout.Toggle(flag2, (userAssignableMapCategory.descriptiveName != string.Empty) ? userAssignableMapCategory.descriptiveName : userAssignableMapCategory.name, "Button", GUILayout.ExpandWidth(expand: false)) != flag2) - { - selectedMapCategoryId = userAssignableMapCategory.id; - selectedMap = selectedPlayer.controllers.maps.GetFirstMapInCategory(selectedController.type, selectedController.id, userAssignableMapCategory.id); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - GUILayout.EndHorizontal(); - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DrawCategoryActions() - { - if (selectedPlayer == null || selectedMapCategoryId < 0) - { - return; - } - bool flag = GUI.enabled; - if (selectedMap == null) - { - return; - } - GUILayout.Space(15f); - GUILayout.Label("Actions:"); - InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(selectedMapCategoryId); - if (mapCategory == null) - { - return; - } - InputCategory actionCategory = ReInput.mapping.GetActionCategory(mapCategory.name); - if (actionCategory == null) - { - return; - } - float width = 150f; - foreach (InputAction item in ReInput.mapping.ActionsInCategory(actionCategory.id)) - { - string text = ((item.descriptiveName != string.Empty) ? item.descriptiveName : item.name); - if (item.type == InputActionType.Button) - { - GUILayout.BeginHorizontal(); - GUILayout.Label(text, GUILayout.Width(width)); - DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap); - foreach (ActionElementMap allMap in selectedMap.AllMaps) - { - if (allMap.actionId == item.id) - { - DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap, allMap); - } - } - GUILayout.EndHorizontal(); - } - else - { - if (item.type != 0) - { - continue; - } - if (selectedController.type != 0) - { - GUILayout.BeginHorizontal(); - GUILayout.Label(text, GUILayout.Width(width)); - DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Full, selectedController, selectedMap); - foreach (ActionElementMap allMap2 in selectedMap.AllMaps) - { - if (allMap2.actionId == item.id && allMap2.elementType != ControllerElementType.Button && allMap2.axisType != AxisType.Split) - { - DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Full, selectedController, selectedMap, allMap2); - DrawInvertButton(selectedPlayer.id, item, Pole.Positive, selectedController, selectedMap, allMap2); - } - } - GUILayout.EndHorizontal(); - } - string text2 = ((item.positiveDescriptiveName != string.Empty) ? item.positiveDescriptiveName : (item.descriptiveName + " +")); - GUILayout.BeginHorizontal(); - GUILayout.Label(text2, GUILayout.Width(width)); - DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap); - foreach (ActionElementMap allMap3 in selectedMap.AllMaps) - { - if (allMap3.actionId == item.id && allMap3.axisContribution == Pole.Positive && allMap3.axisType != AxisType.Normal) - { - DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap, allMap3); - } - } - GUILayout.EndHorizontal(); - string text3 = ((item.negativeDescriptiveName != string.Empty) ? item.negativeDescriptiveName : (item.descriptiveName + " -")); - GUILayout.BeginHorizontal(); - GUILayout.Label(text3, GUILayout.Width(width)); - DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Negative, selectedController, selectedMap); - foreach (ActionElementMap allMap4 in selectedMap.AllMaps) - { - if (allMap4.actionId == item.id && allMap4.axisContribution == Pole.Negative && allMap4.axisType != AxisType.Normal) - { - DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Negative, selectedController, selectedMap, allMap4); - } - } - GUILayout.EndHorizontal(); - } - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DrawActionAssignmentButton(int playerId, InputAction action, AxisRange actionRange, ControllerSelection controller, ControllerMap controllerMap, ActionElementMap elementMap) - { - if (GUILayout.Button(elementMap.elementIdentifierName, GUILayout.ExpandWidth(expand: false), GUILayout.MinWidth(30f))) - { - InputMapper.Context context = new InputMapper.Context - { - actionId = action.id, - actionRange = actionRange, - controllerMap = controllerMap, - actionElementMapToReplace = elementMap - }; - EnqueueAction(new ElementAssignmentChange(ElementAssignmentChangeType.ReassignOrRemove, context)); - startListening = true; - } - GUILayout.Space(4f); - } - - private void DrawInvertButton(int playerId, InputAction action, Pole actionAxisContribution, ControllerSelection controller, ControllerMap controllerMap, ActionElementMap elementMap) - { - bool invert = elementMap.invert; - bool flag = GUILayout.Toggle(invert, "Invert", GUILayout.ExpandWidth(expand: false)); - if (flag != invert) - { - elementMap.invert = flag; - } - GUILayout.Space(10f); - } - - private void DrawAddActionMapButton(int playerId, InputAction action, AxisRange actionRange, ControllerSelection controller, ControllerMap controllerMap) - { - if (GUILayout.Button("Add...", GUILayout.ExpandWidth(expand: false))) - { - InputMapper.Context context = new InputMapper.Context - { - actionId = action.id, - actionRange = actionRange, - controllerMap = controllerMap - }; - EnqueueAction(new ElementAssignmentChange(ElementAssignmentChangeType.Add, context)); - startListening = true; - } - GUILayout.Space(10f); - } - - private void ShowDialog() - { - dialog.Update(); - } - - private void DrawModalWindow(string title, string message) - { - if (dialog.enabled) - { - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - dialog.DrawConfirmButton("Okay"); - GUILayout.FlexibleSpace(); - dialog.DrawCancelButton(); - GUILayout.EndHorizontal(); - } - } - - private void DrawModalWindow_OkayOnly(string title, string message) - { - if (dialog.enabled) - { - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - dialog.DrawConfirmButton("Okay"); - GUILayout.EndHorizontal(); - } - } - - private void DrawElementAssignmentWindow(string title, string message) - { - if (!dialog.enabled) - { - return; - } - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.FlexibleSpace(); - if (!(actionQueue.Peek() is ElementAssignmentChange elementAssignmentChange)) - { - dialog.Cancel(); - return; - } - float num; - if (!dialog.busy) - { - if (startListening && inputMapper.status == InputMapper.Status.Idle) - { - inputMapper.Start(elementAssignmentChange.context); - startListening = false; - } - if (conflictFoundEventData != null) - { - dialog.Confirm(); - return; - } - num = inputMapper.timeRemaining; - if (num == 0f) - { - dialog.Cancel(); - return; - } - } - else - { - num = inputMapper.options.timeout; - } - GUILayout.Label("Assignment will be canceled in " + (int)Mathf.Ceil(num) + "...", style_wordWrap); - } - - private void DrawElementAssignmentProtectedConflictWindow(string title, string message) - { - if (dialog.enabled) - { - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.FlexibleSpace(); - if (!(actionQueue.Peek() is ElementAssignmentChange)) - { - dialog.Cancel(); - return; - } - GUILayout.BeginHorizontal(); - dialog.DrawConfirmButton(UserResponse.Custom1, "Add"); - GUILayout.FlexibleSpace(); - dialog.DrawCancelButton(); - GUILayout.EndHorizontal(); - } - } - - private void DrawElementAssignmentNormalConflictWindow(string title, string message) - { - if (dialog.enabled) - { - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.FlexibleSpace(); - if (!(actionQueue.Peek() is ElementAssignmentChange)) - { - dialog.Cancel(); - return; - } - GUILayout.BeginHorizontal(); - dialog.DrawConfirmButton(UserResponse.Confirm, "Replace"); - GUILayout.FlexibleSpace(); - dialog.DrawConfirmButton(UserResponse.Custom1, "Add"); - GUILayout.FlexibleSpace(); - dialog.DrawCancelButton(); - GUILayout.EndHorizontal(); - } - } - - private void DrawReassignOrRemoveElementAssignmentWindow(string title, string message) - { - if (dialog.enabled) - { - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - dialog.DrawConfirmButton("Reassign"); - GUILayout.FlexibleSpace(); - dialog.DrawCancelButton("Remove"); - GUILayout.EndHorizontal(); - } - } - - private void DrawFallbackJoystickIdentificationWindow(string title, string message) - { - if (!dialog.enabled) - { - return; - } - if (!(actionQueue.Peek() is FallbackJoystickIdentification fallbackJoystickIdentification)) - { - dialog.Cancel(); - return; - } - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.Label("Press any button or axis on \"" + fallbackJoystickIdentification.joystickName + "\" now.", style_wordWrap); - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Skip")) - { - dialog.Cancel(); - } - else if (!dialog.busy && ReInput.controllers.SetUnityJoystickIdFromAnyButtonOrAxisPress(fallbackJoystickIdentification.joystickId, 0.8f, positiveAxesOnly: false)) - { - dialog.Confirm(); - } - } - - private void DrawCalibrationWindow(string title, string message) - { - if (!dialog.enabled) - { - return; - } - if (!(actionQueue.Peek() is Calibration calibration)) - { - dialog.Cancel(); - return; - } - GUILayout.Space(5f); - GUILayout.Label(message, style_wordWrap); - GUILayout.Space(20f); - GUILayout.BeginHorizontal(); - bool flag = GUI.enabled; - GUILayout.BeginVertical(GUILayout.Width(200f)); - calibrateScrollPos = GUILayout.BeginScrollView(calibrateScrollPos); - if (calibration.recording) - { - GUI.enabled = false; - } - IList axisElementIdentifiers = calibration.joystick.AxisElementIdentifiers; - for (int i = 0; i < axisElementIdentifiers.Count; i++) - { - ControllerElementIdentifier controllerElementIdentifier = axisElementIdentifiers[i]; - bool flag2 = calibration.selectedElementIdentifierId == controllerElementIdentifier.id; - bool flag3 = GUILayout.Toggle(flag2, controllerElementIdentifier.name, "Button", GUILayout.ExpandWidth(expand: false)); - if (flag2 != flag3) - { - calibration.selectedElementIdentifierId = controllerElementIdentifier.id; - } - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - GUILayout.EndScrollView(); - GUILayout.EndVertical(); - GUILayout.BeginVertical(GUILayout.Width(200f)); - if (calibration.selectedElementIdentifierId >= 0) - { - float axisRawById = calibration.joystick.GetAxisRawById(calibration.selectedElementIdentifierId); - GUILayout.Label("Raw Value: " + axisRawById); - int axisIndexById = calibration.joystick.GetAxisIndexById(calibration.selectedElementIdentifierId); - AxisCalibration axis = calibration.calibrationMap.GetAxis(axisIndexById); - GUILayout.Label("Calibrated Value: " + calibration.joystick.GetAxisById(calibration.selectedElementIdentifierId)); - GUILayout.Label("Zero: " + axis.calibratedZero); - GUILayout.Label("Min: " + axis.calibratedMin); - GUILayout.Label("Max: " + axis.calibratedMax); - GUILayout.Label("Dead Zone: " + axis.deadZone); - GUILayout.Space(15f); - bool flag4 = GUILayout.Toggle(axis.enabled, "Enabled", "Button", GUILayout.ExpandWidth(expand: false)); - if (axis.enabled != flag4) - { - axis.enabled = flag4; - } - GUILayout.Space(10f); - bool flag5 = GUILayout.Toggle(calibration.recording, "Record Min/Max", "Button", GUILayout.ExpandWidth(expand: false)); - if (flag5 != calibration.recording) - { - if (flag5) - { - axis.calibratedMax = 0f; - axis.calibratedMin = 0f; - } - calibration.recording = flag5; - } - if (calibration.recording) - { - axis.calibratedMin = Mathf.Min(axis.calibratedMin, axisRawById, axis.calibratedMin); - axis.calibratedMax = Mathf.Max(axis.calibratedMax, axisRawById, axis.calibratedMax); - GUI.enabled = false; - } - if (GUILayout.Button("Set Zero", GUILayout.ExpandWidth(expand: false))) - { - axis.calibratedZero = axisRawById; - } - if (GUILayout.Button("Set Dead Zone", GUILayout.ExpandWidth(expand: false))) - { - axis.deadZone = axisRawById; - } - bool flag6 = GUILayout.Toggle(axis.invert, "Invert", "Button", GUILayout.ExpandWidth(expand: false)); - if (axis.invert != flag6) - { - axis.invert = flag6; - } - GUILayout.Space(10f); - if (GUILayout.Button("Reset", GUILayout.ExpandWidth(expand: false))) - { - axis.Reset(); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - else - { - GUILayout.Label("Select an axis to begin."); - } - GUILayout.EndVertical(); - GUILayout.EndHorizontal(); - GUILayout.FlexibleSpace(); - if (calibration.recording) - { - GUI.enabled = false; - } - if (GUILayout.Button("Close")) - { - calibrateScrollPos = default(Vector2); - dialog.Confirm(); - } - if (GUI.enabled != flag) - { - GUI.enabled = flag; - } - } - - private void DialogResultCallback(int queueActionId, UserResponse response) - { - foreach (QueueEntry item in actionQueue) - { - if (item.id == queueActionId) - { - if (response != UserResponse.Cancel) - { - item.Confirm(response); - } - else - { - item.Cancel(); - } - break; - } - } - } - - private Rect GetScreenCenteredRect(float width, float height) - { - return new Rect((float)Screen.width * 0.5f - width * 0.5f, (float)((double)Screen.height * 0.5 - (double)(height * 0.5f)), width, height); - } - - private void EnqueueAction(QueueEntry entry) - { - if (entry != null) - { - busy = true; - GUI.enabled = false; - actionQueue.Enqueue(entry); - } - } - - private void ProcessQueue() - { - if (dialog.enabled || busy || actionQueue.Count == 0) - { - return; - } - while (actionQueue.Count > 0) - { - QueueEntry queueEntry = actionQueue.Peek(); - bool flag = false; - switch (queueEntry.queueActionType) - { - case QueueActionType.JoystickAssignment: - flag = ProcessJoystickAssignmentChange((JoystickAssignmentChange)queueEntry); - break; - case QueueActionType.ElementAssignment: - flag = ProcessElementAssignmentChange((ElementAssignmentChange)queueEntry); - break; - case QueueActionType.FallbackJoystickIdentification: - flag = ProcessFallbackJoystickIdentification((FallbackJoystickIdentification)queueEntry); - break; - case QueueActionType.Calibrate: - flag = ProcessCalibration((Calibration)queueEntry); - break; - } - if (flag) - { - actionQueue.Dequeue(); - continue; - } - break; - } - } - - private bool ProcessJoystickAssignmentChange(JoystickAssignmentChange entry) - { - if (entry.state == QueueEntry.State.Canceled) - { - return true; - } - Player player = ReInput.players.GetPlayer(entry.playerId); - if (player == null) - { - return true; - } - if (!entry.assign) - { - player.controllers.RemoveController(ControllerType.Joystick, entry.joystickId); - ControllerSelectionChanged(); - return true; - } - if (player.controllers.ContainsController(ControllerType.Joystick, entry.joystickId)) - { - return true; - } - if (!ReInput.controllers.IsJoystickAssigned(entry.joystickId) || entry.state == QueueEntry.State.Confirmed) - { - player.controllers.AddController(ControllerType.Joystick, entry.joystickId, removeFromOtherPlayers: true); - ControllerSelectionChanged(); - return true; - } - dialog.StartModal(entry.id, DialogHelper.DialogType.JoystickConflict, new WindowProperties - { - title = "Joystick Reassignment", - message = "This joystick is already assigned to another player. Do you want to reassign this joystick to " + player.descriptiveName + "?", - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawModalWindow - }, DialogResultCallback); - return false; - } - - private bool ProcessElementAssignmentChange(ElementAssignmentChange entry) - { - switch (entry.changeType) - { - case ElementAssignmentChangeType.ReassignOrRemove: - return ProcessRemoveOrReassignElementAssignment(entry); - case ElementAssignmentChangeType.Remove: - return ProcessRemoveElementAssignment(entry); - case ElementAssignmentChangeType.Add: - case ElementAssignmentChangeType.Replace: - return ProcessAddOrReplaceElementAssignment(entry); - case ElementAssignmentChangeType.ConflictCheck: - return ProcessElementAssignmentConflictCheck(entry); - default: - throw new NotImplementedException(); - } - } - - private bool ProcessRemoveOrReassignElementAssignment(ElementAssignmentChange entry) - { - if (entry.context.controllerMap == null) - { - return true; - } - if (entry.state == QueueEntry.State.Canceled) - { - ElementAssignmentChange elementAssignmentChange = new ElementAssignmentChange(entry); - elementAssignmentChange.changeType = ElementAssignmentChangeType.Remove; - actionQueue.Enqueue(elementAssignmentChange); - return true; - } - if (entry.state == QueueEntry.State.Confirmed) - { - ElementAssignmentChange elementAssignmentChange2 = new ElementAssignmentChange(entry); - elementAssignmentChange2.changeType = ElementAssignmentChangeType.Replace; - actionQueue.Enqueue(elementAssignmentChange2); - return true; - } - dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties - { - title = "Reassign or Remove", - message = "Do you want to reassign or remove this assignment?", - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawReassignOrRemoveElementAssignmentWindow - }, DialogResultCallback); - return false; - } - - private bool ProcessRemoveElementAssignment(ElementAssignmentChange entry) - { - if (entry.context.controllerMap == null) - { - return true; - } - if (entry.state == QueueEntry.State.Canceled) - { - return true; - } - if (entry.state == QueueEntry.State.Confirmed) - { - entry.context.controllerMap.DeleteElementMap(entry.context.actionElementMapToReplace.id); - return true; - } - dialog.StartModal(entry.id, DialogHelper.DialogType.DeleteAssignmentConfirmation, new WindowProperties - { - title = "Remove Assignment", - message = "Are you sure you want to remove this assignment?", - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawModalWindow - }, DialogResultCallback); - return false; - } - - private bool ProcessAddOrReplaceElementAssignment(ElementAssignmentChange entry) - { - if (entry.state == QueueEntry.State.Canceled) - { - inputMapper.Stop(); - return true; - } - if (entry.state == QueueEntry.State.Confirmed) - { - if (Event.current.type != EventType.Layout) - { - return false; - } - if (conflictFoundEventData != null) - { - ElementAssignmentChange elementAssignmentChange = new ElementAssignmentChange(entry); - elementAssignmentChange.changeType = ElementAssignmentChangeType.ConflictCheck; - actionQueue.Enqueue(elementAssignmentChange); - } - return true; - } - string text; - if (entry.context.controllerMap.controllerType != 0) - { - text = ((entry.context.controllerMap.controllerType != ControllerType.Mouse) ? "Press any button or axis to assign it to this action." : "Press any mouse button or axis to assign it to this action.\n\nTo assign mouse movement axes, move the mouse quickly in the direction you want mapped to the action. Slow movements will be ignored."); - } - else - { - text = ((Application.platform != 0 && Application.platform != RuntimePlatform.OSXPlayer) ? "Press any key to assign it to this action. You may also use the modifier keys Control, Alt, and Shift. If you wish to assign a modifier key itself to this action, press and hold the key for 1 second." : "Press any key to assign it to this action. You may also use the modifier keys Command, Control, Alt, and Shift. If you wish to assign a modifier key itself to this action, press and hold the key for 1 second."); - if (Application.isEditor) - { - text += "\n\nNOTE: Some modifier key combinations will not work in the Unity Editor, but they will work in a game build."; - } - } - dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties - { - title = "Assign", - message = text, - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawElementAssignmentWindow - }, DialogResultCallback); - return false; - } - - private bool ProcessElementAssignmentConflictCheck(ElementAssignmentChange entry) - { - if (entry.context.controllerMap == null) - { - return true; - } - if (entry.state == QueueEntry.State.Canceled) - { - inputMapper.Stop(); - return true; - } - if (conflictFoundEventData == null) - { - return true; - } - if (entry.state == QueueEntry.State.Confirmed) - { - if (entry.response == UserResponse.Confirm) - { - conflictFoundEventData.responseCallback(InputMapper.ConflictResponse.Replace); - } - else - { - if (entry.response != UserResponse.Custom1) - { - throw new NotImplementedException(); - } - conflictFoundEventData.responseCallback(InputMapper.ConflictResponse.Add); - } - return true; - } - if (conflictFoundEventData.isProtected) - { - string message = conflictFoundEventData.assignment.elementDisplayName + " is already in use and is protected from reassignment. You cannot remove the protected assignment, but you can still assign the action to this element. If you do so, the element will trigger multiple actions when activated."; - dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties - { - title = "Assignment Conflict", - message = message, - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawElementAssignmentProtectedConflictWindow - }, DialogResultCallback); - } - else - { - string message2 = conflictFoundEventData.assignment.elementDisplayName + " is already in use. You may replace the other conflicting assignments, add this assignment anyway which will leave multiple actions assigned to this element, or cancel this assignment."; - dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties - { - title = "Assignment Conflict", - message = message2, - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawElementAssignmentNormalConflictWindow - }, DialogResultCallback); - } - return false; - } - - private bool ProcessFallbackJoystickIdentification(FallbackJoystickIdentification entry) - { - if (entry.state == QueueEntry.State.Canceled) - { - return true; - } - if (entry.state == QueueEntry.State.Confirmed) - { - return true; - } - dialog.StartModal(entry.id, DialogHelper.DialogType.JoystickConflict, new WindowProperties - { - title = "Joystick Identification Required", - message = "A joystick has been attached or removed. You will need to identify each joystick by pressing a button on the controller listed below:", - rect = GetScreenCenteredRect(250f, 200f), - windowDrawDelegate = DrawFallbackJoystickIdentificationWindow - }, DialogResultCallback, 1f); - return false; - } - - private bool ProcessCalibration(Calibration entry) - { - if (entry.state == QueueEntry.State.Canceled) - { - return true; - } - if (entry.state == QueueEntry.State.Confirmed) - { - return true; - } - dialog.StartModal(entry.id, DialogHelper.DialogType.JoystickConflict, new WindowProperties - { - title = "Calibrate Controller", - message = "Select an axis to calibrate on the " + entry.joystick.name + ".", - rect = GetScreenCenteredRect(450f, 480f), - windowDrawDelegate = DrawCalibrationWindow - }, DialogResultCallback); - return false; - } - - private void PlayerSelectionChanged() - { - ClearControllerSelection(); - } - - private void ControllerSelectionChanged() - { - ClearMapSelection(); - } - - private void ClearControllerSelection() - { - selectedController.Clear(); - ClearMapSelection(); - } - - private void ClearMapSelection() - { - selectedMapCategoryId = -1; - selectedMap = null; - } - - private void ResetAll() - { - ClearWorkingVars(); - initialized = false; - showMenu = false; - } - - private void ClearWorkingVars() - { - selectedPlayer = null; - ClearMapSelection(); - selectedController.Clear(); - actionScrollPos = default(Vector2); - dialog.FullReset(); - actionQueue.Clear(); - busy = false; - startListening = false; - conflictFoundEventData = null; - inputMapper.Stop(); - } - - private void SetGUIStateStart() - { - guiState = true; - if (busy) - { - guiState = false; - } - pageGUIState = guiState && !busy && !dialog.enabled && !dialog.busy; - if (GUI.enabled != guiState) - { - GUI.enabled = guiState; - } - } - - private void SetGUIStateEnd() - { - guiState = true; - if (!GUI.enabled) - { - GUI.enabled = guiState; - } - } - - private void JoystickConnected(ControllerStatusChangedEventArgs args) - { - if (ReInput.controllers.IsControllerAssigned(args.controllerType, args.controllerId)) - { - foreach (Player allPlayer in ReInput.players.AllPlayers) - { - if (allPlayer.controllers.ContainsController(args.controllerType, args.controllerId)) - { - ReInput.userDataStore.LoadControllerData(allPlayer.id, args.controllerType, args.controllerId); - } - } - } - else - { - ReInput.userDataStore.LoadControllerData(args.controllerType, args.controllerId); - } - if (ReInput.unityJoystickIdentificationRequired) - { - IdentifyAllJoysticks(); - } - } - - private void JoystickPreDisconnect(ControllerStatusChangedEventArgs args) - { - if (selectedController.hasSelection && args.controllerType == selectedController.type && args.controllerId == selectedController.id) - { - ClearControllerSelection(); - } - if (!showMenu) - { - return; - } - if (ReInput.controllers.IsControllerAssigned(args.controllerType, args.controllerId)) - { - foreach (Player allPlayer in ReInput.players.AllPlayers) - { - if (allPlayer.controllers.ContainsController(args.controllerType, args.controllerId)) - { - ReInput.userDataStore.SaveControllerData(allPlayer.id, args.controllerType, args.controllerId); - } - } - return; - } - ReInput.userDataStore.SaveControllerData(args.controllerType, args.controllerId); - } - - private void JoystickDisconnected(ControllerStatusChangedEventArgs args) - { - if (showMenu) - { - ClearWorkingVars(); - } - if (ReInput.unityJoystickIdentificationRequired) - { - IdentifyAllJoysticks(); - } - } - - private void OnConflictFound(InputMapper.ConflictFoundEventData data) - { - conflictFoundEventData = data; - } - - private void OnStopped(InputMapper.StoppedEventData data) - { - conflictFoundEventData = null; - } - - public void IdentifyAllJoysticks() - { - if (ReInput.controllers.joystickCount == 0) - { - return; - } - ClearWorkingVars(); - Open(); - foreach (Joystick joystick in ReInput.controllers.Joysticks) - { - actionQueue.Enqueue(new FallbackJoystickIdentification(joystick.id, joystick.name)); - } - } - - protected void CheckRecompile() - { - } - - private void RecompileWindow(int windowId) - { - } -} diff --git a/Rewired/Rewired.Demos/CustomControllerDemo.cs b/Rewired/Rewired.Demos/CustomControllerDemo.cs deleted file mode 100644 index 2c67e86..0000000 --- a/Rewired/Rewired.Demos/CustomControllerDemo.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class CustomControllerDemo : MonoBehaviour -{ - public int playerId; - - public string controllerTag; - - public bool useUpdateCallbacks; - - private int buttonCount; - - private int axisCount; - - private float[] axisValues; - - private bool[] buttonValues; - - private TouchJoystickExample[] joysticks; - - private TouchButtonExample[] buttons; - - private CustomController controller; - - [NonSerialized] - private bool initialized; - - private void Awake() - { - ScreenOrientation screenOrientation = ScreenOrientation.LandscapeLeft; - if (SystemInfo.deviceType == DeviceType.Handheld && Screen.orientation != screenOrientation) - { - Screen.orientation = screenOrientation; - } - Initialize(); - } - - private void Initialize() - { - ReInput.InputSourceUpdateEvent += OnInputSourceUpdate; - joysticks = GetComponentsInChildren(); - buttons = GetComponentsInChildren(); - axisCount = joysticks.Length * 2; - buttonCount = buttons.Length; - axisValues = new float[axisCount]; - buttonValues = new bool[buttonCount]; - Player player = ReInput.players.GetPlayer(playerId); - controller = player.controllers.GetControllerWithTag(controllerTag); - if (controller == null) - { - Debug.LogError("A matching controller was not found for tag \"" + controllerTag + "\""); - } - if (controller.buttonCount != buttonValues.Length || controller.axisCount != axisValues.Length) - { - Debug.LogError("Controller has wrong number of elements!"); - } - if (useUpdateCallbacks && controller != null) - { - controller.SetAxisUpdateCallback(GetAxisValueCallback); - controller.SetButtonUpdateCallback(GetButtonValueCallback); - } - initialized = true; - } - - private void Update() - { - if (ReInput.isReady && !initialized) - { - Initialize(); - } - } - - private void OnInputSourceUpdate() - { - GetSourceAxisValues(); - GetSourceButtonValues(); - if (!useUpdateCallbacks) - { - SetControllerAxisValues(); - SetControllerButtonValues(); - } - } - - private void GetSourceAxisValues() - { - for (int i = 0; i < axisValues.Length; i++) - { - if (i % 2 != 0) - { - axisValues[i] = joysticks[i / 2].position.y; - } - else - { - axisValues[i] = joysticks[i / 2].position.x; - } - } - } - - private void GetSourceButtonValues() - { - for (int i = 0; i < buttonValues.Length; i++) - { - buttonValues[i] = buttons[i].isPressed; - } - } - - private void SetControllerAxisValues() - { - for (int i = 0; i < axisValues.Length; i++) - { - controller.SetAxisValue(i, axisValues[i]); - } - } - - private void SetControllerButtonValues() - { - for (int i = 0; i < buttonValues.Length; i++) - { - controller.SetButtonValue(i, buttonValues[i]); - } - } - - private float GetAxisValueCallback(int index) - { - if (index >= axisValues.Length) - { - return 0f; - } - return axisValues[index]; - } - - private bool GetButtonValueCallback(int index) - { - if (index >= buttonValues.Length) - { - return false; - } - return buttonValues[index]; - } -} diff --git a/Rewired/Rewired.Demos/CustomControllerDemo_Player.cs b/Rewired/Rewired.Demos/CustomControllerDemo_Player.cs deleted file mode 100644 index 7c4346a..0000000 --- a/Rewired/Rewired.Demos/CustomControllerDemo_Player.cs +++ /dev/null @@ -1,58 +0,0 @@ -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -[RequireComponent(typeof(CharacterController))] -public class CustomControllerDemo_Player : MonoBehaviour -{ - public int playerId; - - public float speed = 1f; - - public float bulletSpeed = 20f; - - public GameObject bulletPrefab; - - private Player _player; - - private CharacterController cc; - - private Player player - { - get - { - if (_player == null) - { - _player = ReInput.players.GetPlayer(playerId); - } - return _player; - } - } - - private void Awake() - { - cc = GetComponent(); - } - - private void Update() - { - if (ReInput.isReady) - { - Vector2 vector = new Vector2(player.GetAxis("Move Horizontal"), player.GetAxis("Move Vertical")); - cc.Move(vector * speed * Time.deltaTime); - if (player.GetButtonDown("Fire")) - { - Vector3 vector2 = Vector3.Scale(new Vector3(1f, 0f, 0f), base.transform.right); - Object.Instantiate(bulletPrefab, base.transform.position + vector2, Quaternion.identity).GetComponent().velocity = new Vector3(bulletSpeed * base.transform.right.x, 0f, 0f); - } - if (player.GetButtonDown("Change Color")) - { - Renderer component = GetComponent(); - Material material = component.material; - material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); - component.material = material; - } - } - } -} diff --git a/Rewired/Rewired.Demos/CustomControllersTiltDemo.cs b/Rewired/Rewired.Demos/CustomControllersTiltDemo.cs deleted file mode 100644 index d24caf2..0000000 --- a/Rewired/Rewired.Demos/CustomControllersTiltDemo.cs +++ /dev/null @@ -1,47 +0,0 @@ -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class CustomControllersTiltDemo : MonoBehaviour -{ - public Transform target; - - public float speed = 10f; - - private CustomController controller; - - private Player player; - - private void Awake() - { - Screen.orientation = ScreenOrientation.LandscapeLeft; - player = ReInput.players.GetPlayer(0); - ReInput.InputSourceUpdateEvent += OnInputUpdate; - controller = (CustomController)player.controllers.GetControllerWithTag(ControllerType.Custom, "TiltController"); - } - - private void Update() - { - if (!(target == null)) - { - Vector3 zero = Vector3.zero; - zero.y = player.GetAxis("Tilt Vertical"); - zero.x = player.GetAxis("Tilt Horizontal"); - if (zero.sqrMagnitude > 1f) - { - zero.Normalize(); - } - zero *= Time.deltaTime; - target.Translate(zero * speed); - } - } - - private void OnInputUpdate() - { - Vector3 acceleration = Input.acceleration; - controller.SetAxisValue(0, acceleration.x); - controller.SetAxisValue(1, acceleration.y); - controller.SetAxisValue(2, acceleration.z); - } -} diff --git a/Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs b/Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs deleted file mode 100644 index 838b779..0000000 --- a/Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs +++ /dev/null @@ -1,219 +0,0 @@ -using System.Collections.Generic; -using Rewired.ControllerExtensions; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class DualShock4SpecialFeaturesExample : MonoBehaviour -{ - private class Touch - { - public GameObject go; - - public int touchId = -1; - } - - private const int maxTouches = 2; - - public int playerId; - - public Transform touchpadTransform; - - public GameObject lightObject; - - public Transform accelerometerTransform; - - private List touches; - - private Queue unusedTouches; - - private bool isFlashing; - - private GUIStyle textStyle; - - private Player player => ReInput.players.GetPlayer(playerId); - - private void Awake() - { - InitializeTouchObjects(); - } - - private void Update() - { - if (!ReInput.isReady) - { - return; - } - IDualShock4Extension firstDS = GetFirstDS4(player); - if (firstDS != null) - { - base.transform.rotation = firstDS.GetOrientation(); - HandleTouchpad(firstDS); - Vector3 accelerometerValue = firstDS.GetAccelerometerValue(); - accelerometerTransform.LookAt(accelerometerTransform.position + accelerometerValue); - } - if (player.GetButtonDown("CycleLight")) - { - SetRandomLightColor(); - } - if (player.GetButtonDown("ResetOrientation")) - { - ResetOrientation(); - } - if (player.GetButtonDown("ToggleLightFlash")) - { - if (isFlashing) - { - StopLightFlash(); - } - else - { - StartLightFlash(); - } - isFlashing = !isFlashing; - } - if (player.GetButtonDown("VibrateLeft")) - { - firstDS.SetVibration(0, 1f, 1f); - } - if (player.GetButtonDown("VibrateRight")) - { - firstDS.SetVibration(1, 1f, 1f); - } - } - - private void OnGUI() - { - if (textStyle == null) - { - textStyle = new GUIStyle(GUI.skin.label); - textStyle.fontSize = 20; - textStyle.wordWrap = true; - } - if (GetFirstDS4(player) != null) - { - GUILayout.BeginArea(new Rect(200f, 100f, (float)Screen.width - 400f, (float)Screen.height - 200f)); - GUILayout.Label("Rotate the Dual Shock 4 to see the model rotate in sync.", textStyle); - GUILayout.Label("Touch the touchpad to see them appear on the model.", textStyle); - ActionElementMap firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "ResetOrientation", skipDisabledMaps: true); - if (firstElementMapWithAction != null) - { - GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " to reset the orientation. Hold the gamepad facing the screen with sticks pointing up and press the button.", textStyle); - } - firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "CycleLight", skipDisabledMaps: true); - if (firstElementMapWithAction != null) - { - GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " to change the light color.", textStyle); - } - firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "ToggleLightFlash", skipDisabledMaps: true); - if (firstElementMapWithAction != null) - { - GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " to start or stop the light flashing.", textStyle); - } - firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "VibrateLeft", skipDisabledMaps: true); - if (firstElementMapWithAction != null) - { - GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " vibrate the left motor.", textStyle); - } - firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "VibrateRight", skipDisabledMaps: true); - if (firstElementMapWithAction != null) - { - GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " vibrate the right motor.", textStyle); - } - GUILayout.EndArea(); - } - } - - private void ResetOrientation() - { - GetFirstDS4(player)?.ResetOrientation(); - } - - private void SetRandomLightColor() - { - IDualShock4Extension firstDS = GetFirstDS4(player); - if (firstDS != null) - { - Color color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); - firstDS.SetLightColor(color); - lightObject.GetComponent().material.color = color; - } - } - - private void StartLightFlash() - { - if (GetFirstDS4(player) is DualShock4Extension dualShock4Extension) - { - dualShock4Extension.SetLightFlash(0.5f, 0.5f); - } - } - - private void StopLightFlash() - { - if (GetFirstDS4(player) is DualShock4Extension dualShock4Extension) - { - dualShock4Extension.StopLightFlash(); - } - } - - private IDualShock4Extension GetFirstDS4(Player player) - { - foreach (Joystick joystick in player.controllers.Joysticks) - { - IDualShock4Extension extension = joystick.GetExtension(); - if (extension != null) - { - return extension; - } - } - return null; - } - - private void InitializeTouchObjects() - { - touches = new List(2); - unusedTouches = new Queue(2); - for (int i = 0; i < 2; i++) - { - Touch touch = new Touch(); - touch.go = GameObject.CreatePrimitive(PrimitiveType.Sphere); - touch.go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); - touch.go.transform.SetParent(touchpadTransform, worldPositionStays: true); - touch.go.GetComponent().material.color = ((i == 0) ? Color.red : Color.green); - touch.go.SetActive(value: false); - unusedTouches.Enqueue(touch); - } - } - - private void HandleTouchpad(IDualShock4Extension ds4) - { - for (int num = touches.Count - 1; num >= 0; num--) - { - Touch touch = touches[num]; - if (!ds4.IsTouchingByTouchId(touch.touchId)) - { - touch.go.SetActive(value: false); - unusedTouches.Enqueue(touch); - touches.RemoveAt(num); - } - } - for (int i = 0; i < ds4.maxTouches; i++) - { - if (ds4.IsTouching(i)) - { - int touchId = ds4.GetTouchId(i); - Touch touch2 = touches.Find((Touch x) => x.touchId == touchId); - if (touch2 == null) - { - touch2 = unusedTouches.Dequeue(); - touches.Add(touch2); - } - touch2.touchId = touchId; - touch2.go.SetActive(value: true); - ds4.GetTouchPosition(i, out var position); - touch2.go.transform.localPosition = new Vector3(position.x - 0.5f, 0.5f + touch2.go.transform.localScale.y * 0.5f, position.y - 0.5f); - } - } - } -} diff --git a/Rewired/Rewired.Demos/EightPlayersExample_Player.cs b/Rewired/Rewired.Demos/EightPlayersExample_Player.cs deleted file mode 100644 index 0ce56e1..0000000 --- a/Rewired/Rewired.Demos/EightPlayersExample_Player.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -[RequireComponent(typeof(CharacterController))] -public class EightPlayersExample_Player : MonoBehaviour -{ - public int playerId; - - public float moveSpeed = 3f; - - public float bulletSpeed = 15f; - - public GameObject bulletPrefab; - - private Player player; - - private CharacterController cc; - - private Vector3 moveVector; - - private bool fire; - - [NonSerialized] - private bool initialized; - - private void Awake() - { - cc = GetComponent(); - } - - private void Initialize() - { - player = ReInput.players.GetPlayer(playerId); - initialized = true; - } - - private void Update() - { - if (ReInput.isReady) - { - if (!initialized) - { - Initialize(); - } - GetInput(); - ProcessInput(); - } - } - - private void GetInput() - { - moveVector.x = player.GetAxis("Move Horizontal"); - moveVector.y = player.GetAxis("Move Vertical"); - fire = player.GetButtonDown("Fire"); - } - - private void ProcessInput() - { - if (moveVector.x != 0f || moveVector.y != 0f) - { - cc.Move(moveVector * moveSpeed * Time.deltaTime); - } - if (fire) - { - UnityEngine.Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange); - } - } -} diff --git a/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs b/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs deleted file mode 100644 index 3213b71..0000000 --- a/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class FallbackJoystickIdentificationDemo : MonoBehaviour -{ - private const float windowWidth = 250f; - - private const float windowHeight = 250f; - - private const float inputDelay = 1f; - - private bool identifyRequired; - - private Queue joysticksToIdentify; - - private float nextInputAllowedTime; - - private GUIStyle style; - - private void Awake() - { - if (ReInput.unityJoystickIdentificationRequired) - { - ReInput.ControllerConnectedEvent += JoystickConnected; - ReInput.ControllerDisconnectedEvent += JoystickDisconnected; - IdentifyAllJoysticks(); - } - } - - private void JoystickConnected(ControllerStatusChangedEventArgs args) - { - IdentifyAllJoysticks(); - } - - private void JoystickDisconnected(ControllerStatusChangedEventArgs args) - { - IdentifyAllJoysticks(); - } - - public void IdentifyAllJoysticks() - { - Reset(); - if (ReInput.controllers.joystickCount != 0) - { - Joystick[] joysticks = ReInput.controllers.GetJoysticks(); - if (joysticks != null) - { - identifyRequired = true; - joysticksToIdentify = new Queue(joysticks); - SetInputDelay(); - } - } - } - - private void SetInputDelay() - { - nextInputAllowedTime = Time.time + 1f; - } - - private void OnGUI() - { - if (!identifyRequired) - { - return; - } - if (joysticksToIdentify == null || joysticksToIdentify.Count == 0) - { - Reset(); - return; - } - Rect screenRect = new Rect((float)Screen.width * 0.5f - 125f, (float)Screen.height * 0.5f - 125f, 250f, 250f); - GUILayout.Window(0, screenRect, DrawDialogWindow, "Joystick Identification Required"); - GUI.FocusWindow(0); - if (!(Time.time < nextInputAllowedTime) && ReInput.controllers.SetUnityJoystickIdFromAnyButtonOrAxisPress(joysticksToIdentify.Peek().id, 0.8f, positiveAxesOnly: false)) - { - joysticksToIdentify.Dequeue(); - SetInputDelay(); - if (joysticksToIdentify.Count == 0) - { - Reset(); - } - } - } - - private void DrawDialogWindow(int windowId) - { - if (identifyRequired) - { - if (style == null) - { - style = new GUIStyle(GUI.skin.label); - style.wordWrap = true; - } - GUILayout.Space(15f); - GUILayout.Label("A joystick has been attached or removed. You will need to identify each joystick by pressing a button on the controller listed below:", style); - Joystick joystick = joysticksToIdentify.Peek(); - GUILayout.Label("Press any button on \"" + joystick.name + "\" now.", style); - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Skip")) - { - joysticksToIdentify.Dequeue(); - } - } - } - - private void Reset() - { - joysticksToIdentify = null; - identifyRequired = false; - } -} diff --git a/Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs b/Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs deleted file mode 100644 index 194fb5d..0000000 --- a/Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class PlayerMouseSpriteExample : MonoBehaviour -{ - [Tooltip("The Player that will control the mouse")] - public int playerId; - - [Tooltip("The Rewired Action used for the mouse horizontal axis.")] - public string horizontalAction = "MouseX"; - - [Tooltip("The Rewired Action used for the mouse vertical axis.")] - public string verticalAction = "MouseY"; - - [Tooltip("The Rewired Action used for the mouse wheel axis.")] - public string wheelAction = "MouseWheel"; - - [Tooltip("The Rewired Action used for the mouse left button.")] - public string leftButtonAction = "MouseLeftButton"; - - [Tooltip("The Rewired Action used for the mouse right button.")] - public string rightButtonAction = "MouseRightButton"; - - [Tooltip("The Rewired Action used for the mouse middle button.")] - public string middleButtonAction = "MouseMiddleButton"; - - [Tooltip("The distance from the camera that the pointer will be drawn.")] - public float distanceFromCamera = 1f; - - [Tooltip("The scale of the sprite pointer.")] - public float spriteScale = 0.05f; - - [Tooltip("The pointer prefab.")] - public GameObject pointerPrefab; - - [Tooltip("The click effect prefab.")] - public GameObject clickEffectPrefab; - - [Tooltip("Should the hardware pointer be hidden?")] - public bool hideHardwarePointer = true; - - [NonSerialized] - private GameObject pointer; - - [NonSerialized] - private PlayerMouse mouse; - - private void Awake() - { - pointer = UnityEngine.Object.Instantiate(pointerPrefab); - pointer.transform.localScale = new Vector3(spriteScale, spriteScale, spriteScale); - if (hideHardwarePointer) - { - Cursor.visible = false; - } - mouse = PlayerMouse.Factory.Create(); - mouse.playerId = playerId; - mouse.xAxis.actionName = horizontalAction; - mouse.yAxis.actionName = verticalAction; - mouse.wheel.yAxis.actionName = wheelAction; - mouse.leftButton.actionName = leftButtonAction; - mouse.rightButton.actionName = rightButtonAction; - mouse.middleButton.actionName = middleButtonAction; - mouse.pointerSpeed = 1f; - mouse.wheel.yAxis.repeatRate = 5f; - mouse.screenPosition = new Vector2((float)Screen.width * 0.5f, (float)Screen.height * 0.5f); - mouse.ScreenPositionChangedEvent += OnScreenPositionChanged; - OnScreenPositionChanged(mouse.screenPosition); - } - - private void Update() - { - if (ReInput.isReady) - { - pointer.transform.Rotate(Vector3.forward, mouse.wheel.yAxis.value * 20f); - if (mouse.leftButton.justPressed) - { - CreateClickEffect(new Color(0f, 1f, 0f, 1f)); - } - if (mouse.rightButton.justPressed) - { - CreateClickEffect(new Color(1f, 0f, 0f, 1f)); - } - if (mouse.middleButton.justPressed) - { - CreateClickEffect(new Color(1f, 1f, 0f, 1f)); - } - } - } - - private void OnDestroy() - { - if (ReInput.isReady) - { - mouse.ScreenPositionChangedEvent -= OnScreenPositionChanged; - } - } - - private void CreateClickEffect(Color color) - { - GameObject obj = UnityEngine.Object.Instantiate(clickEffectPrefab); - obj.transform.localScale = new Vector3(spriteScale, spriteScale, spriteScale); - obj.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(mouse.screenPosition.x, mouse.screenPosition.y, distanceFromCamera)); - obj.GetComponentInChildren().color = color; - UnityEngine.Object.Destroy(obj, 0.5f); - } - - private void OnScreenPositionChanged(Vector2 position) - { - Vector3 position2 = Camera.main.ScreenToWorldPoint(new Vector3(position.x, position.y, distanceFromCamera)); - pointer.transform.position = position2; - } -} diff --git a/Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs b/Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs deleted file mode 100644 index dde8871..0000000 --- a/Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using Rewired.Integration.UnityUI; -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public sealed class PlayerPointerEventHandlerExample : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerUpHandler, IPointerDownHandler, IPointerClickHandler, IScrollHandler, IBeginDragHandler, IDragHandler, IEndDragHandler -{ - public Text text; - - private const int logLength = 10; - - private List log = new List(); - - private void Log(string o) - { - log.Add(o); - if (log.Count > 10) - { - log.RemoveAt(0); - } - } - - private void Update() - { - if (!(text != null)) - { - return; - } - StringBuilder stringBuilder = new StringBuilder(); - foreach (string item in log) - { - stringBuilder.AppendLine(item); - } - text.text = stringBuilder.ToString(); - } - - public void OnPointerEnter(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnPointerEnter: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData)); - } - } - - public void OnPointerExit(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnPointerExit: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData)); - } - } - - public void OnPointerUp(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnPointerUp: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); - } - } - - public void OnPointerDown(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnPointerDown: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); - } - } - - public void OnPointerClick(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnPointerClick: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); - } - } - - public void OnScroll(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnScroll: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData)); - } - } - - public void OnBeginDrag(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnBeginDrag: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); - } - } - - public void OnDrag(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnDrag: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); - } - } - - public void OnEndDrag(PointerEventData eventData) - { - if (eventData is PlayerPointerEventData) - { - PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; - Log("OnEndDrag: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); - } - } - - private static string GetSourceName(PlayerPointerEventData playerEventData) - { - if (playerEventData.sourceType == PointerEventType.Mouse) - { - if (playerEventData.mouseSource is Behaviour) - { - return (playerEventData.mouseSource as Behaviour).name; - } - } - else if (playerEventData.sourceType == PointerEventType.Touch && playerEventData.touchSource is Behaviour) - { - return (playerEventData.touchSource as Behaviour).name; - } - return null; - } -} diff --git a/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs b/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs deleted file mode 100644 index 83c25e8..0000000 --- a/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class PressAnyButtonToJoinExample_Assigner : MonoBehaviour -{ - private void Update() - { - if (ReInput.isReady) - { - AssignJoysticksToPlayers(); - } - } - - private void AssignJoysticksToPlayers() - { - IList joysticks = ReInput.controllers.Joysticks; - for (int i = 0; i < joysticks.Count; i++) - { - Joystick joystick = joysticks[i]; - if (!ReInput.controllers.IsControllerAssigned(joystick.type, joystick.id) && joystick.GetAnyButtonDown()) - { - Player player = FindPlayerWithoutJoystick(); - if (player == null) - { - return; - } - player.controllers.AddController(joystick, removeFromOtherPlayers: false); - } - } - if (DoAllPlayersHaveJoysticks()) - { - ReInput.configuration.autoAssignJoysticks = true; - base.enabled = false; - } - } - - private Player FindPlayerWithoutJoystick() - { - IList players = ReInput.players.Players; - for (int i = 0; i < players.Count; i++) - { - if (players[i].controllers.joystickCount <= 0) - { - return players[i]; - } - } - return null; - } - - private bool DoAllPlayersHaveJoysticks() - { - return FindPlayerWithoutJoystick() == null; - } -} diff --git a/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs b/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs deleted file mode 100644 index a0466ce..0000000 --- a/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs +++ /dev/null @@ -1,67 +0,0 @@ -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -[RequireComponent(typeof(CharacterController))] -public class PressAnyButtonToJoinExample_GamePlayer : MonoBehaviour -{ - public int playerId; - - public float moveSpeed = 3f; - - public float bulletSpeed = 15f; - - public GameObject bulletPrefab; - - private CharacterController cc; - - private Vector3 moveVector; - - private bool fire; - - private Player player - { - get - { - if (!ReInput.isReady) - { - return null; - } - return ReInput.players.GetPlayer(playerId); - } - } - - private void OnEnable() - { - cc = GetComponent(); - } - - private void Update() - { - if (ReInput.isReady && player != null) - { - GetInput(); - ProcessInput(); - } - } - - private void GetInput() - { - moveVector.x = player.GetAxis("Move Horizontal"); - moveVector.y = player.GetAxis("Move Vertical"); - fire = player.GetButtonDown("Fire"); - } - - private void ProcessInput() - { - if (moveVector.x != 0f || moveVector.y != 0f) - { - cc.Move(moveVector * moveSpeed * Time.deltaTime); - } - if (fire) - { - Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange); - } - } -} diff --git a/Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs b/Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs deleted file mode 100644 index 6b23589..0000000 --- a/Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class PressStartToJoinExample_Assigner : MonoBehaviour -{ - private class PlayerMap - { - public int rewiredPlayerId; - - public int gamePlayerId; - - public PlayerMap(int rewiredPlayerId, int gamePlayerId) - { - this.rewiredPlayerId = rewiredPlayerId; - this.gamePlayerId = gamePlayerId; - } - } - - private static PressStartToJoinExample_Assigner instance; - - public int maxPlayers = 4; - - private List playerMap; - - private int gamePlayerIdCounter; - - public static Player GetRewiredPlayer(int gamePlayerId) - { - if (!ReInput.isReady) - { - return null; - } - if (instance == null) - { - Debug.LogError("Not initialized. Do you have a PressStartToJoinPlayerSelector in your scehe?"); - return null; - } - for (int i = 0; i < instance.playerMap.Count; i++) - { - if (instance.playerMap[i].gamePlayerId == gamePlayerId) - { - return ReInput.players.GetPlayer(instance.playerMap[i].rewiredPlayerId); - } - } - return null; - } - - private void Awake() - { - playerMap = new List(); - instance = this; - } - - private void Update() - { - for (int i = 0; i < ReInput.players.playerCount; i++) - { - if (ReInput.players.GetPlayer(i).GetButtonDown("JoinGame")) - { - AssignNextPlayer(i); - } - } - } - - private void AssignNextPlayer(int rewiredPlayerId) - { - if (playerMap.Count >= maxPlayers) - { - Debug.LogError("Max player limit already reached!"); - return; - } - int nextGamePlayerId = GetNextGamePlayerId(); - playerMap.Add(new PlayerMap(rewiredPlayerId, nextGamePlayerId)); - Player player = ReInput.players.GetPlayer(rewiredPlayerId); - player.controllers.maps.SetMapsEnabled(state: false, "Assignment"); - player.controllers.maps.SetMapsEnabled(state: true, "Default"); - Debug.Log("Added Rewired Player id " + rewiredPlayerId + " to game player " + nextGamePlayerId); - } - - private int GetNextGamePlayerId() - { - return gamePlayerIdCounter++; - } -} diff --git a/Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs b/Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs deleted file mode 100644 index 04ee6c4..0000000 --- a/Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs +++ /dev/null @@ -1,57 +0,0 @@ -using UnityEngine; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -[RequireComponent(typeof(CharacterController))] -public class PressStartToJoinExample_GamePlayer : MonoBehaviour -{ - public int gamePlayerId; - - public float moveSpeed = 3f; - - public float bulletSpeed = 15f; - - public GameObject bulletPrefab; - - private CharacterController cc; - - private Vector3 moveVector; - - private bool fire; - - private Player player => PressStartToJoinExample_Assigner.GetRewiredPlayer(gamePlayerId); - - private void OnEnable() - { - cc = GetComponent(); - } - - private void Update() - { - if (ReInput.isReady && player != null) - { - GetInput(); - ProcessInput(); - } - } - - private void GetInput() - { - moveVector.x = player.GetAxis("Move Horizontal"); - moveVector.y = player.GetAxis("Move Vertical"); - fire = player.GetButtonDown("Fire"); - } - - private void ProcessInput() - { - if (moveVector.x != 0f || moveVector.y != 0f) - { - cc.Move(moveVector * moveSpeed * Time.deltaTime); - } - if (fire) - { - Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange); - } - } -} diff --git a/Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs b/Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs deleted file mode 100644 index 3a2544b..0000000 --- a/Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs +++ /dev/null @@ -1,225 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -namespace Rewired.Demos; - -[AddComponentMenu("")] -public class SimpleCombinedKeyboardMouseRemapping : MonoBehaviour -{ - private class Row - { - public InputAction action; - - public AxisRange actionRange; - - public Button button; - - public Text text; - } - - private struct TargetMapping - { - public ControllerMap controllerMap; - - public int actionElementMapId; - } - - private const string category = "Default"; - - private const string layout = "Default"; - - private const string uiCategory = "UI"; - - private InputMapper inputMapper_keyboard = new InputMapper(); - - private InputMapper inputMapper_mouse = new InputMapper(); - - public GameObject buttonPrefab; - - public GameObject textPrefab; - - public RectTransform fieldGroupTransform; - - public RectTransform actionGroupTransform; - - public Text controllerNameUIText; - - public Text statusUIText; - - private List rows = new List(); - - private TargetMapping _replaceTargetMapping; - - private Player player => ReInput.players.GetPlayer(0); - - private void OnEnable() - { - if (ReInput.isReady) - { - inputMapper_keyboard.options.timeout = 5f; - inputMapper_mouse.options.timeout = 5f; - inputMapper_mouse.options.ignoreMouseXAxis = true; - inputMapper_mouse.options.ignoreMouseYAxis = true; - inputMapper_keyboard.options.allowButtonsOnFullAxisAssignment = false; - inputMapper_mouse.options.allowButtonsOnFullAxisAssignment = false; - inputMapper_keyboard.InputMappedEvent += OnInputMapped; - inputMapper_keyboard.StoppedEvent += OnStopped; - inputMapper_mouse.InputMappedEvent += OnInputMapped; - inputMapper_mouse.StoppedEvent += OnStopped; - InitializeUI(); - } - } - - private void OnDisable() - { - inputMapper_keyboard.Stop(); - inputMapper_mouse.Stop(); - inputMapper_keyboard.RemoveAllEventListeners(); - inputMapper_mouse.RemoveAllEventListeners(); - } - - private void RedrawUI() - { - controllerNameUIText.text = "Keyboard/Mouse"; - for (int i = 0; i < rows.Count; i++) - { - Row row = rows[i]; - InputAction action = rows[i].action; - string text = string.Empty; - int actionElementMapId = -1; - for (int j = 0; j < 2; j++) - { - ControllerType controllerType = ((j != 0) ? ControllerType.Mouse : ControllerType.Keyboard); - foreach (ActionElementMap item in player.controllers.maps.GetMap(controllerType, 0, "Default", "Default").ElementMapsWithAction(action.id)) - { - if (item.ShowInField(row.actionRange)) - { - text = item.elementIdentifierName; - actionElementMapId = item.id; - break; - } - } - if (actionElementMapId >= 0) - { - break; - } - } - row.text.text = text; - row.button.onClick.RemoveAllListeners(); - int index = i; - row.button.onClick.AddListener(delegate - { - OnInputFieldClicked(index, actionElementMapId); - }); - } - } - - private void ClearUI() - { - controllerNameUIText.text = string.Empty; - for (int i = 0; i < rows.Count; i++) - { - rows[i].text.text = string.Empty; - } - } - - private void InitializeUI() - { - foreach (Transform item in actionGroupTransform) - { - Object.Destroy(item.gameObject); - } - foreach (Transform item2 in fieldGroupTransform) - { - Object.Destroy(item2.gameObject); - } - foreach (InputAction item3 in ReInput.mapping.ActionsInCategory("Default")) - { - if (item3.type == InputActionType.Axis) - { - CreateUIRow(item3, AxisRange.Full, item3.descriptiveName); - CreateUIRow(item3, AxisRange.Positive, (!string.IsNullOrEmpty(item3.positiveDescriptiveName)) ? item3.positiveDescriptiveName : (item3.descriptiveName + " +")); - CreateUIRow(item3, AxisRange.Negative, (!string.IsNullOrEmpty(item3.negativeDescriptiveName)) ? item3.negativeDescriptiveName : (item3.descriptiveName + " -")); - } - else if (item3.type == InputActionType.Button) - { - CreateUIRow(item3, AxisRange.Positive, item3.descriptiveName); - } - } - RedrawUI(); - } - - private void CreateUIRow(InputAction action, AxisRange actionRange, string label) - { - GameObject obj = Object.Instantiate(textPrefab); - obj.transform.SetParent(actionGroupTransform); - obj.transform.SetAsLastSibling(); - obj.GetComponent().text = label; - GameObject gameObject = Object.Instantiate(buttonPrefab); - gameObject.transform.SetParent(fieldGroupTransform); - gameObject.transform.SetAsLastSibling(); - rows.Add(new Row - { - action = action, - actionRange = actionRange, - button = gameObject.GetComponent