mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
use pointer position from last event
This commit is contained in:
parent
074f7d0d98
commit
ee64560d4b
2 changed files with 14 additions and 4 deletions
|
@ -5,7 +5,7 @@ using UnityEngine.EventSystems;
|
|||
namespace SanAndreasUnity.Utilities
|
||||
{
|
||||
|
||||
public class ArrowsMovementButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
public class ArrowsMovementButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IDragHandler
|
||||
{
|
||||
|
||||
public RawImage leftArrow, rightArrow, upArrow, downArrow;
|
||||
|
@ -15,6 +15,8 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
public bool IsPointerInside { get; private set; } = false;
|
||||
|
||||
public Vector2 LastPointerPos { get; private set; } = Vector2.zero;
|
||||
|
||||
|
||||
|
||||
void OnDisable()
|
||||
|
@ -26,6 +28,7 @@ namespace SanAndreasUnity.Utilities
|
|||
public void OnPointerDown(PointerEventData pointerEventData)
|
||||
{
|
||||
m_isPointerDown = true;
|
||||
this.LastPointerPos = pointerEventData.position;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData pointerEventData)
|
||||
|
@ -36,6 +39,7 @@ namespace SanAndreasUnity.Utilities
|
|||
public void OnPointerEnter(PointerEventData pointerEventData)
|
||||
{
|
||||
this.IsPointerInside = true;
|
||||
this.LastPointerPos = pointerEventData.position;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData pointerEventData)
|
||||
|
@ -43,13 +47,19 @@ namespace SanAndreasUnity.Utilities
|
|||
this.IsPointerInside = false;
|
||||
}
|
||||
|
||||
public void OnDrag (PointerEventData pointerEventData)
|
||||
{
|
||||
this.LastPointerPos = pointerEventData.position;
|
||||
}
|
||||
|
||||
|
||||
public Vector2 GetMovementNonNormalized()
|
||||
{
|
||||
if (!m_isPointerDown || !this.IsPointerInside)
|
||||
return Vector2.zero;
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
Vector2 pointerPos = this.LastPointerPos;
|
||||
Vector2 localPoint = Vector2.zero;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform, mousePos, null, out localPoint))
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform, pointerPos, null, out localPoint))
|
||||
return Vector2.zero;
|
||||
Vector2 diff = localPoint;
|
||||
return diff;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
- Android: add perms for read/write access to storage ; forbid screen rotation ; assign app version ;
|
||||
|
||||
- Touch input: lock cursor when testing finishes ; add vehicle turn multiplier ;
|
||||
- Touch input: lock cursor when testing finishes ;
|
||||
|
||||
- Play sounds: horn ; empty weapon slot ; ped damage ; footsteps in run and sprint states ;
|
||||
|
||||
|
|
Loading…
Reference in a new issue