diff options
| author | chai <215380520@qq.com> | 2024-05-19 16:05:01 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-05-19 16:05:01 +0800 |
| commit | c5f145786f4c6d2fe4bea831dfc16e52228920a5 (patch) | |
| tree | a6ead7ea8266c767d58ed0f816dcd7a1dd75bd65 /Rewired/Rewired.Integration.UnityUI | |
| parent | 48b64e573a1709dc923cb9162b55be0246b3ff63 (diff) | |
* move
Diffstat (limited to 'Rewired/Rewired.Integration.UnityUI')
5 files changed, 0 insertions, 2293 deletions
diff --git a/Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs b/Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs deleted file mode 100644 index 0c95915..0000000 --- a/Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Text; -using Rewired.UI; -using UnityEngine.EventSystems; - -namespace Rewired.Integration.UnityUI; - -public class PlayerPointerEventData : PointerEventData -{ - public int playerId { get; set; } - - public int inputSourceIndex { get; set; } - - public IMouseInputSource mouseSource { get; set; } - - public ITouchInputSource touchSource { get; set; } - - public PointerEventType sourceType { get; set; } - - public int buttonIndex { get; set; } - - public PlayerPointerEventData(EventSystem eventSystem) - : base(eventSystem) - { - playerId = -1; - inputSourceIndex = -1; - buttonIndex = -1; - } - - public override string ToString() - { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.AppendLine("<b>Player Id</b>: " + playerId); - stringBuilder.AppendLine("<b>Mouse Source</b>: " + mouseSource); - stringBuilder.AppendLine("<b>Input Source Index</b>: " + inputSourceIndex); - stringBuilder.AppendLine("<b>Touch Source/b>: " + touchSource); - stringBuilder.AppendLine("<b>Source Type</b>: " + sourceType); - stringBuilder.AppendLine("<b>Button Index</b>: " + buttonIndex); - stringBuilder.Append(base.ToString()); - return stringBuilder.ToString(); - } -} diff --git a/Rewired/Rewired.Integration.UnityUI/PointerEventType.cs b/Rewired/Rewired.Integration.UnityUI/PointerEventType.cs deleted file mode 100644 index ce70ee8..0000000 --- a/Rewired/Rewired.Integration.UnityUI/PointerEventType.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Rewired.Integration.UnityUI; - -public enum PointerEventType -{ - Mouse, - Touch -} diff --git a/Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs b/Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs deleted file mode 100644 index c46b002..0000000 --- a/Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs +++ /dev/null @@ -1,49 +0,0 @@ -using UnityEngine; -using UnityEngine.EventSystems; - -namespace Rewired.Integration.UnityUI; - -[AddComponentMenu("Rewired/Rewired Event System")] -public class RewiredEventSystem : EventSystem -{ - [Tooltip("If enabled, the Event System will be updated every frame even if other Event Systems are enabled. Otherwise, only EventSystem.current will be updated.")] - [SerializeField] - private bool _alwaysUpdate; - - public bool alwaysUpdate - { - get - { - return _alwaysUpdate; - } - set - { - _alwaysUpdate = value; - } - } - - protected override void Update() - { - if (alwaysUpdate) - { - EventSystem eventSystem = EventSystem.current; - if (eventSystem != this) - { - EventSystem.current = this; - } - try - { - base.Update(); - return; - } - finally - { - if (eventSystem != this) - { - EventSystem.current = eventSystem; - } - } - } - base.Update(); - } -} diff --git a/Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs b/Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs deleted file mode 100644 index 27d419b..0000000 --- a/Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs +++ /dev/null @@ -1,781 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Rewired.UI; -using Rewired.Utils; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace Rewired.Integration.UnityUI; - -public abstract class RewiredPointerInputModule : BaseInputModule -{ - protected class MouseState - { - private List<ButtonState> m_TrackedButtons = new List<ButtonState>(); - - public bool AnyPressesThisFrame() - { - for (int i = 0; i < m_TrackedButtons.Count; i++) - { - if (m_TrackedButtons[i].eventData.PressedThisFrame()) - { - return true; - } - } - return false; - } - - public bool AnyReleasesThisFrame() - { - for (int i = 0; i < m_TrackedButtons.Count; i++) - { - if (m_TrackedButtons[i].eventData.ReleasedThisFrame()) - { - return true; - } - } - return false; - } - - public ButtonState GetButtonState(int button) - { - ButtonState buttonState = null; - for (int i = 0; i < m_TrackedButtons.Count; i++) - { - if (m_TrackedButtons[i].button == button) - { - buttonState = m_TrackedButtons[i]; - break; - } - } - if (buttonState == null) - { - buttonState = new ButtonState - { - button = button, - eventData = new MouseButtonEventData() - }; - m_TrackedButtons.Add(buttonState); - } - return buttonState; - } - - public void SetButtonState(int button, PointerEventData.FramePressState stateForMouseButton, PlayerPointerEventData data) - { - ButtonState buttonState = GetButtonState(button); - buttonState.eventData.buttonState = stateForMouseButton; - buttonState.eventData.buttonData = data; - } - } - - public class MouseButtonEventData - { - public PointerEventData.FramePressState buttonState; - - public PlayerPointerEventData buttonData; - - public bool PressedThisFrame() - { - if (buttonState != 0) - { - return buttonState == PointerEventData.FramePressState.PressedAndReleased; - } - return true; - } - - public bool ReleasedThisFrame() - { - if (buttonState != PointerEventData.FramePressState.Released) - { - return buttonState == PointerEventData.FramePressState.PressedAndReleased; - } - return true; - } - } - - protected class ButtonState - { - private int m_Button; - - private MouseButtonEventData m_EventData; - - public MouseButtonEventData eventData - { - get - { - return m_EventData; - } - set - { - m_EventData = value; - } - } - - public int button - { - get - { - return m_Button; - } - set - { - m_Button = value; - } - } - } - - private sealed class UnityInputSource : IMouseInputSource, ITouchInputSource - { - private Vector2 m_MousePosition; - - private Vector2 m_MousePositionPrev; - - private int m_LastUpdatedFrame = -1; - - int IMouseInputSource.playerId - { - get - { - TryUpdate(); - return 0; - } - } - - int ITouchInputSource.playerId - { - get - { - TryUpdate(); - return 0; - } - } - - bool IMouseInputSource.enabled - { - get - { - TryUpdate(); - return Input.mousePresent; - } - } - - bool IMouseInputSource.locked - { - get - { - TryUpdate(); - return Cursor.lockState == CursorLockMode.Locked; - } - } - - int IMouseInputSource.buttonCount - { - get - { - TryUpdate(); - return 3; - } - } - - Vector2 IMouseInputSource.screenPosition - { - get - { - TryUpdate(); - return Input.mousePosition; - } - } - - Vector2 IMouseInputSource.screenPositionDelta - { - get - { - TryUpdate(); - return m_MousePosition - m_MousePositionPrev; - } - } - - Vector2 IMouseInputSource.wheelDelta - { - get - { - TryUpdate(); - return Input.mouseScrollDelta; - } - } - - bool ITouchInputSource.touchSupported - { - get - { - TryUpdate(); - return Input.touchSupported; - } - } - - int ITouchInputSource.touchCount - { - get - { - TryUpdate(); - return Input.touchCount; - } - } - - bool IMouseInputSource.GetButtonDown(int button) - { - TryUpdate(); - return Input.GetMouseButtonDown(button); - } - - bool IMouseInputSource.GetButtonUp(int button) - { - TryUpdate(); - return Input.GetMouseButtonUp(button); - } - - bool IMouseInputSource.GetButton(int button) - { - TryUpdate(); - return Input.GetMouseButton(button); - } - - Touch ITouchInputSource.GetTouch(int index) - { - TryUpdate(); - return Input.GetTouch(index); - } - - private void TryUpdate() - { - if (Time.frameCount != m_LastUpdatedFrame) - { - m_LastUpdatedFrame = Time.frameCount; - m_MousePositionPrev = m_MousePosition; - m_MousePosition = Input.mousePosition; - } - } - } - - public const int kMouseLeftId = -1; - - public const int kMouseRightId = -2; - - public const int kMouseMiddleId = -3; - - public const int kFakeTouchesId = -4; - - private const int customButtonsStartingId = -2147483520; - - private const int customButtonsMaxCount = 128; - - private const int customButtonsLastId = -2147483392; - - private readonly List<IMouseInputSource> m_MouseInputSourcesList = new List<IMouseInputSource>(); - - private Dictionary<int, Dictionary<int, PlayerPointerEventData>[]> m_PlayerPointerData = new Dictionary<int, Dictionary<int, PlayerPointerEventData>[]>(); - - private ITouchInputSource m_UserDefaultTouchInputSource; - - private UnityInputSource __m_DefaultInputSource; - - private readonly MouseState m_MouseState = new MouseState(); - - private UnityInputSource defaultInputSource - { - get - { - if (__m_DefaultInputSource == null) - { - return __m_DefaultInputSource = new UnityInputSource(); - } - return __m_DefaultInputSource; - } - } - - private IMouseInputSource defaultMouseInputSource => defaultInputSource; - - protected ITouchInputSource defaultTouchInputSource => defaultInputSource; - - protected virtual bool isMouseSupported - { - get - { - int count = m_MouseInputSourcesList.Count; - if (count == 0) - { - return defaultMouseInputSource.enabled; - } - for (int i = 0; i < count; i++) - { - if (m_MouseInputSourcesList[i].enabled) - { - return true; - } - } - return false; - } - } - - protected bool IsDefaultMouse(IMouseInputSource mouse) - { - return defaultMouseInputSource == mouse; - } - - public IMouseInputSource GetMouseInputSource(int playerId, int mouseIndex) - { - if (mouseIndex < 0) - { - throw new ArgumentOutOfRangeException("mouseIndex"); - } - if (m_MouseInputSourcesList.Count == 0 && IsDefaultPlayer(playerId)) - { - return defaultMouseInputSource; - } - int count = m_MouseInputSourcesList.Count; - int num = 0; - for (int i = 0; i < count; i++) - { - IMouseInputSource mouseInputSource = m_MouseInputSourcesList[i]; - if (!UnityTools.IsNullOrDestroyed(mouseInputSource) && mouseInputSource.playerId == playerId) - { - if (mouseIndex == num) - { - return mouseInputSource; - } - num++; - } - } - return null; - } - - public void RemoveMouseInputSource(IMouseInputSource source) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - m_MouseInputSourcesList.Remove(source); - } - - public void AddMouseInputSource(IMouseInputSource source) - { - if (UnityTools.IsNullOrDestroyed(source)) - { - throw new ArgumentNullException("source"); - } - m_MouseInputSourcesList.Add(source); - } - - public int GetMouseInputSourceCount(int playerId) - { - if (m_MouseInputSourcesList.Count == 0 && IsDefaultPlayer(playerId)) - { - return 1; - } - int count = m_MouseInputSourcesList.Count; - int num = 0; - for (int i = 0; i < count; i++) - { - IMouseInputSource mouseInputSource = m_MouseInputSourcesList[i]; - if (!UnityTools.IsNullOrDestroyed(mouseInputSource) && mouseInputSource.playerId == playerId) - { - num++; - } - } - return num; - } - - public ITouchInputSource GetTouchInputSource(int playerId, int sourceIndex) - { - if (!UnityTools.IsNullOrDestroyed(m_UserDefaultTouchInputSource)) - { - return m_UserDefaultTouchInputSource; - } - return defaultTouchInputSource; - } - - public void RemoveTouchInputSource(ITouchInputSource source) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (m_UserDefaultTouchInputSource == source) - { - m_UserDefaultTouchInputSource = null; - } - } - - public void AddTouchInputSource(ITouchInputSource source) - { - if (UnityTools.IsNullOrDestroyed(source)) - { - throw new ArgumentNullException("source"); - } - m_UserDefaultTouchInputSource = source; - } - - public int GetTouchInputSourceCount(int playerId) - { - if (!IsDefaultPlayer(playerId)) - { - return 0; - } - return 1; - } - - protected void ClearMouseInputSources() - { - m_MouseInputSourcesList.Clear(); - } - - protected abstract bool IsDefaultPlayer(int playerId); - - protected bool GetPointerData(int playerId, int pointerIndex, int pointerTypeId, out PlayerPointerEventData data, bool create, PointerEventType pointerEventType) - { - if (!m_PlayerPointerData.TryGetValue(playerId, out var value)) - { - value = new Dictionary<int, PlayerPointerEventData>[pointerIndex + 1]; - for (int i = 0; i < value.Length; i++) - { - value[i] = new Dictionary<int, PlayerPointerEventData>(); - } - m_PlayerPointerData.Add(playerId, value); - } - if (pointerIndex >= value.Length) - { - Dictionary<int, PlayerPointerEventData>[] array = new Dictionary<int, PlayerPointerEventData>[pointerIndex + 1]; - for (int j = 0; j < value.Length; j++) - { - array[j] = value[j]; - } - array[pointerIndex] = new Dictionary<int, PlayerPointerEventData>(); - value = array; - m_PlayerPointerData[playerId] = value; - } - Dictionary<int, PlayerPointerEventData> dictionary = value[pointerIndex]; - if (!dictionary.TryGetValue(pointerTypeId, out data)) - { - if (!create) - { - return false; - } - data = CreatePointerEventData(playerId, pointerIndex, pointerTypeId, pointerEventType); - dictionary.Add(pointerTypeId, data); - return true; - } - data.mouseSource = ((pointerEventType == PointerEventType.Mouse) ? GetMouseInputSource(playerId, pointerIndex) : null); - data.touchSource = ((pointerEventType == PointerEventType.Touch) ? GetTouchInputSource(playerId, pointerIndex) : null); - return false; - } - - private PlayerPointerEventData CreatePointerEventData(int playerId, int pointerIndex, int pointerTypeId, PointerEventType pointerEventType) - { - PlayerPointerEventData playerPointerEventData = new PlayerPointerEventData(base.eventSystem) - { - playerId = playerId, - inputSourceIndex = pointerIndex, - pointerId = pointerTypeId, - sourceType = pointerEventType - }; - switch (pointerEventType) - { - case PointerEventType.Mouse: - playerPointerEventData.mouseSource = GetMouseInputSource(playerId, pointerIndex); - break; - case PointerEventType.Touch: - playerPointerEventData.touchSource = GetTouchInputSource(playerId, pointerIndex); - break; - } - if (pointerTypeId == -1) - { - playerPointerEventData.buttonIndex = 0; - } - else if (pointerTypeId == -2) - { - playerPointerEventData.buttonIndex = 1; - } - else if (pointerTypeId == -3) - { - playerPointerEventData.buttonIndex = 2; - } - else if (pointerTypeId >= -2147483520 && pointerTypeId <= -2147483392) - { - playerPointerEventData.buttonIndex = pointerTypeId - -2147483520; - } - return playerPointerEventData; - } - - protected void RemovePointerData(PlayerPointerEventData data) - { - if (m_PlayerPointerData.TryGetValue(data.playerId, out var value) && (uint)data.inputSourceIndex < (uint)value.Length) - { - value[data.inputSourceIndex].Remove(data.pointerId); - } - } - - protected PlayerPointerEventData GetTouchPointerEventData(int playerId, int touchDeviceIndex, Touch input, out bool pressed, out bool released) - { - PlayerPointerEventData data; - bool pointerData = GetPointerData(playerId, touchDeviceIndex, input.fingerId, out data, create: true, PointerEventType.Touch); - data.Reset(); - pressed = pointerData || input.phase == TouchPhase.Began; - released = input.phase == TouchPhase.Canceled || input.phase == TouchPhase.Ended; - if (pointerData) - { - data.position = input.position; - } - if (pressed) - { - data.delta = Vector2.zero; - } - else - { - data.delta = input.position - data.position; - } - data.position = input.position; - data.button = PointerEventData.InputButton.Left; - base.eventSystem.RaycastAll(data, m_RaycastResultCache); - RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(m_RaycastResultCache); - data.pointerCurrentRaycast = pointerCurrentRaycast; - m_RaycastResultCache.Clear(); - return data; - } - - protected virtual MouseState GetMousePointerEventData(int playerId, int mouseIndex) - { - IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, mouseIndex); - if (mouseInputSource == null) - { - return null; - } - PlayerPointerEventData data; - bool pointerData = GetPointerData(playerId, mouseIndex, -1, out data, create: true, PointerEventType.Mouse); - data.Reset(); - if (pointerData) - { - data.position = mouseInputSource.screenPosition; - } - Vector2 screenPosition = mouseInputSource.screenPosition; - if (mouseInputSource.locked || !mouseInputSource.enabled) - { - data.position = new Vector2(-1f, -1f); - data.delta = Vector2.zero; - } - else - { - data.delta = screenPosition - data.position; - data.position = screenPosition; - } - data.scrollDelta = mouseInputSource.wheelDelta; - data.button = PointerEventData.InputButton.Left; - base.eventSystem.RaycastAll(data, m_RaycastResultCache); - RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(m_RaycastResultCache); - data.pointerCurrentRaycast = pointerCurrentRaycast; - m_RaycastResultCache.Clear(); - GetPointerData(playerId, mouseIndex, -2, out var data2, create: true, PointerEventType.Mouse); - CopyFromTo(data, data2); - data2.button = PointerEventData.InputButton.Right; - GetPointerData(playerId, mouseIndex, -3, out var data3, create: true, PointerEventType.Mouse); - CopyFromTo(data, data3); - data3.button = PointerEventData.InputButton.Middle; - for (int i = 3; i < mouseInputSource.buttonCount; i++) - { - GetPointerData(playerId, mouseIndex, -2147483520 + i, out var data4, create: true, PointerEventType.Mouse); - CopyFromTo(data, data4); - data4.button = (PointerEventData.InputButton)(-1); - } - m_MouseState.SetButtonState(0, StateForMouseButton(playerId, mouseIndex, 0), data); - m_MouseState.SetButtonState(1, StateForMouseButton(playerId, mouseIndex, 1), data2); - m_MouseState.SetButtonState(2, StateForMouseButton(playerId, mouseIndex, 2), data3); - for (int j = 3; j < mouseInputSource.buttonCount; j++) - { - GetPointerData(playerId, mouseIndex, -2147483520 + j, out var data5, create: false, PointerEventType.Mouse); - m_MouseState.SetButtonState(j, StateForMouseButton(playerId, mouseIndex, j), data5); - } - return m_MouseState; - } - - protected PlayerPointerEventData GetLastPointerEventData(int playerId, int pointerIndex, int pointerTypeId, bool ignorePointerTypeId, PointerEventType pointerEventType) - { - if (!ignorePointerTypeId) - { - GetPointerData(playerId, pointerIndex, pointerTypeId, out var data, create: false, pointerEventType); - return data; - } - if (!m_PlayerPointerData.TryGetValue(playerId, out var value)) - { - return null; - } - if ((uint)pointerIndex >= (uint)value.Length) - { - return null; - } - using (Dictionary<int, PlayerPointerEventData>.Enumerator enumerator = value[pointerIndex].GetEnumerator()) - { - if (enumerator.MoveNext()) - { - return enumerator.Current.Value; - } - } - return null; - } - - private static bool ShouldStartDrag(Vector2 pressPos, Vector2 currentPos, float threshold, bool useDragThreshold) - { - if (!useDragThreshold) - { - return true; - } - return (pressPos - currentPos).sqrMagnitude >= threshold * threshold; - } - - protected virtual void ProcessMove(PlayerPointerEventData pointerEvent) - { - GameObject newEnterTarget; - if (pointerEvent.sourceType == PointerEventType.Mouse) - { - IMouseInputSource mouseInputSource = GetMouseInputSource(pointerEvent.playerId, pointerEvent.inputSourceIndex); - newEnterTarget = ((mouseInputSource == null) ? null : ((!mouseInputSource.enabled || mouseInputSource.locked) ? null : pointerEvent.pointerCurrentRaycast.gameObject)); - } - else - { - if (pointerEvent.sourceType != PointerEventType.Touch) - { - throw new NotImplementedException(); - } - newEnterTarget = pointerEvent.pointerCurrentRaycast.gameObject; - } - HandlePointerExitAndEnter(pointerEvent, newEnterTarget); - } - - protected virtual void ProcessDrag(PlayerPointerEventData pointerEvent) - { - if (!pointerEvent.IsPointerMoving() || pointerEvent.pointerDrag == null) - { - return; - } - if (pointerEvent.sourceType == PointerEventType.Mouse) - { - IMouseInputSource mouseInputSource = GetMouseInputSource(pointerEvent.playerId, pointerEvent.inputSourceIndex); - if (mouseInputSource == null || mouseInputSource.locked || !mouseInputSource.enabled) - { - return; - } - } - if (!pointerEvent.dragging && ShouldStartDrag(pointerEvent.pressPosition, pointerEvent.position, base.eventSystem.pixelDragThreshold, pointerEvent.useDragThreshold)) - { - ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler); - pointerEvent.dragging = true; - } - if (pointerEvent.dragging) - { - if (pointerEvent.pointerPress != pointerEvent.pointerDrag) - { - ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); - pointerEvent.eligibleForClick = false; - pointerEvent.pointerPress = null; - pointerEvent.rawPointerPress = null; - } - ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); - } - } - - public override bool IsPointerOverGameObject(int pointerTypeId) - { - foreach (KeyValuePair<int, Dictionary<int, PlayerPointerEventData>[]> playerPointerDatum in m_PlayerPointerData) - { - Dictionary<int, PlayerPointerEventData>[] value = playerPointerDatum.Value; - for (int i = 0; i < value.Length; i++) - { - if (value[i].TryGetValue(pointerTypeId, out var value2) && value2.pointerEnter != null) - { - return true; - } - } - } - return false; - } - - protected void ClearSelection() - { - BaseEventData baseEventData = GetBaseEventData(); - foreach (KeyValuePair<int, Dictionary<int, PlayerPointerEventData>[]> playerPointerDatum in m_PlayerPointerData) - { - Dictionary<int, PlayerPointerEventData>[] value = playerPointerDatum.Value; - for (int i = 0; i < value.Length; i++) - { - foreach (KeyValuePair<int, PlayerPointerEventData> item in value[i]) - { - HandlePointerExitAndEnter(item.Value, null); - } - value[i].Clear(); - } - } - base.eventSystem.SetSelectedGameObject(null, baseEventData); - } - - public override string ToString() - { - StringBuilder stringBuilder = new StringBuilder("<b>Pointer Input Module of type: </b>" + GetType()); - stringBuilder.AppendLine(); - foreach (KeyValuePair<int, Dictionary<int, PlayerPointerEventData>[]> playerPointerDatum in m_PlayerPointerData) - { - stringBuilder.AppendLine("<B>Player Id:</b> " + playerPointerDatum.Key); - Dictionary<int, PlayerPointerEventData>[] value = playerPointerDatum.Value; - for (int i = 0; i < value.Length; i++) - { - stringBuilder.AppendLine("<B>Pointer Index:</b> " + i); - foreach (KeyValuePair<int, PlayerPointerEventData> item in value[i]) - { - stringBuilder.AppendLine("<B>Button Id:</b> " + item.Key); - stringBuilder.AppendLine(item.Value.ToString()); - } - } - } - return stringBuilder.ToString(); - } - - protected void DeselectIfSelectionChanged(GameObject currentOverGo, BaseEventData pointerEvent) - { - if (ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo) != base.eventSystem.currentSelectedGameObject) - { - base.eventSystem.SetSelectedGameObject(null, pointerEvent); - } - } - - protected void CopyFromTo(PointerEventData from, PointerEventData to) - { - to.position = from.position; - to.delta = from.delta; - to.scrollDelta = from.scrollDelta; - to.pointerCurrentRaycast = from.pointerCurrentRaycast; - to.pointerEnter = from.pointerEnter; - } - - protected PointerEventData.FramePressState StateForMouseButton(int playerId, int mouseIndex, int buttonId) - { - IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, mouseIndex); - if (mouseInputSource == null) - { - return PointerEventData.FramePressState.NotChanged; - } - bool buttonDown = mouseInputSource.GetButtonDown(buttonId); - bool buttonUp = mouseInputSource.GetButtonUp(buttonId); - if (buttonDown && buttonUp) - { - return PointerEventData.FramePressState.PressedAndReleased; - } - if (buttonDown) - { - return PointerEventData.FramePressState.Pressed; - } - if (buttonUp) - { - return PointerEventData.FramePressState.Released; - } - return PointerEventData.FramePressState.NotChanged; - } -} diff --git a/Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs b/Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs deleted file mode 100644 index 02245ab..0000000 --- a/Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs +++ /dev/null @@ -1,1415 +0,0 @@ -using System; -using System.Collections.Generic; -using Rewired.Components; -using Rewired.UI; -using Rewired.Utils; -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.Serialization; - -namespace Rewired.Integration.UnityUI; - -[AddComponentMenu("Rewired/Rewired Standalone Input Module")] -public sealed class RewiredStandaloneInputModule : RewiredPointerInputModule -{ - [Serializable] - public class PlayerSetting - { - public int playerId; - - public List<Rewired.Components.PlayerMouse> playerMice = new List<Rewired.Components.PlayerMouse>(); - - public PlayerSetting() - { - } - - private PlayerSetting(PlayerSetting other) - { - if (other == null) - { - throw new ArgumentNullException("other"); - } - playerId = other.playerId; - playerMice = new List<Rewired.Components.PlayerMouse>(); - if (other.playerMice == null) - { - return; - } - foreach (Rewired.Components.PlayerMouse item in other.playerMice) - { - playerMice.Add(item); - } - } - - public PlayerSetting Clone() - { - return new PlayerSetting(this); - } - } - - private const string DEFAULT_ACTION_MOVE_HORIZONTAL = "UIHorizontal"; - - private const string DEFAULT_ACTION_MOVE_VERTICAL = "UIVertical"; - - private const string DEFAULT_ACTION_SUBMIT = "UISubmit"; - - private const string DEFAULT_ACTION_CANCEL = "UICancel"; - - [Tooltip("(Optional) Link the Rewired Input Manager here for easier access to Player ids, etc.")] - [SerializeField] - private InputManager_Base rewiredInputManager; - - [SerializeField] - [Tooltip("Use all Rewired game Players to control the UI. This does not include the System Player. If enabled, this setting overrides individual Player Ids set in Rewired Player Ids.")] - private bool useAllRewiredGamePlayers; - - [SerializeField] - [Tooltip("Allow the Rewired System Player to control the UI.")] - private bool useRewiredSystemPlayer; - - [SerializeField] - [Tooltip("A list of Player Ids that are allowed to control the UI. If Use All Rewired Game Players = True, this list will be ignored.")] - private int[] rewiredPlayerIds = new int[1]; - - [SerializeField] - [Tooltip("Allow only Players with Player.isPlaying = true to control the UI.")] - private bool usePlayingPlayersOnly; - - [SerializeField] - [Tooltip("Player Mice allowed to interact with the UI. Each Player that owns a Player Mouse must also be allowed to control the UI or the Player Mouse will not function.")] - private List<Rewired.Components.PlayerMouse> playerMice = new List<Rewired.Components.PlayerMouse>(); - - [SerializeField] - [Tooltip("Makes an axis press always move only one UI selection. Enable if you do not want to allow scrolling through UI elements by holding an axis direction.")] - private bool moveOneElementPerAxisPress; - - [SerializeField] - [Tooltip("If enabled, Action Ids will be used to set the Actions. If disabled, string names will be used to set the Actions.")] - private bool setActionsById; - - [SerializeField] - [Tooltip("Id of the horizontal Action for movement (if axis events are used).")] - private int horizontalActionId = -1; - - [SerializeField] - [Tooltip("Id of the vertical Action for movement (if axis events are used).")] - private int verticalActionId = -1; - - [SerializeField] - [Tooltip("Id of the Action used to submit.")] - private int submitActionId = -1; - - [SerializeField] - [Tooltip("Id of the Action used to cancel.")] - private int cancelActionId = -1; - - [SerializeField] - [Tooltip("Name of the horizontal axis for movement (if axis events are used).")] - private string m_HorizontalAxis = "UIHorizontal"; - - [SerializeField] - [Tooltip("Name of the vertical axis for movement (if axis events are used).")] - private string m_VerticalAxis = "UIVertical"; - - [SerializeField] - [Tooltip("Name of the action used to submit.")] - private string m_SubmitButton = "UISubmit"; - - [SerializeField] - [Tooltip("Name of the action used to cancel.")] - private string m_CancelButton = "UICancel"; - - [SerializeField] - [Tooltip("Number of selection changes allowed per second when a movement button/axis is held in a direction.")] - private float m_InputActionsPerSecond = 10f; - - [SerializeField] - [Tooltip("Delay in seconds before vertical/horizontal movement starts repeating continouously when a movement direction is held.")] - private float m_RepeatDelay; - - [SerializeField] - [Tooltip("Allows the mouse to be used to select elements.")] - private bool m_allowMouseInput = true; - - [SerializeField] - [Tooltip("Allows the mouse to be used to select elements if the device also supports touch control.")] - private bool m_allowMouseInputIfTouchSupported = true; - - [SerializeField] - [Tooltip("Allows touch input to be used to select elements.")] - private bool m_allowTouchInput = true; - - [SerializeField] - [Tooltip("Deselects the current selection on mouse/touch click when the pointer is not over a selectable object.")] - private bool m_deselectIfBackgroundClicked = true; - - [SerializeField] - [Tooltip("Deselects the current selection on mouse/touch click before selecting the next object.")] - private bool m_deselectBeforeSelecting = true; - - [SerializeField] - [FormerlySerializedAs("m_AllowActivationOnMobileDevice")] - [Tooltip("Forces the module to always be active.")] - private bool m_ForceModuleActive; - - [NonSerialized] - private int[] playerIds; - - private bool recompiling; - - [NonSerialized] - private bool isTouchSupported; - - [NonSerialized] - private double m_PrevActionTime; - - [NonSerialized] - private Vector2 m_LastMoveVector; - - [NonSerialized] - private int m_ConsecutiveMoveCount; - - [NonSerialized] - private bool m_HasFocus = true; - - public InputManager_Base RewiredInputManager - { - get - { - return rewiredInputManager; - } - set - { - rewiredInputManager = value; - } - } - - public bool UseAllRewiredGamePlayers - { - get - { - return useAllRewiredGamePlayers; - } - set - { - bool num = value != useAllRewiredGamePlayers; - useAllRewiredGamePlayers = value; - if (num) - { - SetupRewiredVars(); - } - } - } - - public bool UseRewiredSystemPlayer - { - get - { - return useRewiredSystemPlayer; - } - set - { - bool num = value != useRewiredSystemPlayer; - useRewiredSystemPlayer = value; - if (num) - { - SetupRewiredVars(); - } - } - } - - public int[] RewiredPlayerIds - { - get - { - return (int[])rewiredPlayerIds.Clone(); - } - set - { - rewiredPlayerIds = ((value != null) ? ((int[])value.Clone()) : new int[0]); - SetupRewiredVars(); - } - } - - public bool UsePlayingPlayersOnly - { - get - { - return usePlayingPlayersOnly; - } - set - { - usePlayingPlayersOnly = value; - } - } - - public List<Rewired.Components.PlayerMouse> PlayerMice - { - get - { - return new List<Rewired.Components.PlayerMouse>(playerMice); - } - set - { - if (value == null) - { - playerMice = new List<Rewired.Components.PlayerMouse>(); - SetupRewiredVars(); - } - else - { - playerMice = new List<Rewired.Components.PlayerMouse>(value); - SetupRewiredVars(); - } - } - } - - public bool MoveOneElementPerAxisPress - { - get - { - return moveOneElementPerAxisPress; - } - set - { - moveOneElementPerAxisPress = value; - } - } - - public bool allowMouseInput - { - get - { - return m_allowMouseInput; - } - set - { - m_allowMouseInput = value; - } - } - - public bool allowMouseInputIfTouchSupported - { - get - { - return m_allowMouseInputIfTouchSupported; - } - set - { - m_allowMouseInputIfTouchSupported = value; - } - } - - public bool allowTouchInput - { - get - { - return m_allowTouchInput; - } - set - { - m_allowTouchInput = value; - } - } - - public bool deselectIfBackgroundClicked - { - get - { - return m_deselectIfBackgroundClicked; - } - set - { - m_deselectIfBackgroundClicked = value; - } - } - - private bool deselectBeforeSelecting - { - get - { - return m_deselectBeforeSelecting; - } - set - { - m_deselectBeforeSelecting = value; - } - } - - public bool SetActionsById - { - get - { - return setActionsById; - } - set - { - if (setActionsById != value) - { - setActionsById = value; - SetupRewiredVars(); - } - } - } - - public int HorizontalActionId - { - get - { - return horizontalActionId; - } - set - { - if (value != horizontalActionId) - { - horizontalActionId = value; - if (ReInput.isReady) - { - m_HorizontalAxis = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); - } - } - } - } - - public int VerticalActionId - { - get - { - return verticalActionId; - } - set - { - if (value != verticalActionId) - { - verticalActionId = value; - if (ReInput.isReady) - { - m_VerticalAxis = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); - } - } - } - } - - public int SubmitActionId - { - get - { - return submitActionId; - } - set - { - if (value != submitActionId) - { - submitActionId = value; - if (ReInput.isReady) - { - m_SubmitButton = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); - } - } - } - } - - public int CancelActionId - { - get - { - return cancelActionId; - } - set - { - if (value != cancelActionId) - { - cancelActionId = value; - if (ReInput.isReady) - { - m_CancelButton = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); - } - } - } - } - - protected override bool isMouseSupported - { - get - { - if (!base.isMouseSupported) - { - return false; - } - if (!m_allowMouseInput) - { - return false; - } - if (!isTouchSupported) - { - return true; - } - return m_allowMouseInputIfTouchSupported; - } - } - - private bool isTouchAllowed => m_allowTouchInput; - - [Obsolete("allowActivationOnMobileDevice has been deprecated. Use forceModuleActive instead")] - public bool allowActivationOnMobileDevice - { - get - { - return m_ForceModuleActive; - } - set - { - m_ForceModuleActive = value; - } - } - - public bool forceModuleActive - { - get - { - return m_ForceModuleActive; - } - set - { - m_ForceModuleActive = value; - } - } - - public float inputActionsPerSecond - { - get - { - return m_InputActionsPerSecond; - } - set - { - m_InputActionsPerSecond = value; - } - } - - public float repeatDelay - { - get - { - return m_RepeatDelay; - } - set - { - m_RepeatDelay = value; - } - } - - public string horizontalAxis - { - get - { - return m_HorizontalAxis; - } - set - { - if (!(m_HorizontalAxis == value)) - { - m_HorizontalAxis = value; - if (ReInput.isReady) - { - horizontalActionId = ReInput.mapping.GetActionId(value); - } - } - } - } - - public string verticalAxis - { - get - { - return m_VerticalAxis; - } - set - { - if (!(m_VerticalAxis == value)) - { - m_VerticalAxis = value; - if (ReInput.isReady) - { - verticalActionId = ReInput.mapping.GetActionId(value); - } - } - } - } - - public string submitButton - { - get - { - return m_SubmitButton; - } - set - { - if (!(m_SubmitButton == value)) - { - m_SubmitButton = value; - if (ReInput.isReady) - { - submitActionId = ReInput.mapping.GetActionId(value); - } - } - } - } - - public string cancelButton - { - get - { - return m_CancelButton; - } - set - { - if (!(m_CancelButton == value)) - { - m_CancelButton = value; - if (ReInput.isReady) - { - cancelActionId = ReInput.mapping.GetActionId(value); - } - } - } - } - - private RewiredStandaloneInputModule() - { - } - - protected override void Awake() - { - base.Awake(); - isTouchSupported = base.defaultTouchInputSource.touchSupported; - TouchInputModule component = GetComponent<TouchInputModule>(); - if (component != null) - { - component.enabled = false; - } - ReInput.InitializedEvent += OnRewiredInitialized; - InitializeRewired(); - } - - public override void UpdateModule() - { - CheckEditorRecompile(); - if (!recompiling && ReInput.isReady && !m_HasFocus) - { - ShouldIgnoreEventsOnNoFocus(); - } - } - - public override bool IsModuleSupported() - { - return true; - } - - public override bool ShouldActivateModule() - { - if (!base.ShouldActivateModule()) - { - return false; - } - if (recompiling) - { - return false; - } - if (!ReInput.isReady) - { - return false; - } - bool flag = m_ForceModuleActive; - for (int i = 0; i < playerIds.Length; i++) - { - Player player = ReInput.players.GetPlayer(playerIds[i]); - if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) - { - flag |= GetButtonDown(player, submitActionId); - flag |= GetButtonDown(player, cancelActionId); - if (moveOneElementPerAxisPress) - { - flag |= GetButtonDown(player, horizontalActionId) || GetNegativeButtonDown(player, horizontalActionId); - flag |= GetButtonDown(player, verticalActionId) || GetNegativeButtonDown(player, verticalActionId); - } - else - { - flag |= !Mathf.Approximately(GetAxis(player, horizontalActionId), 0f); - flag |= !Mathf.Approximately(GetAxis(player, verticalActionId), 0f); - } - } - } - if (isMouseSupported) - { - flag |= DidAnyMouseMove(); - flag |= GetMouseButtonDownOnAnyMouse(0); - } - if (isTouchAllowed) - { - for (int j = 0; j < base.defaultTouchInputSource.touchCount; j++) - { - Touch touch = base.defaultTouchInputSource.GetTouch(j); - flag |= touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary; - } - } - return flag; - } - - public override void ActivateModule() - { - if (m_HasFocus || !ShouldIgnoreEventsOnNoFocus()) - { - base.ActivateModule(); - GameObject gameObject = base.eventSystem.currentSelectedGameObject; - if (gameObject == null) - { - gameObject = base.eventSystem.firstSelectedGameObject; - } - base.eventSystem.SetSelectedGameObject(gameObject, GetBaseEventData()); - } - } - - public override void DeactivateModule() - { - base.DeactivateModule(); - ClearSelection(); - } - - public override void Process() - { - if (!ReInput.isReady || (!m_HasFocus && ShouldIgnoreEventsOnNoFocus()) || !base.enabled || !base.gameObject.activeInHierarchy) - { - return; - } - bool flag = SendUpdateEventToSelectedObject(); - if (base.eventSystem.sendNavigationEvents) - { - if (!flag) - { - flag |= SendMoveEventToSelectedObject(); - } - if (!flag) - { - SendSubmitEventToSelectedObject(); - } - } - if (!ProcessTouchEvents() && isMouseSupported) - { - ProcessMouseEvents(); - } - } - - private bool ProcessTouchEvents() - { - if (!isTouchAllowed) - { - return false; - } - for (int i = 0; i < base.defaultTouchInputSource.touchCount; i++) - { - Touch touch = base.defaultTouchInputSource.GetTouch(i); - if (touch.type != TouchType.Indirect) - { - bool pressed; - bool released; - PlayerPointerEventData touchPointerEventData = GetTouchPointerEventData(0, 0, touch, out pressed, out released); - ProcessTouchPress(touchPointerEventData, pressed, released); - if (!released) - { - ProcessMove(touchPointerEventData); - ProcessDrag(touchPointerEventData); - } - else - { - RemovePointerData(touchPointerEventData); - } - } - } - return base.defaultTouchInputSource.touchCount > 0; - } - - private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) - { - GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject; - if (pressed) - { - pointerEvent.eligibleForClick = true; - pointerEvent.delta = Vector2.zero; - pointerEvent.dragging = false; - pointerEvent.useDragThreshold = true; - pointerEvent.pressPosition = pointerEvent.position; - pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; - HandleMouseTouchDeselectionOnSelectionChanged(gameObject, pointerEvent); - if (pointerEvent.pointerEnter != gameObject) - { - HandlePointerExitAndEnter(pointerEvent, gameObject); - pointerEvent.pointerEnter = gameObject; - } - GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler); - if (gameObject2 == null) - { - gameObject2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); - } - double unscaledTime = ReInput.time.unscaledTime; - if (gameObject2 == pointerEvent.lastPress) - { - if (unscaledTime - (double)pointerEvent.clickTime < 0.30000001192092896) - { - int clickCount = pointerEvent.clickCount + 1; - pointerEvent.clickCount = clickCount; - } - else - { - pointerEvent.clickCount = 1; - } - pointerEvent.clickTime = (float)unscaledTime; - } - else - { - pointerEvent.clickCount = 1; - } - pointerEvent.pointerPress = gameObject2; - pointerEvent.rawPointerPress = gameObject; - pointerEvent.clickTime = (float)unscaledTime; - pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(gameObject); - if (pointerEvent.pointerDrag != null) - { - ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); - } - } - if (released) - { - ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); - GameObject eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); - if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick) - { - ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); - } - else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) - { - ExecuteEvents.ExecuteHierarchy(gameObject, pointerEvent, ExecuteEvents.dropHandler); - } - pointerEvent.eligibleForClick = false; - pointerEvent.pointerPress = null; - pointerEvent.rawPointerPress = null; - if (pointerEvent.pointerDrag != null && pointerEvent.dragging) - { - ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); - } - pointerEvent.dragging = false; - pointerEvent.pointerDrag = null; - if (pointerEvent.pointerDrag != null) - { - ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); - } - pointerEvent.pointerDrag = null; - ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler); - pointerEvent.pointerEnter = null; - } - } - - private bool SendSubmitEventToSelectedObject() - { - if (base.eventSystem.currentSelectedGameObject == null) - { - return false; - } - if (recompiling) - { - return false; - } - BaseEventData baseEventData = GetBaseEventData(); - for (int i = 0; i < playerIds.Length; i++) - { - Player player = ReInput.players.GetPlayer(playerIds[i]); - if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) - { - if (GetButtonDown(player, submitActionId)) - { - ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, baseEventData, ExecuteEvents.submitHandler); - break; - } - if (GetButtonDown(player, cancelActionId)) - { - ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, baseEventData, ExecuteEvents.cancelHandler); - break; - } - } - } - return baseEventData.used; - } - - private Vector2 GetRawMoveVector() - { - if (recompiling) - { - return Vector2.zero; - } - Vector2 zero = Vector2.zero; - for (int i = 0; i < playerIds.Length; i++) - { - Player player = ReInput.players.GetPlayer(playerIds[i]); - if (player == null || (usePlayingPlayersOnly && !player.isPlaying)) - { - continue; - } - float num = GetAxis(player, horizontalActionId); - float num2 = GetAxis(player, verticalActionId); - if (Mathf.Approximately(num, 0f)) - { - num = 0f; - } - if (Mathf.Approximately(num2, 0f)) - { - num2 = 0f; - } - if (moveOneElementPerAxisPress) - { - if (GetButtonDown(player, horizontalActionId) && num > 0f) - { - zero.x += 1f; - } - if (GetNegativeButtonDown(player, horizontalActionId) && num < 0f) - { - zero.x -= 1f; - } - if (GetButtonDown(player, verticalActionId) && num2 > 0f) - { - zero.y += 1f; - } - if (GetNegativeButtonDown(player, verticalActionId) && num2 < 0f) - { - zero.y -= 1f; - } - } - else - { - if (GetButton(player, horizontalActionId) && num > 0f) - { - zero.x += 1f; - } - if (GetNegativeButton(player, horizontalActionId) && num < 0f) - { - zero.x -= 1f; - } - if (GetButton(player, verticalActionId) && num2 > 0f) - { - zero.y += 1f; - } - if (GetNegativeButton(player, verticalActionId) && num2 < 0f) - { - zero.y -= 1f; - } - } - } - return zero; - } - - private bool SendMoveEventToSelectedObject() - { - if (recompiling) - { - return false; - } - double unscaledTime = ReInput.time.unscaledTime; - Vector2 rawMoveVector = GetRawMoveVector(); - if (Mathf.Approximately(rawMoveVector.x, 0f) && Mathf.Approximately(rawMoveVector.y, 0f)) - { - m_ConsecutiveMoveCount = 0; - return false; - } - bool flag = Vector2.Dot(rawMoveVector, m_LastMoveVector) > 0f; - CheckButtonOrKeyMovement(out var downHorizontal, out var downVertical); - AxisEventData axisEventData = null; - bool flag2 = downHorizontal || downVertical; - if (flag2) - { - axisEventData = GetAxisEventData(rawMoveVector.x, rawMoveVector.y, 0f); - MoveDirection moveDir = axisEventData.moveDir; - flag2 = ((moveDir == MoveDirection.Up || moveDir == MoveDirection.Down) && downVertical) || ((moveDir == MoveDirection.Left || moveDir == MoveDirection.Right) && downHorizontal); - } - if (!flag2) - { - flag2 = ((!(m_RepeatDelay > 0f)) ? (unscaledTime > m_PrevActionTime + (double)(1f / m_InputActionsPerSecond)) : ((!flag || m_ConsecutiveMoveCount != 1) ? (unscaledTime > m_PrevActionTime + (double)(1f / m_InputActionsPerSecond)) : (unscaledTime > m_PrevActionTime + (double)m_RepeatDelay))); - } - if (!flag2) - { - return false; - } - if (axisEventData == null) - { - axisEventData = GetAxisEventData(rawMoveVector.x, rawMoveVector.y, 0f); - } - if (axisEventData.moveDir != MoveDirection.None) - { - ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); - if (!flag) - { - m_ConsecutiveMoveCount = 0; - } - if (m_ConsecutiveMoveCount == 0 || !(downHorizontal || downVertical)) - { - m_ConsecutiveMoveCount++; - } - m_PrevActionTime = unscaledTime; - m_LastMoveVector = rawMoveVector; - } - else - { - m_ConsecutiveMoveCount = 0; - } - return axisEventData.used; - } - - private void CheckButtonOrKeyMovement(out bool downHorizontal, out bool downVertical) - { - downHorizontal = false; - downVertical = false; - for (int i = 0; i < playerIds.Length; i++) - { - Player player = ReInput.players.GetPlayer(playerIds[i]); - if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) - { - downHorizontal |= GetButtonDown(player, horizontalActionId) || GetNegativeButtonDown(player, horizontalActionId); - downVertical |= GetButtonDown(player, verticalActionId) || GetNegativeButtonDown(player, verticalActionId); - } - } - } - - private void ProcessMouseEvents() - { - for (int i = 0; i < playerIds.Length; i++) - { - Player player = ReInput.players.GetPlayer(playerIds[i]); - if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) - { - int mouseInputSourceCount = GetMouseInputSourceCount(playerIds[i]); - for (int j = 0; j < mouseInputSourceCount; j++) - { - ProcessMouseEvent(playerIds[i], j); - } - } - } - } - - private void ProcessMouseEvent(int playerId, int pointerIndex) - { - MouseState mousePointerEventData = GetMousePointerEventData(playerId, pointerIndex); - if (mousePointerEventData == null) - { - return; - } - MouseButtonEventData eventData = mousePointerEventData.GetButtonState(0).eventData; - ProcessMousePress(eventData); - ProcessMove(eventData.buttonData); - ProcessDrag(eventData.buttonData); - ProcessMousePress(mousePointerEventData.GetButtonState(1).eventData); - ProcessDrag(mousePointerEventData.GetButtonState(1).eventData.buttonData); - ProcessMousePress(mousePointerEventData.GetButtonState(2).eventData); - ProcessDrag(mousePointerEventData.GetButtonState(2).eventData.buttonData); - IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, pointerIndex); - if (mouseInputSource != null) - { - for (int i = 3; i < mouseInputSource.buttonCount; i++) - { - ProcessMousePress(mousePointerEventData.GetButtonState(i).eventData); - ProcessDrag(mousePointerEventData.GetButtonState(i).eventData.buttonData); - } - if (!Mathf.Approximately(eventData.buttonData.scrollDelta.sqrMagnitude, 0f)) - { - ExecuteEvents.ExecuteHierarchy(ExecuteEvents.GetEventHandler<IScrollHandler>(eventData.buttonData.pointerCurrentRaycast.gameObject), eventData.buttonData, ExecuteEvents.scrollHandler); - } - } - } - - private bool SendUpdateEventToSelectedObject() - { - if (base.eventSystem.currentSelectedGameObject == null) - { - return false; - } - BaseEventData baseEventData = GetBaseEventData(); - ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, baseEventData, ExecuteEvents.updateSelectedHandler); - return baseEventData.used; - } - - private void ProcessMousePress(MouseButtonEventData data) - { - PlayerPointerEventData buttonData = data.buttonData; - if (GetMouseInputSource(buttonData.playerId, buttonData.inputSourceIndex) == null) - { - return; - } - GameObject gameObject = buttonData.pointerCurrentRaycast.gameObject; - if (data.PressedThisFrame()) - { - buttonData.eligibleForClick = true; - buttonData.delta = Vector2.zero; - buttonData.dragging = false; - buttonData.useDragThreshold = true; - buttonData.pressPosition = buttonData.position; - buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast; - HandleMouseTouchDeselectionOnSelectionChanged(gameObject, buttonData); - GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy(gameObject, buttonData, ExecuteEvents.pointerDownHandler); - if (gameObject2 == null) - { - gameObject2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); - } - double unscaledTime = ReInput.time.unscaledTime; - if (gameObject2 == buttonData.lastPress) - { - if (unscaledTime - (double)buttonData.clickTime < 0.30000001192092896) - { - int clickCount = buttonData.clickCount + 1; - buttonData.clickCount = clickCount; - } - else - { - buttonData.clickCount = 1; - } - buttonData.clickTime = (float)unscaledTime; - } - else - { - buttonData.clickCount = 1; - } - buttonData.pointerPress = gameObject2; - buttonData.rawPointerPress = gameObject; - buttonData.clickTime = (float)unscaledTime; - buttonData.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(gameObject); - if (buttonData.pointerDrag != null) - { - ExecuteEvents.Execute(buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag); - } - } - if (data.ReleasedThisFrame()) - { - ExecuteEvents.Execute(buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler); - GameObject eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); - if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick) - { - ExecuteEvents.Execute(buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler); - } - else if (buttonData.pointerDrag != null && buttonData.dragging) - { - ExecuteEvents.ExecuteHierarchy(gameObject, buttonData, ExecuteEvents.dropHandler); - } - buttonData.eligibleForClick = false; - buttonData.pointerPress = null; - buttonData.rawPointerPress = null; - if (buttonData.pointerDrag != null && buttonData.dragging) - { - ExecuteEvents.Execute(buttonData.pointerDrag, buttonData, ExecuteEvents.endDragHandler); - } - buttonData.dragging = false; - buttonData.pointerDrag = null; - if (gameObject != buttonData.pointerEnter) - { - HandlePointerExitAndEnter(buttonData, null); - HandlePointerExitAndEnter(buttonData, gameObject); - } - } - } - - private void HandleMouseTouchDeselectionOnSelectionChanged(GameObject currentOverGo, BaseEventData pointerEvent) - { - if (m_deselectIfBackgroundClicked && m_deselectBeforeSelecting) - { - DeselectIfSelectionChanged(currentOverGo, pointerEvent); - return; - } - GameObject eventHandler = ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo); - if (m_deselectIfBackgroundClicked) - { - if (eventHandler != base.eventSystem.currentSelectedGameObject && eventHandler != null) - { - base.eventSystem.SetSelectedGameObject(null, pointerEvent); - } - } - else if (m_deselectBeforeSelecting && eventHandler != null && eventHandler != base.eventSystem.currentSelectedGameObject) - { - base.eventSystem.SetSelectedGameObject(null, pointerEvent); - } - } - - private void OnApplicationFocus(bool hasFocus) - { - m_HasFocus = hasFocus; - } - - private bool ShouldIgnoreEventsOnNoFocus() - { - if (!ReInput.isReady) - { - return true; - } - return ReInput.configuration.ignoreInputWhenAppNotInFocus; - } - - protected override void OnDestroy() - { - base.OnDestroy(); - ReInput.InitializedEvent -= OnRewiredInitialized; - ReInput.ShutDownEvent -= OnRewiredShutDown; - ReInput.EditorRecompileEvent -= OnEditorRecompile; - } - - protected override bool IsDefaultPlayer(int playerId) - { - if (playerIds == null) - { - return false; - } - if (!ReInput.isReady) - { - return false; - } - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < playerIds.Length; j++) - { - Player player = ReInput.players.GetPlayer(playerIds[j]); - if (player != null && (i >= 1 || !usePlayingPlayersOnly || player.isPlaying) && (i >= 2 || player.controllers.hasMouse)) - { - return playerIds[j] == playerId; - } - } - } - return false; - } - - private void InitializeRewired() - { - if (!ReInput.isReady) - { - Debug.LogError("Rewired is not initialized! Are you missing a Rewired Input Manager in your scene?"); - return; - } - ReInput.ShutDownEvent -= OnRewiredShutDown; - ReInput.ShutDownEvent += OnRewiredShutDown; - ReInput.EditorRecompileEvent -= OnEditorRecompile; - ReInput.EditorRecompileEvent += OnEditorRecompile; - SetupRewiredVars(); - } - - private void SetupRewiredVars() - { - if (!ReInput.isReady) - { - return; - } - SetUpRewiredActions(); - if (useAllRewiredGamePlayers) - { - IList<Player> list = (useRewiredSystemPlayer ? ReInput.players.AllPlayers : ReInput.players.Players); - playerIds = new int[list.Count]; - for (int i = 0; i < list.Count; i++) - { - playerIds[i] = list[i].id; - } - } - else - { - bool flag = false; - List<int> list2 = new List<int>(rewiredPlayerIds.Length + 1); - for (int j = 0; j < rewiredPlayerIds.Length; j++) - { - Player player = ReInput.players.GetPlayer(rewiredPlayerIds[j]); - if (player != null && !list2.Contains(player.id)) - { - list2.Add(player.id); - if (player.id == 9999999) - { - flag = true; - } - } - } - if (useRewiredSystemPlayer && !flag) - { - list2.Insert(0, ReInput.players.GetSystemPlayer().id); - } - playerIds = list2.ToArray(); - } - SetUpRewiredPlayerMice(); - } - - private void SetUpRewiredPlayerMice() - { - if (!ReInput.isReady) - { - return; - } - ClearMouseInputSources(); - for (int i = 0; i < playerMice.Count; i++) - { - Rewired.Components.PlayerMouse playerMouse = playerMice[i]; - if (!UnityTools.IsNullOrDestroyed(playerMouse)) - { - AddMouseInputSource(playerMouse); - } - } - } - - private void SetUpRewiredActions() - { - if (!ReInput.isReady) - { - return; - } - if (!setActionsById) - { - horizontalActionId = ReInput.mapping.GetActionId(m_HorizontalAxis); - verticalActionId = ReInput.mapping.GetActionId(m_VerticalAxis); - submitActionId = ReInput.mapping.GetActionId(m_SubmitButton); - cancelActionId = ReInput.mapping.GetActionId(m_CancelButton); - return; - } - InputAction action = ReInput.mapping.GetAction(horizontalActionId); - m_HorizontalAxis = ((action != null) ? action.name : string.Empty); - if (action == null) - { - horizontalActionId = -1; - } - action = ReInput.mapping.GetAction(verticalActionId); - m_VerticalAxis = ((action != null) ? action.name : string.Empty); - if (action == null) - { - verticalActionId = -1; - } - action = ReInput.mapping.GetAction(submitActionId); - m_SubmitButton = ((action != null) ? action.name : string.Empty); - if (action == null) - { - submitActionId = -1; - } - action = ReInput.mapping.GetAction(cancelActionId); - m_CancelButton = ((action != null) ? action.name : string.Empty); - if (action == null) - { - cancelActionId = -1; - } - } - - private bool GetButton(Player player, int actionId) - { - if (actionId < 0) - { - return false; - } - return player.GetButton(actionId); - } - - private bool GetButtonDown(Player player, int actionId) - { - if (actionId < 0) - { - return false; - } - return player.GetButtonDown(actionId); - } - - private bool GetNegativeButton(Player player, int actionId) - { - if (actionId < 0) - { - return false; - } - return player.GetNegativeButton(actionId); - } - - private bool GetNegativeButtonDown(Player player, int actionId) - { - if (actionId < 0) - { - return false; - } - return player.GetNegativeButtonDown(actionId); - } - - private float GetAxis(Player player, int actionId) - { - if (actionId < 0) - { - return 0f; - } - return player.GetAxis(actionId); - } - - private void CheckEditorRecompile() - { - if (recompiling && ReInput.isReady) - { - recompiling = false; - InitializeRewired(); - } - } - - private void OnEditorRecompile() - { - recompiling = true; - ClearRewiredVars(); - } - - private void ClearRewiredVars() - { - Array.Clear(playerIds, 0, playerIds.Length); - ClearMouseInputSources(); - } - - private bool DidAnyMouseMove() - { - for (int i = 0; i < playerIds.Length; i++) - { - int playerId = playerIds[i]; - Player player = ReInput.players.GetPlayer(playerId); - if (player == null || (usePlayingPlayersOnly && !player.isPlaying)) - { - continue; - } - int mouseInputSourceCount = GetMouseInputSourceCount(playerId); - for (int j = 0; j < mouseInputSourceCount; j++) - { - IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, j); - if (mouseInputSource != null && mouseInputSource.screenPositionDelta.sqrMagnitude > 0f) - { - return true; - } - } - } - return false; - } - - private bool GetMouseButtonDownOnAnyMouse(int buttonIndex) - { - for (int i = 0; i < playerIds.Length; i++) - { - int playerId = playerIds[i]; - Player player = ReInput.players.GetPlayer(playerId); - if (player == null || (usePlayingPlayersOnly && !player.isPlaying)) - { - continue; - } - int mouseInputSourceCount = GetMouseInputSourceCount(playerId); - for (int j = 0; j < mouseInputSourceCount; j++) - { - IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, j); - if (mouseInputSource != null && mouseInputSource.GetButtonDown(buttonIndex)) - { - return true; - } - } - } - return false; - } - - private void OnRewiredInitialized() - { - InitializeRewired(); - } - - private void OnRewiredShutDown() - { - ClearRewiredVars(); - } -} |
