Following reports that certain UI Extensions controls do not work with the new input system, working on a small refactor to manage and handle dependencies on the old input system.

pull/413/head
Simon (darkside) Jackson 2020-10-08 17:07:39 +01:00
parent 7342ed2e31
commit 0b0d03cdb7
15 changed files with 121 additions and 39 deletions

View File

@ -26,7 +26,7 @@ namespace UnityEngine.UI.Extensions
void Update()
{
// Check if the "Enter" key was just released with the chat input not focused
if (Input.GetKeyUp(KeyCode.Return) && !_inputField.isFocused)
if (UIExtensionsInputManager.GetKeyUp(KeyCode.Return) && !_inputField.isFocused)
{
// If we need to ignore the keypress, do nothing - otherwise activate the input field
if (_ignoreNextActivation)
@ -60,7 +60,7 @@ namespace UnityEngine.UI.Extensions
public void OnEndEdit(string textString)
{
// If the edit ended because we clicked away, don't do anything extra
if (!Input.GetKeyDown(KeyCode.Return))
if (!UIExtensionsInputManager.GetKeyDown(KeyCode.Return))
{
return;
}

View File

@ -147,14 +147,14 @@ namespace UnityEngine.UI.Extensions
void BeginSelection(){
// Click somewhere in the Game View.
if (!Input.GetMouseButtonDown(0))
if (!UIExtensionsInputManager.GetMouseButtonDown(0))
return;
//The boxRect will be inactive up until the point we start selecting
boxRect.gameObject.SetActive(true);
// Get the initial click position of the mouse.
origin = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
origin = new Vector2(UIExtensionsInputManager.MousePosition.x, UIExtensionsInputManager.MousePosition.y);
//If the initial click point is not inside the selection mask, we abort the selection
if (!PointIsValidAgainstSelectionMask(origin)) {
@ -185,7 +185,7 @@ namespace UnityEngine.UI.Extensions
selectableList.Add (selectable);
//We're using left shift to act as the "Add To Selection" command. So if left shift isn't pressed, we want everything to begin deselected
if (!Input.GetKey (KeyCode.LeftShift)) {
if (!UIExtensionsInputManager.GetKey (KeyCode.LeftShift)) {
selectable.selected = false;
}
}
@ -211,7 +211,7 @@ namespace UnityEngine.UI.Extensions
IBoxSelectable GetSelectableAtMousePosition() {
//Firstly, we cannot click on something that is not inside the selection mask (if we have one)
if (!PointIsValidAgainstSelectionMask(Input.mousePosition)) {
if (!PointIsValidAgainstSelectionMask(UIExtensionsInputManager.MousePosition)) {
return null;
}
@ -227,7 +227,7 @@ namespace UnityEngine.UI.Extensions
//Once we've found the rendering camera, we check if the selectables rectTransform contains the click. That way we
//Can click anywhere on a rectTransform to select it.
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, screenCamera)) {
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, UIExtensionsInputManager.MousePosition, screenCamera)) {
//And if it does, we select it and send it back
return selectable;
@ -240,7 +240,7 @@ namespace UnityEngine.UI.Extensions
var selectableScreenPoint = GetScreenPointOfSelectable(selectable);
//Check that the click fits within the screen-radius of the selectable
if (Vector2.Distance(selectableScreenPoint, Input.mousePosition) <= radius) {
if (Vector2.Distance(selectableScreenPoint, UIExtensionsInputManager.MousePosition) <= radius) {
//And if it does, we select it and send it back
return selectable;
@ -255,11 +255,11 @@ namespace UnityEngine.UI.Extensions
void DragSelection(){
//Return if we're not dragging or if the selection has been aborted (BoxRect disabled)
if (!Input.GetMouseButton(0) || !boxRect.gameObject.activeSelf)
if (!UIExtensionsInputManager.GetMouseButton(0) || !boxRect.gameObject.activeSelf)
return;
// Store the current mouse position in screen space.
Vector2 currentMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 currentMousePosition = new Vector2(UIExtensionsInputManager.MousePosition.x, UIExtensionsInputManager.MousePosition.y);
// How far have we moved the mouse?
Vector2 difference = currentMousePosition - origin;
@ -414,7 +414,7 @@ namespace UnityEngine.UI.Extensions
void EndSelection(){
//Get out if we haven't finished selecting, or if the selection has been aborted (boxRect disabled)
if (!Input.GetMouseButtonUp(0) || !boxRect.gameObject.activeSelf)
if (!UIExtensionsInputManager.GetMouseButtonUp(0) || !boxRect.gameObject.activeSelf)
return;
clickedAfterDrag = GetSelectableAtMousePosition();

View File

@ -1,6 +1,8 @@
/// Credit Chris Trueman
/// Sourced from - http://forum.unity3d.com/threads/use-reticle-like-mouse-for-worldspace-uis.295271/
using UnityEngine.UI.Extensions;
namespace UnityEngine.EventSystems.Extensions
{
[RequireComponent(typeof(EventSystem))]
@ -38,8 +40,8 @@ namespace UnityEngine.EventSystems.Extensions
public override void Process()
{
bool pressed = Input.GetButtonDown(activateAxis);
bool released = Input.GetButtonUp(activateAxis);
bool pressed = UIExtensionsInputManager.GetButtonDown(activateAxis);
bool released = UIExtensionsInputManager.GetButtonUp(activateAxis);
PointerEventData pointer = GetAimerPointerEventData();

View File

@ -1,6 +1,8 @@
/// Credit Simon (simonDarksideJ) Jackson
/// Sourced from - UI SIM source and My Brain
using UnityEngine.UI.Extensions;
namespace UnityEngine.EventSystems
{
[AddComponentMenu("Event/Extensions/GamePad Input Module")]
@ -88,10 +90,10 @@ namespace UnityEngine.EventSystems
return false;
var shouldActivate = true;
shouldActivate |= Input.GetButtonDown(m_SubmitButton);
shouldActivate |= Input.GetButtonDown(m_CancelButton);
shouldActivate |= !Mathf.Approximately(Input.GetAxisRaw(m_HorizontalAxis), 0.0f);
shouldActivate |= !Mathf.Approximately(Input.GetAxisRaw(m_VerticalAxis), 0.0f);
shouldActivate |= UIExtensionsInputManager.GetButtonDown(m_SubmitButton);
shouldActivate |= UIExtensionsInputManager.GetButtonDown(m_CancelButton);
shouldActivate |= !Mathf.Approximately(UIExtensionsInputManager.GetAxisRaw(m_HorizontalAxis), 0.0f);
shouldActivate |= !Mathf.Approximately(UIExtensionsInputManager.GetAxisRaw(m_VerticalAxis), 0.0f);
return shouldActivate;
}
@ -142,10 +144,10 @@ namespace UnityEngine.EventSystems
return false;
var data = GetBaseEventData();
if (Input.GetButtonDown(m_SubmitButton))
if (UIExtensionsInputManager.GetButtonDown(m_SubmitButton))
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
if (Input.GetButtonDown(m_CancelButton))
if (UIExtensionsInputManager.GetButtonDown(m_CancelButton))
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
return data.used;
}
@ -153,17 +155,17 @@ namespace UnityEngine.EventSystems
private Vector2 GetRawMoveVector()
{
Vector2 move = Vector2.zero;
move.x = Input.GetAxisRaw(m_HorizontalAxis);
move.y = Input.GetAxisRaw(m_VerticalAxis);
move.x = UIExtensionsInputManager.GetAxisRaw(m_HorizontalAxis);
move.y = UIExtensionsInputManager.GetAxisRaw(m_VerticalAxis);
if (Input.GetButtonDown(m_HorizontalAxis))
if (UIExtensionsInputManager.GetButtonDown(m_HorizontalAxis))
{
if (move.x < 0)
move.x = -1f;
if (move.x > 0)
move.x = 1f;
}
if (Input.GetButtonDown(m_VerticalAxis))
if (UIExtensionsInputManager.GetButtonDown(m_VerticalAxis))
{
if (move.y < 0)
move.y = -1f;
@ -188,7 +190,7 @@ namespace UnityEngine.EventSystems
}
// If user pressed key again, always allow event
bool allow = Input.GetButtonDown(m_HorizontalAxis) || Input.GetButtonDown(m_VerticalAxis);
bool allow = UIExtensionsInputManager.GetButtonDown(m_HorizontalAxis) || UIExtensionsInputManager.GetButtonDown(m_VerticalAxis);
bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
if (!allow)
{

View File

@ -76,12 +76,12 @@ public class CardStack2D : MonoBehaviour
if (canUseHorizontalAxis)
{
///Controls for the cards.
if (Input.GetAxisRaw("Horizontal") < 0 && cardArrayOffset > 0)
if (UIExtensionsInputManager.GetAxisRaw("Horizontal") < 0 && cardArrayOffset > 0)
{
cardArrayOffset--;
StartCoroutine(ButtonCooldown());
}
else if (Input.GetAxisRaw("Horizontal") > 0 && cardArrayOffset < cards.Length - 1)
else if (UIExtensionsInputManager.GetAxisRaw("Horizontal") > 0 && cardArrayOffset < cards.Length - 1)
{
cardArrayOffset++;
StartCoroutine(ButtonCooldown());

View File

@ -200,7 +200,7 @@ namespace UnityEngine.UI.Extensions
}
if (!Input.GetMouseButton(0))
if (!UIExtensionsInputManager.GetMouseButton(0))
{
// scroll slowly to nearest element when not dragged
ScrollingElements();

View File

@ -143,7 +143,7 @@ namespace UnityEngine.UI.Extensions
private void Update()
{
// On Android the back button is sent as Esc
if (Input.GetKeyDown(KeyCode.Escape) && menuStack.Count > 0)
if (UIExtensionsInputManager.GetKeyDown(KeyCode.Escape) && menuStack.Count > 0)
{
menuStack.Peek().OnBackPressed();
}

View File

@ -56,7 +56,7 @@ namespace UnityEngine.UI.Extensions
}
}
if (Input.GetKeyDown(KeyCode.Tab) && Input.GetKey(KeyCode.LeftShift))
if (UIExtensionsInputManager.GetKeyDown(KeyCode.Tab) && UIExtensionsInputManager.GetKey(KeyCode.LeftShift))
{
if (NavigationMode == NavigationMode.Manual && NavigationPath.Length > 0)
{
@ -85,7 +85,7 @@ namespace UnityEngine.UI.Extensions
}
}
}
else if (Input.GetKeyDown(KeyCode.Tab))
else if (UIExtensionsInputManager.GetKeyDown(KeyCode.Tab))
{
if (NavigationMode == NavigationMode.Manual && NavigationPath.Length > 0)
{

View File

@ -135,7 +135,7 @@ namespace UnityEngine.UI.Extensions
public void OnScreenSpaceCamera()
{
//get the dynamic position of the pos in viewport coordinates
Vector3 newPos = GUICamera.ScreenToViewportPoint(Input.mousePosition);
Vector3 newPos = GUICamera.ScreenToViewportPoint(UIExtensionsInputManager.MousePosition);
// store in val the updated position (x or y) of the tooltip edge of interest
float val;

View File

@ -55,10 +55,10 @@ namespace UnityEngine.UI.Extensions
{
switch (tooltipPositioningType) {
case TooltipPositioningType.mousePosition:
StartHover(Input.mousePosition + offset, true);
StartHover(UIExtensionsInputManager.MousePosition + offset, true);
break;
case TooltipPositioningType.mousePositionAndFollow:
StartHover(Input.mousePosition + offset, true);
StartHover(UIExtensionsInputManager.MousePosition + offset, true);
hovered = true;
StartCoroutine(HoveredMouseFollowingLoop());
break;
@ -72,7 +72,7 @@ namespace UnityEngine.UI.Extensions
IEnumerator HoveredMouseFollowingLoop() {
while (hovered) {
StartHover(Input.mousePosition + offset);
StartHover(UIExtensionsInputManager.MousePosition + offset);
yield return null;
}
}

View File

@ -30,7 +30,7 @@ namespace UnityEngine.UI.Extensions
public void OnEndEdit(string txt)
{
if (!Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter))
if (!UIExtensionsInputManager.GetKeyDown(KeyCode.Return) && !UIExtensionsInputManager.GetKeyDown(KeyCode.KeypadEnter))
return;
EnterSubmit.Invoke(txt);
if (defocusInput)

View File

@ -0,0 +1,67 @@
/// Credit SimonDarksideJ
/// Sourced from: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/348/menu-manager-does-not-work-with-the-new
namespace UnityEngine.UI.Extensions
{
public static class UIExtensionsInputManager
{
public static bool GetMouseButton(int button)
{
return Input.GetMouseButton(button);
}
public static bool GetMouseButtonDown(int button)
{
return Input.GetMouseButtonDown(button);
}
public static bool GetMouseButtonUp(int button)
{
return Input.GetMouseButtonUp(button);
}
public static bool GetButton(string input)
{
return Input.GetButton(input);
}
public static bool GetButtonDown(string input)
{
return Input.GetButtonDown(input);
}
public static bool GetButtonUp(string input)
{
return Input.GetButtonUp(input);
}
public static bool GetKey(KeyCode key)
{
return Input.GetKey(key);
}
public static bool GetKeyDown(KeyCode key)
{
return Input.GetKeyDown(key);
}
public static bool GetKeyUp(KeyCode key)
{
return Input.GetKeyUp(key);
}
public static float GetAxisRaw(string axis)
{
return Input.GetAxisRaw(axis);
}
public static Vector3 MousePosition
{
get
{
return Input.mousePosition;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: de7e73fc10fb95143a19dbc76c2595a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -124,7 +124,7 @@ namespace UnityEngine.UI.Extensions
for (int i = 0; i < CancelScrollKeycodes.Count; i++)
{
if (Input.GetKeyDown(CancelScrollKeycodes[i]) == true)
if (UIExtensionsInputManager.GetKeyDown(CancelScrollKeycodes[i]) == true)
{
IsManualScrollingAvailable = true;

View File

@ -16,15 +16,15 @@ namespace UnityEngine.UI.Extensions
{
Vector3 thisPosition;
thisPosition.x = Input.mousePosition.x * xSens;
thisPosition.y = Input.mousePosition.y * ySens - 1;
thisPosition.x = UIExtensionsInputManager.MousePosition.x * xSens;
thisPosition.y = UIExtensionsInputManager.MousePosition.y * ySens - 1;
thisPosition.z = transform.position.z;
transform.position = thisPosition;
VRInputModule.cursorPosition = transform.position;
if (Input.GetMouseButtonDown(0) && currentCollider)
if (UIExtensionsInputManager.GetMouseButtonDown(0) && currentCollider)
{
VRInputModule.PointerSubmit(currentCollider.gameObject);
}