public void DragAsset(Touch touch)
 {
     if (touch.phase == TouchPhase.Moved)
     {
         touchTxt.text = "MOVE";
     }
 }
    /// <summary>
    /// Determines if a touch drag has occurred, and if so passes the value to the Build Manager
    /// </summary>
    /// <param name="touch"></param>
    public void DragAsset(Touch touch)
    {
        if (touch.phase != TouchPhase.Moved)
        {
            return;
        }

        BuildManager.Instance?.MoveAsset(touch.screenPosition);
    }
Exemple #3
0
    public override void OnTouch(Touch touch, Vector3 touchPosition)
    {
        // Destroy on touch
        if (touch.phase != TouchPhase.Began && (touch.time - touch.startTime) > tapWindow)
        {
            return;
        }

        OnEnemyKilledByPlayer();
    }
Exemple #4
0
    public void CheckSwipe()
    {
        //Aqui checa-se se existe exatamente um dedo ativo na tela
        if (Touch.activeFingers.Count == 1)
        {
            Touch activeTouch = Touch.activeFingers[0].currentTouch;

            //O código so continua caso o toque esteja em sua fase final ("Ended")
            if (activeTouch.phase != TouchPhase.Ended)
            {
                return;
            }

            //As diferenças entre os valores inicial e final de X e Y são calculadas
            float difX = activeTouch.screenPosition.x - activeTouch.startScreenPosition.x;
            float difY = activeTouch.screenPosition.y - activeTouch.startScreenPosition.y;

            //Aqui é checado qual deslocamento no eixo foi maior
            //Caso o maior seja X, o código detecta esquerda ou direita
            //Caso o maior seja Y, o código detecta baixo ou cima
            if (Mathf.Abs(difX) > Mathf.Abs(difY))
            {
                //Aqui checa-se se difX é positivo ou negativo
                if (difX < -swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE ESQUERDO
                    //Debug.LogWarning("ESQUERDA");
                    StartCoroutine(fightManagerScript.PerformMove(Move.ESQUERDA));
                }
                else if (difX > swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE DIREITO
                    //Debug.LogWarning("DIREITA");
                    StartCoroutine(fightManagerScript.PerformMove(Move.DIREITA));
                }
            }
            else
            {
                //Aqui checa-se se difY é positivo ou negativo
                if (difY < -swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE PARA BAIXO
                    //Debug.LogWarning("BAIXO");
                    StartCoroutine(fightManagerScript.PerformMove(Move.BAIXO));
                }
                else if (difY > swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE PARA CIMA
                    //Debug.LogWarning("CIMA");
                    StartCoroutine(fightManagerScript.PerformMove(Move.CIMA));
                }
            }
        }
    }
Exemple #5
0
 protected override void ProcessTouchesMoved(Touch touch)
 {
     if (state.IsRecognizeState(RecognizeState.Failed))
     {
         return;
     }
     if (Vector2.Distance(touch.startScreenPosition, touch.screenPosition) > 30f)
     {
         Debug.Log("tap gesture failed2.");
         state.UpdateRecognizeState(RecognizeState.Failed);// = Owlet.GestureRecognizerState.Failed;
     }
 }
    /// <summary>
    /// Move the camera based on a touch position
    /// </summary>
    /// <param name="touch">Touch data associated with finger that is touching the screen</param>
    private void MoveCamera(Touch touch)
    {
        // Ensure that remaining logic only executes if the finger is actively moving
        if (touch.phase != TouchPhase.Moved)
        {
            return;
        }

        //Calculate the new camera position based on the current touch position and desired touch speed.
        Vector3 newPosition = new Vector3(-touch.delta.normalized.x, 0, -touch.delta.normalized.y) *
                              Time.deltaTime * TouchSpeed;

        //Pass the new target position to the camera for calculation
        CameraController.Instance?.Move(newPosition);
    }
Exemple #7
0
    void Tap(Finger finger)
    {
        // TODO Support 3+
        if (Touch.activeTouches.Count == 2)
        {
            Vector2[] reals = new Vector2[2];
            for (int i = 0; i < 2; i++)
            {
                Touch touch = Touch.activeTouches[i];
                reals[i] = TouchToGamePos(touch.screenPosition);
            }

            // Return note
            noteAction(new Note(reals, GenerateCloudFromReals(reals), jukeTime));
        }
    }
    void Update()
    {
        // ensures we're not doing anything if there's
        // no reference to the ball

        if (currentBallRigidbody == null)
        {
            return;
        }
        else
        {
            currentBallRigidbody.isKinematic = false;

            if (Touch.activeTouches.Count == 0)
            {
                if (isDragging)
                {
                    LaunchBall();
                }

                isDragging = false;

                return;
            }

            // setting our ball to not interact with physics
            // set dragging bool to true

            currentBallRigidbody.isKinematic = true;
            isDragging = true;

            // get position of our first finger touch

            Touch currentTouch = Touch.activeTouches[0];

            // taking our camera's xy coords and converting them to
            // world point, then setting our rigid body pos to this point

            Vector3 worldPosition = mainCamera.ScreenToWorldPoint(currentTouch.screenPosition);

            currentBallRigidbody.position = worldPosition;
        }
    }
