How to get swipping event

Hi Developers.
I want to get swipe event in Trigger.

I can see below.

TouchpadRepresents “Trigger” button,and is also used as a touchpad. It can detect touching and swipping.
Customize Controller UI - NRSDK

I looked into MultiScreenController & NRVirtualDisplayer but I didn’t get how to get swipe event from Trigger.
Anyone knows how to get swipping event correctly?

Regards,
Yuma

Hi Yuma, sorry to tell you that we haven’t give out the available interface for swiping event. But the following codes demonstrate how to listen to it. Hope it’s helpful for you.

preIsTouching = isTouching;
            isTouching = NRInput.IsTouching();
            if (!preIsTouching && isTouching)
            {
                mDownPos = NRInput.GetTouch();//Note the starting position of touching
                mPointerDown = true;
                Debug.LogError("Update touching downPos =" + mDownPos);
                dragNormalizedValue = normalizedValue;
                return;
            }
            if (isTouching)
            {
                if(Vector2.Distance(NRInput.GetTouch(),mDownPos)>0.1f)
                {
                    //touch move. That means touch swipe
                }
            }
1 Like

Hello Doris
Thank you for your code!!.
I forgot ‘NRInput’ :frowning:

I implemented like this with SystemInputState
I don’t know this is a best practice and this algo that gets a detection for swipe is not perfect. It feels lazy little bit

but It works for me.

using UnityEngine;
using NRKernal;

public class TestSwipe : MonoBehaviour
{

    private static SystemInputState _systemInputState;
    private bool _previousState = false;
    private Vector2 _tappedPosition = new Vector2(0, 0);
    private Vector2 _previousPosition = new Vector2(0, 0);

    private void Start()
    {
        _systemInputState = NRVirtualDisplayer.SystemButtonState;
    }

    private void Update()
    {
        checkInput();
    }

    private void checkInput()
    {
        bool curState = _systemInputState.buttons[0];
        if(curState != _previousState)
        {
            if (curState)
            {
                _tappedPosition = _systemInputState.touch;
            }
            else
            {
                float dx = _previousPosition.x - _tappedPosition.x;
                float absDx = Mathf.Abs(dx);
                if(absDx > 0)
                {
                    if(dx > 0)
                    {
                        Debug.Log("Swiped Right >>>>>>>>>>>");
                    }
                    else
                    {
                        Debug.Log("Swiped Left <<<<<<<<<<<");
                    }
                    updatePrevious();
                    return;
                }
            }
        }

        if (curState != _previousState)
        {
            if (!curState)
            {
                Debug.Log("Tapped");
            }
        }
        updatePrevious();
    }

    private void updatePrevious()
    {
        _previousState = _systemInputState.buttons[0];
        _previousPosition = _systemInputState.touch;
    }
}
1 Like