Esempio n. 1
0
    public static void Update()
    {
        if (Input.touchCount != TouchCount && OnTouchCountChanged != null)
        {
            TouchCount = Input.touchCount;
            OnTouchCountChanged();
        }

        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; ++i)
            {
                Touch     currentTouch = Input.touches[i];
                TouchInfo touchInfo    = GetTouchInfo(currentTouch);

                if (touchInfo == null)
                {
                    touchInfos.Add(new TouchInfo(currentTouch));
                }
                else
                {
                    touchInfo.UpdateInfo(currentTouch);
                }

                switch (currentTouch.phase)
                {
                case TouchPhase.Began:
                    OnTouchStart?.Invoke(touchInfo);
                    break;

                case TouchPhase.Stationary:
                    OnTouchHold?.Invoke(touchInfo);
                    break;

                case TouchPhase.Moved:
                    OnTouchMove?.Invoke(touchInfo);
                    break;

                case TouchPhase.Ended:
                    touchInfos.Remove(touchInfo);
                    OnTouchEnd?.Invoke(touchInfo);
                    break;

                case TouchPhase.Canceled:
                    touchInfos.Remove(touchInfo);
                    OnTouchCancel?.Invoke(touchInfo);
                    break;

                default:
                    continue;
                }
            }
        }
    }
    public virtual void TouchHold(Vector2 _touchScreenLocation)
    {
        touchWorldPoint       = cameraRef.ScreenToWorldPoint(_touchScreenLocation);
        touchScreenCoordinate = _touchScreenLocation;
        endTouchLocation      = _touchScreenLocation;
        deltaRelease          = endTouchLocation - startTouchLocation;

        touchScreenRatio.x = _touchScreenLocation.x / Screen.width;
        touchScreenRatio.y = _touchScreenLocation.y / Screen.height;


        touchInfo.touchWorldPoint       = touchWorldPoint;
        touchInfo.touchScreenCoordinate = touchScreenCoordinate;
        touchInfo.endTouchLocation      = endTouchLocation;
        touchInfo.deltaRelease          = deltaRelease;
        touchInfo.touchScreenRatio      = touchScreenRatio;


        OnTouchHold?.Invoke(touchInfo);
    }