Exemple #9
0
    public void CheckTap()
    {
        if (Touch.activeFingers.Count == 1)
        {
            Touch activeTouch = Touch.activeFingers[0].currentTouch;

            if (activeTouch.isTap)
            {
                if (TextPlayer.instance.SourcesPlaying())
                {
                    TextPlayer.instance.StopAudio();
                }
                else if (ShiftManagementScript.state == BattleState.PLAYERTURN)
                {
                    StartCoroutine(fightManagerScript.PlayGameStatus());
                }
            }
        }
    }
    private void PerformJoystickActions(UnityEngine.InputSystem.EnhancedTouch.Touch touch)
    {
        if (touch.phase == UnityEngine.InputSystem.TouchPhase.Began)
        {
            joystick.RevealPad(startTouchPosition);
        }

        if (touch.phase == UnityEngine.InputSystem.TouchPhase.Moved)
        {
            joystick.TransformNavStick(touchPosition);
        }

        if (touch.phase == UnityEngine.InputSystem.TouchPhase.Ended)
        {
            joystick.HidePad();
            isJoystickActive = false;
        }

        playerMovement.CalculateMovement(startTouchPosition, touchPosition);
    }
    /// <summary>
    /// Dictates the control behaviour of the Joystick UI.
    /// </summary>
    private void OnJoyStickControl(UnityEngine.InputSystem.EnhancedTouch.Touch touch)
    {
        touchPosition      = touch.screenPosition;
        startTouchPosition = touch.startScreenPosition;

        if (touchPosition.x > Screen.width / 2)
        {
            return;
        }
        if (!isJoystickActive)
        {
            currentTocuhID   = touch.touchId;
            isJoystickActive = true;
        }

        if (currentTocuhID == touch.touchId && isJoystickActive)
        {
            //Debug.Log("Is passed id test condition");
            PerformJoystickActions(touch);
        }
    }
    /// <summary>
    /// Zoom the camera based on pinching movement
    /// </summary>
    /// <param name="firstTouch">Touch data relating to the first finger touching the screen</param>
    /// <param name="secondTouch">Touch data relating to the second finger the screen</param>
    private void ZoomCamera(Touch firstTouch, Touch secondTouch)
    {
        if (firstTouch.phase == TouchPhase.Began || secondTouch.phase == TouchPhase.Began)
        {
            lastMultiTouchDistance = Vector2.Distance(firstTouch.screenPosition, secondTouch.screenPosition);
        }

        // Ensure that remaining logic only executes if either finger is actively moving
        if (firstTouch.phase != TouchPhase.Moved || secondTouch.phase != TouchPhase.Moved)
        {
            return;
        }

        //Calculate if fingers are pinching together or apart
        float newMultiTouchDistance = Vector2.Distance(firstTouch.screenPosition, secondTouch.screenPosition);

        //Call the zoom method on the camera, specifying if it's zooming in our out
        CameraController.Instance?.Zoom(newMultiTouchDistance < lastMultiTouchDistance);

        // Set the last distance calculation
        lastMultiTouchDistance = newMultiTouchDistance;
    }
Exemple #13
0
    protected override void ProcessTouchesEnded(Touch touch)
    {
        state.UpdateTouchState(TouchState.Finished);

        if (state.IsRecognizeState(RecognizeState.Failed))
        {
            return;
        }

        if (state.IsRecognizeState(RecognizeState.Unknown))//  == Owlet.GestureRecognizerState.Began)
        {
            if (touch.time - touch.startTime > 0.3f)
            {
                Debug.Log("tap gesture failed1.");
                state.UpdateRecognizeState(RecognizeState.Failed);
            }
            else
            {
                state.UpdateRecognizeState(RecognizeState.Succeeded);
                Debug.Log("trigger tap gesture.");
            }
        }
    }
