diff --git a/Runtime/Scripts/Controls/InputFocus.cs b/Runtime/Scripts/Controls/InputFocus.cs
index e900806..9802314 100644
--- a/Runtime/Scripts/Controls/InputFocus.cs
+++ b/Runtime/Scripts/Controls/InputFocus.cs
@@ -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;
}
diff --git a/Runtime/Scripts/Controls/SelectionBox/SelectionBox.cs b/Runtime/Scripts/Controls/SelectionBox/SelectionBox.cs
index ca99161..cb8a632 100644
--- a/Runtime/Scripts/Controls/SelectionBox/SelectionBox.cs
+++ b/Runtime/Scripts/Controls/SelectionBox/SelectionBox.cs
@@ -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();
diff --git a/Runtime/Scripts/InputModules.meta b/Runtime/Scripts/InputModules.meta
deleted file mode 100644
index 2969fc2..0000000
--- a/Runtime/Scripts/InputModules.meta
+++ /dev/null
@@ -1,5 +0,0 @@
-fileFormatVersion: 2
-guid: a0789c2f62bad6b4c800a3dc502fa18e
-folderAsset: yes
-DefaultImporter:
- userData:
diff --git a/Runtime/Scripts/InputModules/AimerInputModule.cs b/Runtime/Scripts/InputModules/AimerInputModule.cs
deleted file mode 100644
index d4ce670..0000000
--- a/Runtime/Scripts/InputModules/AimerInputModule.cs
+++ /dev/null
@@ -1,163 +0,0 @@
-/// Credit Chris Trueman
-/// Sourced from - http://forum.unity3d.com/threads/use-reticle-like-mouse-for-worldspace-uis.295271/
-
-namespace UnityEngine.EventSystems.Extensions
-{
- [RequireComponent(typeof(EventSystem))]
- [AddComponentMenu("Event/Extensions/Aimer Input Module")]
- public class AimerInputModule : PointerInputModule
- {
- ///
- /// The Input axis name used to activate the object under the reticle.
- ///
- public string activateAxis = "Submit";
-
- ///
- /// The aimer offset position. Aimer is center screen use this offset to change that.
- ///
- public Vector2 aimerOffset = new Vector2(0, 0);
-
- ///
- /// The object under aimer. A static access field that lets you know what is under the aimer.
- /// This field can return null.
- ///
- public static GameObject objectUnderAimer;
-
- protected AimerInputModule() { }
-
- public override void ActivateModule()
- {
- StandaloneInputModule StandAloneSystem = GetComponent();
-
- if (StandAloneSystem != null && StandAloneSystem.enabled)
- {
- Debug.LogError("Aimer Input Module is incompatible with the StandAloneInputSystem, " +
- "please remove it from the Event System in this scene or disable it when this module is in use");
- }
- }
-
- public override void Process()
- {
- bool pressed = Input.GetButtonDown(activateAxis);
- bool released = Input.GetButtonUp(activateAxis);
-
- PointerEventData pointer = GetAimerPointerEventData();
-
- ProcessInteraction(pointer, pressed, released);
-
- if (!released)
- ProcessMove(pointer);
- else
- RemovePointerData(pointer);
- }
-
- protected virtual PointerEventData GetAimerPointerEventData()
- {
- PointerEventData pointerData;
-
- //Not certain on the use of this.
- //I know that -1 is the mouse and anything positive would be a finger/touch, 0 being the first finger, 1 being the second and so one till the system limit is reached.
- //So that is the reason I choose -2.
- GetPointerData(-2, out pointerData, true);
-
- pointerData.Reset();
-
- pointerData.position = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f) + aimerOffset;
-
- eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
- var raycast = FindFirstRaycast(m_RaycastResultCache);
- pointerData.pointerCurrentRaycast = raycast;
- m_RaycastResultCache.Clear();
- return pointerData;
- }
-
- private void ProcessInteraction(PointerEventData pointer, bool pressed, bool released)
- {
- var currentOverGo = pointer.pointerCurrentRaycast.gameObject;
-
- objectUnderAimer = ExecuteEvents.GetEventHandler(currentOverGo);//we only want objects that we can submit on.
-
- if (pressed)
- {
- pointer.eligibleForClick = true;
- pointer.delta = Vector2.zero;
- pointer.pressPosition = pointer.position;
- pointer.pointerPressRaycast = pointer.pointerCurrentRaycast;
-
- // search for the control that will receive the press
- // if we can't find a press handler set the press
- // handler to be what would receive a click.
- var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.submitHandler);
-
- // didn't find a press handler... search for a click handler
- if (newPressed == null)
- {
- newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.pointerDownHandler);
- if (newPressed == null)
- newPressed = ExecuteEvents.GetEventHandler(currentOverGo);
- }
- else
- {
- pointer.eligibleForClick = false;
- }
-
- if (newPressed != pointer.pointerPress)
- {
- pointer.pointerPress = newPressed;
- pointer.rawPointerPress = currentOverGo;
- pointer.clickCount = 0;
- }
-
- // Save the drag handler as well
- pointer.pointerDrag = ExecuteEvents.GetEventHandler(currentOverGo);
-
- if (pointer.pointerDrag != null)
- ExecuteEvents.Execute(pointer.pointerDrag, pointer, ExecuteEvents.beginDragHandler);
- }
-
- if (released)
- {
- //Debug.Log("Executing pressup on: " + pointer.pointerPress);
- ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerUpHandler);
-
- //Debug.Log("KeyCode: " + pointer.eventData.keyCode);
-
- // see if we mouse up on the same element that we clicked on...
- var pointerUpHandler = ExecuteEvents.GetEventHandler(currentOverGo);
-
- // PointerClick
- if (pointer.pointerPress == pointerUpHandler && pointer.eligibleForClick)
- {
- float time = Time.unscaledTime;
-
- if (time - pointer.clickTime < 0.3f)
- ++pointer.clickCount;
- else
- pointer.clickCount = 1;
- pointer.clickTime = time;
-
- ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerClickHandler);
- }
- else if (pointer.pointerDrag != null)
- {
- ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.dropHandler);
- }
-
- pointer.eligibleForClick = false;
- pointer.pointerPress = null;
- pointer.rawPointerPress = null;
-
- if (pointer.pointerDrag != null)
- ExecuteEvents.Execute(pointer.pointerDrag, pointer, ExecuteEvents.endDragHandler);
-
- pointer.pointerDrag = null;
- }
- }
-
- public override void DeactivateModule()
- {
- base.DeactivateModule();
- ClearSelection();
- }
- }
-}
\ No newline at end of file
diff --git a/Runtime/Scripts/InputModules/AimerInputModule.cs.meta b/Runtime/Scripts/InputModules/AimerInputModule.cs.meta
deleted file mode 100644
index ee7993f..0000000
--- a/Runtime/Scripts/InputModules/AimerInputModule.cs.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 08b9f423b73fdfb47b59e7de89863600
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
diff --git a/Runtime/Scripts/InputModules/GamePadInputModule.cs b/Runtime/Scripts/InputModules/GamePadInputModule.cs
deleted file mode 100644
index d1d0d9b..0000000
--- a/Runtime/Scripts/InputModules/GamePadInputModule.cs
+++ /dev/null
@@ -1,226 +0,0 @@
-/// Credit Simon (simonDarksideJ) Jackson
-/// Sourced from - UI SIM source and My Brain
-
-namespace UnityEngine.EventSystems
-{
- [AddComponentMenu("Event/Extensions/GamePad Input Module")]
- public class GamePadInputModule : BaseInputModule
- {
- private float m_PrevActionTime;
- Vector2 m_LastMoveVector;
- int m_ConsecutiveMoveCount = 0;
-
- protected GamePadInputModule()
- {}
-
- [SerializeField]
- private string m_HorizontalAxis = "Horizontal";
-
- ///
- /// Name of the vertical axis for movement (if axis events are used).
- ///
- [SerializeField]
- private string m_VerticalAxis = "Vertical";
-
- ///
- /// Name of the submit button.
- ///
- [SerializeField]
- private string m_SubmitButton = "Submit";
-
- ///
- /// Name of the submit button.
- ///
- [SerializeField]
- private string m_CancelButton = "Cancel";
-
- [SerializeField]
- private float m_InputActionsPerSecond = 10;
-
- [SerializeField]
- private float m_RepeatDelay = 0.1f;
-
- public float inputActionsPerSecond
- {
- get { return m_InputActionsPerSecond; }
- set { m_InputActionsPerSecond = value; }
- }
-
- public float repeatDelay
- {
- get { return m_RepeatDelay; }
- set { m_RepeatDelay = value; }
- }
-
- ///
- /// Name of the horizontal axis for movement (if axis events are used).
- ///
- public string horizontalAxis
- {
- get { return m_HorizontalAxis; }
- set { m_HorizontalAxis = value; }
- }
-
- ///
- /// Name of the vertical axis for movement (if axis events are used).
- ///
- public string verticalAxis
- {
- get { return m_VerticalAxis; }
- set { m_VerticalAxis = value; }
- }
-
- public string submitButton
- {
- get { return m_SubmitButton; }
- set { m_SubmitButton = value; }
- }
-
- public string cancelButton
- {
- get { return m_CancelButton; }
- set { m_CancelButton = value; }
- }
-
- public override bool ShouldActivateModule()
- {
- if (!base.ShouldActivateModule())
- 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);
- return shouldActivate;
- }
-
- public override void ActivateModule()
- {
- StandaloneInputModule StandAloneSystem = GetComponent();
-
- if (StandAloneSystem && StandAloneSystem.enabled)
- {
- Debug.LogError("StandAloneInputSystem should not be used with the GamePadInputModule, " +
- "please remove it from the Event System in this scene or disable it when this module is in use");
- }
-
- base.ActivateModule();
-
- var toSelect = eventSystem.currentSelectedGameObject;
- if (toSelect == null)
- toSelect = eventSystem.firstSelectedGameObject;
-
- eventSystem.SetSelectedGameObject(toSelect, GetBaseEventData());
- }
-
- public override void DeactivateModule()
- {
- base.DeactivateModule();
- }
-
- public override void Process()
- {
- bool usedEvent = SendUpdateEventToSelectedObject();
-
- if (eventSystem.sendNavigationEvents)
- {
- if (!usedEvent)
- usedEvent |= SendMoveEventToSelectedObject();
-
- if (!usedEvent)
- SendSubmitEventToSelectedObject();
- }
- }
-
- ///
- /// Process submit keys.
- ///
- protected bool SendSubmitEventToSelectedObject()
- {
- if (eventSystem.currentSelectedGameObject == null)
- return false;
-
- var data = GetBaseEventData();
- if (Input.GetButtonDown(m_SubmitButton))
- ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
-
- if (Input.GetButtonDown(m_CancelButton))
- ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
- return data.used;
- }
-
- private Vector2 GetRawMoveVector()
- {
- Vector2 move = Vector2.zero;
- move.x = Input.GetAxisRaw(m_HorizontalAxis);
- move.y = Input.GetAxisRaw(m_VerticalAxis);
-
- if (Input.GetButtonDown(m_HorizontalAxis))
- {
- if (move.x < 0)
- move.x = -1f;
- if (move.x > 0)
- move.x = 1f;
- }
- if (Input.GetButtonDown(m_VerticalAxis))
- {
- if (move.y < 0)
- move.y = -1f;
- if (move.y > 0)
- move.y = 1f;
- }
- return move;
- }
-
- ///
- /// Process events.
- ///
- protected bool SendMoveEventToSelectedObject()
- {
- float time = Time.unscaledTime;
-
- Vector2 movement = GetRawMoveVector();
- if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
- {
- m_ConsecutiveMoveCount = 0;
- return false;
- }
-
- // If user pressed key again, always allow event
- bool allow = Input.GetButtonDown(m_HorizontalAxis) || Input.GetButtonDown(m_VerticalAxis);
- bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
- if (!allow)
- {
- // Otherwise, user held down key or axis.
- // If direction didn't change at least 90 degrees, wait for delay before allowing consecutive event.
- if (similarDir && m_ConsecutiveMoveCount == 1)
- allow = (time > m_PrevActionTime + m_RepeatDelay);
- // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
- else
- allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
- }
- if (!allow)
- return false;
-
- var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
- ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
- if (!similarDir)
- m_ConsecutiveMoveCount = 0;
- m_ConsecutiveMoveCount++;
- m_PrevActionTime = time;
- m_LastMoveVector = movement;
- return axisEventData.used;
- }
-
- protected bool SendUpdateEventToSelectedObject()
- {
- if (eventSystem.currentSelectedGameObject == null)
- return false;
-
- var data = GetBaseEventData();
- ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler);
- return data.used;
- }
- }
-}
diff --git a/Runtime/Scripts/Layout/CardUI/2D Cards/CardStack2D.cs b/Runtime/Scripts/Layout/CardUI/2D Cards/CardStack2D.cs
index d099b6b..61487c1 100644
--- a/Runtime/Scripts/Layout/CardUI/2D Cards/CardStack2D.cs
+++ b/Runtime/Scripts/Layout/CardUI/2D Cards/CardStack2D.cs
@@ -3,118 +3,121 @@
/// Sourced from - https://github.com/ryanslikesocool/Unity-Card-UI
///
- using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEngine.UI;
+using System.Collections;
namespace UnityEngine.UI.Extensions
{
-public class CardStack2D : MonoBehaviour
-{
-
- [SerializeField]
- private float cardMoveSpeed = 8f;
- [SerializeField]
- private float buttonCooldownTime = 0.125f;
- [SerializeField]
- private int cardZMultiplier = 32;
- [SerializeField]
- private bool useDefaultUsedXPos = true;
- [SerializeField]
- private int usedCardXPos = 1280;
- [SerializeField]
- private Transform[] cards = null;
-
- private int cardArrayOffset;
- private Vector3[] cardPositions;
- private int xPowerDifference;
-
- ///Static variables can be used across the scene if this script is in it.
- ///Thankfully it doesn't matter if another script attempts to use the variable and this script isn't in the scene.
- public static bool canUseHorizontalAxis = true;
-
- void Start()
+ public class CardStack2D : MonoBehaviour
{
- ///I've found that 9 is a good number for this.
- ///I wouldn't really recommend changing it, but go ahead if you want to.
- xPowerDifference = 9 - cards.Length;
- ///This is optional, but makes it super easy to figure out the off screen position for cards.
- ///Unfortunately, it's only really useful if the cards are the same width.
- if (useDefaultUsedXPos)
+ [SerializeField]
+ private float cardMoveSpeed = 8f;
+ [SerializeField]
+ private float buttonCooldownTime = 0.125f;
+ [SerializeField]
+ private int cardZMultiplier = 32;
+ [SerializeField]
+ private bool useDefaultUsedXPos = true;
+ [SerializeField]
+ private int usedCardXPos = 1280;
+ [SerializeField]
+ private KeyCode leftButton = KeyCode.LeftArrow;
+ [SerializeField]
+ private KeyCode rightButton = KeyCode.RightArrow;
+ [SerializeField]
+ private Transform[] cards = null;
+
+
+
+ private int cardArrayOffset;
+ private Vector3[] cardPositions;
+ private int xPowerDifference;
+
+ ///Static variables can be used across the scene if this script is in it.
+ ///Thankfully it doesn't matter if another script attempts to use the variable and this script isn't in the scene.
+ public static bool canUseHorizontalAxis = true;
+
+ void Start()
{
- int cardWidth = (int)(cards[0].GetComponent().rect.width);
- usedCardXPos = (int)(Screen.width * 0.5f + cardWidth);
- }
+ ///I've found that 9 is a good number for this.
+ ///I wouldn't really recommend changing it, but go ahead if you want to.
+ xPowerDifference = 9 - cards.Length;
- cardPositions = new Vector3[cards.Length * 2 - 1];
-
- ///This loop is for cards still in the stack.
- for (int i = cards.Length; i > -1; i--)
- {
- if (i < cards.Length - 1)
+ ///This is optional, but makes it super easy to figure out the off screen position for cards.
+ ///Unfortunately, it's only really useful if the cards are the same width.
+ if (useDefaultUsedXPos)
{
- cardPositions[i] = new Vector3(-Mathf.Pow(2, i + xPowerDifference) + cardPositions[i + 1].x, 0, cardZMultiplier * Mathf.Abs(i + 1 - cards.Length));
+ int cardWidth = (int)(cards[0].GetComponent().rect.width);
+ usedCardXPos = (int)(Screen.width * 0.5f + cardWidth);
}
- else
- {
- cardPositions[i] = Vector3.zero;
- }
- }
- ///This loop is for cards outside of the stack.
- for (int i = cards.Length; i < cardPositions.Length; i++)
- {
- cardPositions[i] = new Vector3(usedCardXPos + 4 * (i - cards.Length), 0, -2 + -2 * (i - cards.Length));
- }
- }
+ cardPositions = new Vector3[cards.Length * 2 - 1];
- void Update()
- {
- if (canUseHorizontalAxis)
- {
- ///Controls for the cards.
- if (Input.GetAxisRaw("Horizontal") < 0 && cardArrayOffset > 0)
+ ///This loop is for cards still in the stack.
+ for (int i = cards.Length; i > -1; i--)
{
- cardArrayOffset--;
- StartCoroutine(ButtonCooldown());
- }
- else if (Input.GetAxisRaw("Horizontal") > 0 && cardArrayOffset < cards.Length - 1)
- {
- cardArrayOffset++;
- StartCoroutine(ButtonCooldown());
- }
- }
-
- ///This loop moves the cards. I know that none of my lerps are the "right way," but it looks much nicer.
- for (int i = 0; i < cards.Length; i++)
- {
- cards[i].localPosition = Vector3.Lerp(cards[i].localPosition, cardPositions[i + cardArrayOffset], Time.deltaTime * cardMoveSpeed);
- if (Mathf.Abs(cards[i].localPosition.x - cardPositions[i + cardArrayOffset].x) < 0.01f)
- {
- cards[i].localPosition = cardPositions[i + cardArrayOffset];
-
- ///This disables interaction with cards that are not on top of the stack.
- if (cards[i].localPosition.x == 0)
+ if (i < cards.Length - 1)
{
- cards[i].gameObject.GetComponent().interactable = true;
+ cardPositions[i] = new Vector3(-Mathf.Pow(2, i + xPowerDifference) + cardPositions[i + 1].x, 0, cardZMultiplier * Mathf.Abs(i + 1 - cards.Length));
}
else
{
- cards[i].gameObject.GetComponent().interactable = false;
+ cardPositions[i] = Vector3.zero;
+ }
+ }
+
+ ///This loop is for cards outside of the stack.
+ for (int i = cards.Length; i < cardPositions.Length; i++)
+ {
+ cardPositions[i] = new Vector3(usedCardXPos + 4 * (i - cards.Length), 0, -2 + -2 * (i - cards.Length));
+ }
+ }
+
+ void Update()
+ {
+ if (canUseHorizontalAxis)
+ {
+ ///Controls for the cards.
+ if ((UIExtensionsInputManager.GetAxisRaw("Horizontal") < 0 || UIExtensionsInputManager.GetKey(leftButton)) && cardArrayOffset > 0)
+ {
+ cardArrayOffset--;
+ StartCoroutine(ButtonCooldown());
+ }
+ else if ((UIExtensionsInputManager.GetAxisRaw("Horizontal") > 0 || UIExtensionsInputManager.GetKey(rightButton)) && cardArrayOffset < cards.Length - 1)
+ {
+ cardArrayOffset++;
+ StartCoroutine(ButtonCooldown());
+ }
+ }
+
+ ///This loop moves the cards. I know that none of my lerps are the "right way," but it looks much nicer.
+ for (int i = 0; i < cards.Length; i++)
+ {
+ cards[i].localPosition = Vector3.Lerp(cards[i].localPosition, cardPositions[i + cardArrayOffset], Time.deltaTime * cardMoveSpeed);
+ if (Mathf.Abs(cards[i].localPosition.x - cardPositions[i + cardArrayOffset].x) < 0.01f)
+ {
+ cards[i].localPosition = cardPositions[i + cardArrayOffset];
+
+ ///This disables interaction with cards that are not on top of the stack.
+ if (cards[i].localPosition.x == 0)
+ {
+ cards[i].gameObject.GetComponent().interactable = true;
+ }
+ else
+ {
+ cards[i].gameObject.GetComponent().interactable = false;
+ }
}
}
}
- }
- ///Stops the cards from scrolling super quickly if a button on the horizontal axis is held down.
- IEnumerator ButtonCooldown()
- {
- canUseHorizontalAxis = false;
- yield return new WaitForSeconds(buttonCooldownTime);
- canUseHorizontalAxis = true;
+ ///Stops the cards from scrolling super quickly if a button on the horizontal axis is held down.
+ IEnumerator ButtonCooldown()
+ {
+ canUseHorizontalAxis = false;
+ yield return new WaitForSeconds(buttonCooldownTime);
+ canUseHorizontalAxis = true;
+ }
}
-}
}
\ No newline at end of file
diff --git a/Runtime/Scripts/Layout/UIVerticalScroller.cs b/Runtime/Scripts/Layout/UIVerticalScroller.cs
index 5d65dd5..cad0e86 100644
--- a/Runtime/Scripts/Layout/UIVerticalScroller.cs
+++ b/Runtime/Scripts/Layout/UIVerticalScroller.cs
@@ -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();
diff --git a/Runtime/Scripts/MenuSystem/MenuManager.cs b/Runtime/Scripts/MenuSystem/MenuManager.cs
index fd63df1..2024b60 100644
--- a/Runtime/Scripts/MenuSystem/MenuManager.cs
+++ b/Runtime/Scripts/MenuSystem/MenuManager.cs
@@ -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();
}
diff --git a/Runtime/Scripts/TabNavigationHelper.cs b/Runtime/Scripts/TabNavigationHelper.cs
index 12a287e..d1dcd3d 100644
--- a/Runtime/Scripts/TabNavigationHelper.cs
+++ b/Runtime/Scripts/TabNavigationHelper.cs
@@ -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)
{
diff --git a/Runtime/Scripts/ToolTips/HoverTooltip.cs b/Runtime/Scripts/ToolTips/HoverTooltip.cs
index 1eb29bf..74ef3e7 100644
--- a/Runtime/Scripts/ToolTips/HoverTooltip.cs
+++ b/Runtime/Scripts/ToolTips/HoverTooltip.cs
@@ -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;
diff --git a/Runtime/Scripts/ToolTips/TooltipTrigger.cs b/Runtime/Scripts/ToolTips/TooltipTrigger.cs
index b199c03..0efa6c7 100644
--- a/Runtime/Scripts/ToolTips/TooltipTrigger.cs
+++ b/Runtime/Scripts/ToolTips/TooltipTrigger.cs
@@ -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;
}
}
diff --git a/Runtime/Scripts/Utilities/InputFieldEnterSubmit.cs b/Runtime/Scripts/Utilities/InputFieldEnterSubmit.cs
index 55d9bea..72192b2 100644
--- a/Runtime/Scripts/Utilities/InputFieldEnterSubmit.cs
+++ b/Runtime/Scripts/Utilities/InputFieldEnterSubmit.cs
@@ -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)
diff --git a/Runtime/Scripts/Utilities/UIExtensionsInputManager.cs b/Runtime/Scripts/Utilities/UIExtensionsInputManager.cs
new file mode 100644
index 0000000..85453f4
--- /dev/null
+++ b/Runtime/Scripts/Utilities/UIExtensionsInputManager.cs
@@ -0,0 +1,273 @@
+/// Credit SimonDarksideJ
+/// Sourced from: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/348/menu-manager-does-not-work-with-the-new
+
+using System;
+using System.Collections.Generic;
+using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.Controls;
+
+namespace UnityEngine.UI.Extensions
+{
+ public static class UIExtensionsInputManager
+ {
+#if !ENABLE_LEGACY_INPUT_MANAGER
+ private static bool[] mouseButtons = new bool[3] { false, false, false };
+ private static Dictionary keys = new Dictionary();
+ private static Dictionary buttons = new Dictionary();
+#endif
+
+ public static bool GetMouseButton(int button)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetMouseButton(button);
+#else
+ if (Mouse.current == null)
+ {
+ return false;
+ }
+
+ return Mouse.current.leftButton.isPressed;
+#endif
+ }
+
+ public static bool GetMouseButtonDown(int button)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetMouseButtonDown(button);
+#else
+ if (Mouse.current == null)
+ {
+ return false;
+ }
+
+ if (Mouse.current.leftButton.isPressed)
+ {
+ if (!mouseButtons[button])
+ {
+ mouseButtons[button] = true;
+ return true;
+ }
+ }
+ return false;
+#endif
+ }
+
+ public static bool GetMouseButtonUp(int button)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetMouseButtonUp(button);
+#else
+ if (Mouse.current == null)
+ {
+ return false;
+ }
+
+ if (mouseButtons[button] && !Mouse.current.leftButton.isPressed)
+ {
+ mouseButtons[button] = false;
+ return true;
+ }
+ return false;
+#endif
+ }
+
+ public static bool GetButton(string input)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetButton(input);
+#else
+ ButtonControl buttonPressed = GetButtonControlFromString(input);
+
+ if (!buttons.ContainsKey(input))
+ {
+ buttons.Add(input, false);
+ }
+
+ return buttonPressed != null ? buttonPressed.isPressed : false;
+#endif
+ }
+
+ private static ButtonControl GetButtonControlFromString(string input)
+ {
+ if (Gamepad.current == null)
+ {
+ return null;
+ }
+
+ switch (input)
+ {
+ case "Submit":
+ return Gamepad.current.aButton;
+ case "Cancel":
+ return Gamepad.current.bButton;
+ default:
+ return null;
+ }
+ }
+
+ public static bool GetButtonDown(string input)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetButtonDown(input);
+#else
+ ButtonControl buttonPressed = GetButtonControlFromString(input);
+
+ if (buttonPressed.isPressed)
+ {
+ if (!buttons.ContainsKey(input))
+ {
+ buttons.Add(input, false);
+ }
+
+ if (!buttons[input])
+ {
+ buttons[input] = true;
+ return true;
+ }
+ }
+ else
+ {
+ buttons[input] = false;
+ }
+ return false;
+#endif
+ }
+
+ public static bool GetButtonUp(string input)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetButtonUp(input);
+#else
+ ButtonControl buttonPressed = GetButtonControlFromString(input);
+
+ if (buttons[input] && !buttonPressed.isPressed)
+ {
+ buttons[input] = false;
+ return true;
+ }
+ return false;
+#endif
+ }
+
+ public static bool GetKey(KeyCode key)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetKey(key);
+#else
+ KeyControl keyPressed = GetKeyControlFromKeyCode(key);
+ if (!keys.ContainsKey(key))
+ {
+ keys.Add(key, false);
+ }
+
+ return keyPressed != null ? keyPressed.isPressed : false;
+#endif
+ }
+
+ private static KeyControl GetKeyControlFromKeyCode(KeyCode key)
+ {
+ if (Keyboard.current == null)
+ {
+ return null;
+ }
+
+ switch (key)
+ {
+ case KeyCode.Escape:
+ return Keyboard.current.escapeKey;
+ case KeyCode.KeypadEnter:
+ return Keyboard.current.numpadEnterKey;
+ case KeyCode.UpArrow:
+ return Keyboard.current.upArrowKey;
+ case KeyCode.DownArrow:
+ return Keyboard.current.downArrowKey;
+ case KeyCode.RightArrow:
+ return Keyboard.current.rightArrowKey;
+ case KeyCode.LeftArrow:
+ return Keyboard.current.leftArrowKey;
+ case KeyCode.LeftShift:
+ return Keyboard.current.leftShiftKey;
+ case KeyCode.Tab:
+ return Keyboard.current.tabKey;
+ default:
+ return null;
+ }
+ }
+
+ public static bool GetKeyDown(KeyCode key)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetKeyDown(key);
+#else
+ KeyControl keyPressed = GetKeyControlFromKeyCode(key);
+ if (keyPressed.isPressed)
+ {
+ if (!keys.ContainsKey(key))
+ {
+ keys.Add(key, false);
+ }
+
+ if (!keys[key])
+ {
+ keys[key] = true;
+ return true;
+ }
+ }
+ else
+ {
+ keys[key] = false;
+ }
+ return false;
+#endif
+ }
+
+ public static bool GetKeyUp(KeyCode key)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetKeyUp(key);
+#else
+ KeyControl keyPressed = GetKeyControlFromKeyCode(key);
+ if (keys[key] && !keyPressed.isPressed)
+ {
+ keys[key] = false;
+ return true;
+ }
+ return false;
+#endif
+ }
+
+ public static float GetAxisRaw(string axis)
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.GetAxisRaw(axis);
+#else
+ if (Gamepad.current == null)
+ {
+ return 0f;
+ }
+
+ switch (axis)
+ {
+ case "Horizontal":
+ return Gamepad.current.leftStick.x.ReadValue();
+ case "Vertical":
+ return Gamepad.current.leftStick.y.ReadValue();
+
+ }
+ return 0f;
+#endif
+ }
+
+ public static Vector3 MousePosition
+ {
+ get
+ {
+#if ENABLE_LEGACY_INPUT_MANAGER
+ return Input.mousePosition;
+#else
+ return Mouse.current.position.ReadValue();
+#endif
+ }
+ }
+ }
+}
diff --git a/Runtime/Scripts/InputModules/GamePadInputModule.cs.meta b/Runtime/Scripts/Utilities/UIExtensionsInputManager.cs.meta
similarity index 57%
rename from Runtime/Scripts/InputModules/GamePadInputModule.cs.meta
rename to Runtime/Scripts/Utilities/UIExtensionsInputManager.cs.meta
index a331d60..f7dc41c 100644
--- a/Runtime/Scripts/InputModules/GamePadInputModule.cs.meta
+++ b/Runtime/Scripts/Utilities/UIExtensionsInputManager.cs.meta
@@ -1,8 +1,11 @@
fileFormatVersion: 2
-guid: 26158f38115d49a4a915f46c7eced4ab
+guid: de7e73fc10fb95143a19dbc76c2595a7
MonoImporter:
+ externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/Scripts/Utilities/UIScrollToSelection.cs b/Runtime/Scripts/Utilities/UIScrollToSelection.cs
index 6eff1ae..478e049 100644
--- a/Runtime/Scripts/Utilities/UIScrollToSelection.cs
+++ b/Runtime/Scripts/Utilities/UIScrollToSelection.cs
@@ -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;
diff --git a/Runtime/Scripts/VR Extensions/VRCursor.cs b/Runtime/Scripts/VR Extensions/VRCursor.cs
index 3edad87..50e06ad 100644
--- a/Runtime/Scripts/VR Extensions/VRCursor.cs
+++ b/Runtime/Scripts/VR Extensions/VRCursor.cs
@@ -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);
}
diff --git a/Runtime/UnityUIExtensions.asmdef b/Runtime/UnityUIExtensions.asmdef
index 66e9532..f9b5f8a 100644
--- a/Runtime/UnityUIExtensions.asmdef
+++ b/Runtime/UnityUIExtensions.asmdef
@@ -1,7 +1,8 @@
{
"name": "UnityUIExtensions",
"references": [
- "GUID:2bafac87e7f4b9b418d9448d219b01ab"
+ "GUID:2bafac87e7f4b9b418d9448d219b01ab",
+ "GUID:75469ad4d38634e559750d17036d5f7c"
],
"includePlatforms": [],
"excludePlatforms": [],
@@ -10,5 +11,6 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
- "versionDefines": []
+ "versionDefines": [],
+ "noEngineReferences": false
}
\ No newline at end of file