コード例 #1
0
ファイル: CameraControl.cs プロジェクト: Chapmania/Juniper
 private bool GestureSatisfied(Mode mode)
 {
     if (mode == Mode.None)
     {
         return(false);
     }
     else if (mode == Mode.Gamepad || mode == Mode.MagicWindow)
     {
         return(true);
     }
     else if (mode == Mode.Touch)
     {
         if (UnityInput.touchCount != requiredTouchCount)
         {
             return(false);
         }
         else
         {
             var touchPhase = UnityInput.GetTouch(requiredTouchCount - 1).phase;
             return(touchPhase == TouchPhase.Moved ||
                    touchPhase == TouchPhase.Stationary);
         }
     }
     else if (mode == Mode.NetworkView)
     {
         return(NetworkPose.HasValue);
     }
     else
     {
         var btn     = (int)requiredMouseButton;
         var pressed = requiredMouseButton == InputEventButton.None || UnityInput.GetMouseButton(btn);
         var down    = requiredMouseButton != InputEventButton.None && UnityInput.GetMouseButtonDown(btn);
         return(pressed && !down && (mode != Mode.MouseLocked || Cursor.lockState == CursorLockMode.Locked));
     }
 }
コード例 #2
0
    public void ButtonCenterClicked()
    {
#if UNITY_EDITOR
        if (EditorInput.touchCount > 0)
        {
            UpdateTouchPosition(EditorInput.GetTouch(0));
        }
#endif
        mLastButtonClickedText.text = "ButtonCenter is clicked";
    }
コード例 #3
0
 public override void Update()
 {
     wasPressed = pressed;
     pressed    = false;
     if (UnityInput.touchCount == 1)
     {
         var finger = UnityInput.GetTouch(0);
         pressed           = finger.phase != TouchPhase.Ended && finger.phase != TouchPhase.Canceled;
         lastViewportPoint = ViewportFromScreen(finger.position);
     }
     base.Update();
 }
コード例 #4
0
ファイル: TouchPoint.cs プロジェクト: Chapmania/Juniper
        public override void Update()
        {
            wasPressed = pressed;
            var finger = ActiveThisFrame
                ? UnityInput.GetTouch(fingerID)
                : DEAD_FINGER;

            pressed = finger.phase != TouchPhase.Ended &&
                      finger.phase != TouchPhase.Canceled;
            lastWorldPoint = WorldFromScreen(finger.position);
            base.Update();
        }
コード例 #5
0
        private void Update()
        {
#if UNITY_EDITOR
            if (UInput.GetMouseButtonDown(0))
            {
                _lastMousePosition = UInput.mousePosition;
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos   = _lastMousePosition,
                    touchDelta = Vector3.zero
                };
                OnTouchStart?.Invoke(tie);
            }
            else if (UInput.GetMouseButton(0))
            {
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos = UInput.mousePosition
                };
                tie.touchDelta     = tie.touchPos - _lastMousePosition;
                _lastMousePosition = tie.touchPos;
                OnTouchStay?.Invoke(tie);
            }
            else if (UInput.GetMouseButtonUp(0))
            {
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos   = UInput.mousePosition,
                    touchDelta = Vector3.zero
                };
                OnTouchRelease?.Invoke(tie);
            }
#elif UNITY_ANDROID
            if (UInput.touchCount > 0)
            {
                // Only polling touch 0
                Touch           touch = UInput.GetTouch(0);
                TouchInputEvent tie   = new TouchInputEvent()
                {
                    touchPos   = touch.position,
                    touchDelta = touch.deltaPosition
                };

                // Send the respective event depending on touch phase state
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    OnTouchStart?.Invoke(tie);
                    break;

                case TouchPhase.Moved:
                case TouchPhase.Stationary:
                    OnTouchStay?.Invoke(tie);
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    OnTouchRelease?.Invoke(tie);
                    break;
                }
            }
#endif
        }
コード例 #6
0
    /// <summary>
    /// Update all touches
    /// </summary>
    void UpdateTouches()
    {
        touchPressedThisFrame = false;
        for (int i = 0; i < UnityInput.touchCount; ++i)
        {
            Touch touch = UnityInput.GetTouch(i);

            // Find existing touch, or create new one
            TouchInfo existingTouch = m_Touches.FirstOrDefault(t => t.touchId == touch.fingerId);

            if (existingTouch == null)
            {
                existingTouch = new TouchInfo
                {
                    touchId = touch.fingerId,
                    startPosition = touch.position,
                    currentPosition = touch.position,
                    previousPosition = touch.position,
                    startTime = Time.realtimeSinceStartup,
                    startedOverUI = EventSystem.current.IsPointerOverGameObject(touch.fingerId)
                };

                m_Touches.Add(existingTouch);

                // Sanity check
                Debug.Assert(touch.phase == TouchPhase.Began);
            }
            switch (touch.phase)
            {
                case TouchPhase.Began:
                    touchPressedThisFrame = true;
                    if (pressed != null)
                    {
                        pressed(existingTouch);
                    }
                    break;

                case TouchPhase.Moved:
                    bool wasDrag = existingTouch.isDrag;
                    UpdateMovingFinger(touch, existingTouch);

                    // Is this a drag?
                    existingTouch.isDrag = existingTouch.totalMovement >= dragThresholdTouch;

                    if (existingTouch.isDrag)
                    {
                        if (existingTouch.isHold)
                        {
                            existingTouch.wasHold = existingTouch.isHold;
                            existingTouch.isHold = false;
                        }
                        // Did it just start now?
                        if (!wasDrag)
                        {
                            if (startedDrag != null)
                            {
                                startedDrag(existingTouch);
                            }
                        }
                        if (dragged != null)
                        {
                            dragged(existingTouch);
                        }

                        if (existingTouch.delta.sqrMagnitude > flickThreshold * flickThreshold)
                        {
                            existingTouch.flickVelocity =
                                (existingTouch.flickVelocity * (1 - k_FlickAccumulationFactor)) +
                                (existingTouch.delta * k_FlickAccumulationFactor);
                        }
                        else
                        {
                            existingTouch.flickVelocity = Vector2.zero;
                        }
                    }
                    else
                    {
                        UpdateHoldingFinger(existingTouch);
                    }
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    // Could have moved a bit
                    UpdateMovingFinger(touch, existingTouch);
                    // Quick enough (with no drift) to be a tap?
                    if (!existingTouch.isDrag &&
                        Time.realtimeSinceStartup - existingTouch.startTime < tapTime)
                    {
                        if (tapped != null)
                        {
                            tapped(existingTouch);
                        }
                    }
                    if (released != null)
                    {
                        released(existingTouch);
                    }

                    // Remove from track list
                    m_Touches.Remove(existingTouch);
                    break;

                case TouchPhase.Stationary:
                    UpdateMovingFinger(touch, existingTouch);
                    UpdateHoldingFinger(existingTouch);
                    existingTouch.flickVelocity = Vector2.zero;
                    break;
            }
        }

        if (activeTouchCount >= 2 && (m_Touches[0].isDrag ||
                                      m_Touches[1].isDrag))
        {
            if (pinched != null)
            {
                pinched(new PinchInfo
                {
                    touch1 = m_Touches[0],
                    touch2 = m_Touches[1]
                });
            }
        }
    }