Exemple #14
0
    void UpdateWithTouch()
    {
        int touchCount = Touch.activeTouches.Count;

        if (touchCount == 1)
        {
            Touch touch = Touch.activeTouches[0];

            switch (touch.phase)
            {
            case TouchPhase.Began: {
                if (ignoreUI || !IsPointerOverUIObject())
                {
                    touch0StartPosition = touch.screenPosition;
                    touch0StartTime     = Time.time;
                    touch0LastPosition  = touch0StartPosition;

                    isTouching = true;

                    if (onStartTouch != null)
                    {
                        onStartTouch(touch0StartPosition);
                    }
                }

                break;
            }

            case TouchPhase.Moved:
            {
                touch0LastPosition = touch.screenPosition;

                if (touch.delta != Vector2.zero && isTouching)
                {
                    DoOnSwipe(touch.delta);
                }
                break;
            }

            case TouchPhase.Ended: {
                if (Time.time - touch0StartTime <= maxDurationForTap &&
                    Vector2.Distance(touch.screenPosition, touch0StartPosition) <= maxDistanceForTap &&
                    isTouching)
                {
                    DoOnClick(touch.screenPosition);
                }

                if (onEndTouch != null)
                {
                    onEndTouch(touch.screenPosition);
                }
                isTouching           = false;
                cameraControlEnabled = true;
                break;
            }

            case TouchPhase.Stationary:
            case TouchPhase.Canceled:
                break;
            }
        }
        else if (touchCount == 2)
        {
            Touch touch0 = Touch.activeTouches[0];
            Touch touch1 = Touch.activeTouches[1];

            if (touch0.phase == TouchPhase.Ended || touch1.phase == TouchPhase.Ended)
            {
                return;
            }

            isTouching = true;

            float previousDistance = Vector2.Distance(touch0.screenPosition - touch0.delta, touch1.screenPosition - touch1.delta);

            float currentDistance = Vector2.Distance(touch0.screenPosition, touch1.screenPosition);

            if (previousDistance != currentDistance)
            {
                DoOnPinch((touch0.screenPosition + touch1.screenPosition) / 2, previousDistance, currentDistance, (touch1.screenPosition - touch0.screenPosition).normalized);
            }
        }
        else
        {
            if (isTouching)
            {
                if (onEndTouch != null)
                {
                    onEndTouch(touch0LastPosition);
                }
                isTouching = false;
            }

            cameraControlEnabled = true;
        }
    }
Exemple #15
0
 protected override void ProcessTouchBegan(Touch touch)
 {
     state.UpdateTouchState(TouchState.Touching);
 }
    private void UpdateTouchscreen()
    {
        if (Touch.activeFingers.Count == 1)
        {
            Touch touch = Touch.activeTouches[0];

            transformCache.position = dummyTransform.position = Vector3.zero;

            var hasHitRestrictedHitArea = false;

            if (touch.phase == TouchPhase.Began)
            {
                _touch0StartPosition = touch.screenPosition;
                _isTrackingTouch0    = true;
            }

            if (_touch0StartPosition.x < 200f && _touch0StartPosition.y > Screen.height - 200f)
            {
                hasHitRestrictedHitArea = true;
            }

            if (!hasHitRestrictedHitArea)
            {
                if (_isTrackingTouch0)
                {
                    Vector3 touchPositionDifference = touch.screenPosition - _touch0StartPosition;
                    dummyTransform.Rotate(Vector3.up, touchPositionDifference.x * 0.4f, Space.World);

                    dummyTransform.Rotate(dummyTransform.right.normalized, touchPositionDifference.y * -0.4f,
                                          Space.World);
                    _rot2 = dummyTransform.rotation;
                    _touch0StartPosition = touch.screenPosition;
                }
                transformCache.rotation = Quaternion.Lerp(transformCache.rotation, _rot2, Time.deltaTime * 4f);
            }

            if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
            {
                _isTrackingTouch0 = false;
            }
        }
        else if (Touch.activeFingers.Count == 2)
        {
            var firstTouch  = Touch.activeTouches[0];
            var secondTouch = Touch.activeTouches[1];

            transformCache.position = dummyTransform.position = Vector3.zero;

            if (firstTouch.phase == TouchPhase.Began || secondTouch.phase == TouchPhase.Began)
            {
                _startMultiTouchDistance = Vector2.Distance(firstTouch.screenPosition, secondTouch.screenPosition);

                _startMultiTouchRadius = _radius;
            }

            if (firstTouch.phase == TouchPhase.Moved || secondTouch.phase == TouchPhase.Moved)
            {
                _radius = _startMultiTouchRadius;

                var distance = Vector2.Distance(firstTouch.screenPosition, secondTouch.screenPosition) - _startMultiTouchDistance;
                var delta    = distance / 250 * zoomSpeed * -_radius;

                _radius += delta;

                if (_radius < RadiusMin)
                {
                    var radDiff = RadiusMin - _radius;
                    positionOffset += transformCache.forward * (radDiff * 4f);
                    _radius         = RadiusMin;
                }
            }
        }

        _positionOffsetCurrent  = Vector3.Lerp(_positionOffsetCurrent, positionOffset, Time.deltaTime * 4f);
        _radiusCurrent          = Mathf.Lerp(_radiusCurrent, _radius, Time.deltaTime * 4f);
        _focusPoint             = transformCache.forward * -1f * _radiusCurrent;
        transformCache.position = _focusPoint + _positionOffsetCurrent;
        dummyTransform.position = transformCache.position;
    }
Exemple #17
0
 public abstract void OnTouch(Touch touch, Vector3 touchPosition);
 protected virtual void ProcessTouchesEnded(Touch touch)
 {
     //Debug.Log($"ProcessTouchesEnded {state} {touch.touchId}");
 }
 protected virtual void ProcessTouchBegan(Touch touch)
 {
     //Debug.Log($"ProcessTouchBegan {state} {touch.touchId}");
 }