-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Fixed multiple OnScreenStick
Components that does not work together when using them simultaneously in isolation mode (ISXB-813)
#2090
base: develop
Are you sure you want to change the base?
Changes from 3 commits
d209cbe
a7ca2e9
239fb7f
34eedc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using UnityEngine.InputSystem.Layouts; | ||
using UnityEngine.InputSystem.Utilities; | ||
using UnityEngine.UI; | ||
using UnityEngine.InputSystem.Controls; | ||
|
||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
|
@@ -91,7 +92,10 @@ private void Start() | |
if (m_PointerDownAction == null || m_PointerDownAction.bindings.Count == 0) | ||
{ | ||
if (m_PointerDownAction == null) | ||
m_PointerDownAction = new InputAction(); | ||
m_PointerDownAction = new InputAction(type: InputActionType.PassThrough); | ||
// ensure PassThrough mode | ||
else if (m_PointerDownAction.m_Type != InputActionType.PassThrough) | ||
m_PointerDownAction.m_Type = InputActionType.PassThrough; | ||
|
||
#if UNITY_EDITOR | ||
InputExitPlayModeAnalytic.suppress = true; | ||
|
@@ -121,8 +125,7 @@ private void Start() | |
#endif | ||
} | ||
|
||
m_PointerDownAction.started += OnPointerDown; | ||
m_PointerDownAction.canceled += OnPointerUp; | ||
m_PointerDownAction.performed += OnPointerChanged; | ||
m_PointerDownAction.Enable(); | ||
m_PointerMoveAction.Enable(); | ||
} | ||
|
@@ -154,8 +157,7 @@ private void OnDestroy() | |
{ | ||
if (m_UseIsolatedInputActions) | ||
{ | ||
m_PointerDownAction.started -= OnPointerDown; | ||
m_PointerDownAction.canceled -= OnPointerUp; | ||
m_PointerDownAction.performed -= OnPointerChanged; | ||
} | ||
} | ||
|
||
|
@@ -227,11 +229,20 @@ private void EndInteraction() | |
|
||
private void OnPointerDown(InputAction.CallbackContext ctx) | ||
{ | ||
if (m_IsIsolationActive) { return; } | ||
Debug.Assert(EventSystem.current != null); | ||
|
||
var screenPosition = Vector2.zero; | ||
if (ctx.control?.device is Pointer pointer) | ||
TouchControl touchControl = null; | ||
if (ctx.control?.parent is TouchControl touch) | ||
{ | ||
touchControl = touch; | ||
screenPosition = touch.position.ReadValue(); | ||
} | ||
else if (ctx.control?.device is Pointer pointer) | ||
{ | ||
screenPosition = pointer.position.ReadValue(); | ||
} | ||
|
||
m_PointerEventData.position = screenPosition; | ||
EventSystem.current.RaycastAll(m_PointerEventData, m_RaycastResults); | ||
|
@@ -251,23 +262,63 @@ private void OnPointerDown(InputAction.CallbackContext ctx) | |
return; | ||
|
||
BeginInteraction(screenPosition, GetCameraFromCanvas()); | ||
if (touchControl != null) | ||
{ | ||
m_TouchControl = touchControl; | ||
m_PointerMoveAction.ApplyBindingOverride($"{touchControl.path}/position", path: "<Touchscreen>/touch*/position"); | ||
} | ||
|
||
m_PointerMoveAction.performed += OnPointerMove; | ||
m_IsIsolationActive = true; | ||
} | ||
|
||
private void OnPointerChanged(InputAction.CallbackContext ctx) | ||
{ | ||
if (ctx.control.IsPressed()) | ||
OnPointerDown(ctx); | ||
else | ||
OnPointerUp(ctx); | ||
} | ||
|
||
private void OnPointerMove(InputAction.CallbackContext ctx) | ||
{ | ||
// only pointer devices are allowed | ||
Debug.Assert(ctx.control?.device is Pointer); | ||
Vector2 screenPosition; | ||
|
||
var screenPosition = ((Pointer)ctx.control.device).position.ReadValue(); | ||
// If it's a finger take the value from the finger that initiated the change | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More a general conceptual thought around the scalability of this than the particular fix, what if the on screen control is interacted with a pen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good question I don't have a pen/touch setup to test. |
||
if (m_TouchControl != null) | ||
{ | ||
// if the finger is up ignore the move | ||
if (m_TouchControl.isInProgress == false) | ||
{ | ||
return; | ||
} | ||
screenPosition = m_TouchControl.position.ReadValue(); | ||
} | ||
else | ||
{ | ||
screenPosition = ((Pointer)ctx.control.device).position.ReadValue(); | ||
} | ||
|
||
MoveStick(screenPosition, GetCameraFromCanvas()); | ||
} | ||
|
||
private void OnPointerUp(InputAction.CallbackContext ctx) | ||
{ | ||
if (!m_IsIsolationActive) return; | ||
|
||
// if it's a finger ensure that is the one that get released | ||
if (m_TouchControl != null) | ||
{ | ||
if (m_TouchControl.isInProgress) return; | ||
m_PointerMoveAction.ApplyBindingOverride(null, path: "<Touchscreen>/touch*/position"); | ||
m_TouchControl = null; | ||
} | ||
|
||
EndInteraction(); | ||
m_PointerMoveAction.performed -= OnPointerMove; | ||
m_IsIsolationActive = false; | ||
} | ||
|
||
private Camera GetCameraFromCanvas() | ||
|
@@ -430,6 +481,10 @@ public bool useIsolatedInputActions | |
private List<RaycastResult> m_RaycastResults; | ||
[NonSerialized] | ||
private PointerEventData m_PointerEventData; | ||
[NonSerialized] | ||
private TouchControl m_TouchControl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really related to this fix, but more to the original design, this implies that a member would need to be added for any kind of pointer device right? Or is this particularly due to TouchControl not being a derivative of pointer in your opinion @bmalrat ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally we don't need it for each type, only for touch to identify which one was touched in the /touch*/press. I'm not aware of an other type that could aggregate multiple source into one binding. |
||
[NonSerialized] | ||
private bool m_IsIsolationActive; | ||
|
||
protected override string controlPathInternal | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this is the design, generally this is a perfect fit for a device-agnostic pointer interface (just a side note)