Beispiel #1
0
        public override bool TryGetPointerPosition(uint sourceId, out Vector3 position)
        {
            Touch?knownTouch = GetTouch((int)sourceId);

            position = (knownTouch.HasValue) ? (Vector3)knownTouch.Value.position : Vector3.zero;
            return(knownTouch.HasValue);
        }
Beispiel #2
0
        //ON TOUCH DEVICES (MOBILE,TABLET)
        void update_touch()
        {
            touches    = Input.touches;    // stored for opti
            touchCount = Input.touchCount; // quantité de doigts a un instant T

            //first, check for new touch and assign touches to fingers
            for (int i = 0; i < touchCount; i++)
            {
                Touch touch = touches[i];
                _finger = getFingerById(touches[i].fingerId);
                if (_finger == null)
                {
                    _finger = getFirstAvailableFinger();
                    _finger.assign(touch.fingerId);
                }
            }

            //second, for each fingers apply state
            for (int i = 0; i < _fingers.Length; i++)
            {
                _finger = _fingers[i]; // never null

                Touch?touch = getSystemTouchById(_fingers[i].fingerId);
                if (touch != null) // active finger
                {
                    _finger.update(touch.Value);
                }
                else if (_finger.isFingerNotCanceled())
                {
                    _finger.setEnded();
                }
            }
        }
Beispiel #3
0
    /// <summary>
    /// タッチ入力情報をGestureInfoへ変換します
    /// </summary>
    /// <returns>入力情報があればtrueを返します</returns>
    /// <param name="info"></param>
    bool InputForTouch(ref GestureInfo info)
    {
        // 基本的にタッチは1点のみ検出するインターフェースとする
        Touch?touch = GetTouch();

        if (!touch.HasValue)
        {
            return(false);
        }
        info.ScreenPosition = touch.GetValueOrDefault().position;
        info.DeltaPosition  = touch.GetValueOrDefault().deltaPosition;
        switch (touch.GetValueOrDefault().phase)
        {
        case TouchPhase.Began:
            info.IsDown = true;
            break;

        case TouchPhase.Moved:
        case TouchPhase.Stationary:
            info.IsDrag = true;
            break;

        case TouchPhase.Ended:
        case TouchPhase.Canceled:
            info.IsUp    = true;
            this.TouchId = -1;                  // タッチ終了
            break;
        }
        return(true);
    }
Beispiel #4
0
    /// <summary>
    /// Decides on current touch phase and classification (single or multiple touches)
    /// </summary>
    void UpdateTouchClassification()
    {
        singleTouchEnded = false;

        foreach (Touch touch in Input.touches)
        {
            switch (touch.phase)
            {
            case TouchPhase.Began:
                if (singleTouch == null && multiTouches.Count == 0)
                {
                    singleTouch = touch;
                }
                else
                {
                    if (singleTouch != null)
                    {
                        multiTouches.Add(singleTouch.Value);
                    }
                    multiTouches.Add(touch);

                    singleTouch = null;
                }
                break;

            case TouchPhase.Ended:
            case TouchPhase.Canceled:
                // not passing last touch makes sprites touch actions work
                if (singleTouch != null)
                {
                    singleTouch = null;
                }
                else
                {
                    multiTouches.Clear();
                }
                singleTouchEnded = true;
                break;

            default:
                if (singleTouch != null && singleTouch.Value.fingerId == touch.fingerId)
                {
                    singleTouch = touch;
                }
                else
                {
                    for (int i = 0; i < multiTouches.Count; ++i)
                    {
                        var multiTouch = multiTouches[i];
                        if (multiTouch.fingerId == touch.fingerId)
                        {
                            multiTouches[i] = touch;
                        }
                    }
                }
                break;
            }
        }
    }
Beispiel #5
0
 public TouchDetector(PlaneTouchHandler planeTouchHandler, VirtualObjectTouchHandler virtualObjectTouchHandler,
                      ARRaycastManager arRaycastmanager, Logger logger)
 {
     this.planeTouchHandler         = planeTouchHandler;
     this.virtualObjectTouchHandler = virtualObjectTouchHandler;
     this.arRaycastmanager          = arRaycastmanager;
     this.logger            = logger;
     this.lastTouch         = null;
     this.lastTouchResolved = false;
     GenericState <TouchDetector> .InitState <SNoTouch>(this);
 }
Beispiel #6
0
 public void Push(IntPtr L, Touch?n)
 {
     if (n == null)
     {
         LuaDLL.lua_pushnil(L);
     }
     else
     {
         ToLua.Push(L, n.Value);
     }
 }
Beispiel #7
0
    private Touch?GetTouchFromBottomButton()
    {
        Touch?tempTouchCheck = GetTouchFromObject(bottomButton);

        //MovingByLeftAndRight();
        if (tempTouchCheck != null)
        {
            Touch tempTouchReal = (Touch)tempTouchCheck;
            return(tempTouchReal);
        }
        return(null);
    }
Beispiel #8
0
        public void Update()
        {
            FirstDownThisFrame  = FirstMoveThisFrame = FirstUpThisFrame = false;
            SecondDownThisFrame = SecondMoveThisFrame = SecondUpThisFrame = false;

            foreach (var touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Began)
                {
                    if (FingerOne == null)
                    {
                        FirstDownThisFrame = true;
                        FingerOne          = touch;
                    }
                    else
                    {
                        SecondDownThisFrame = true;
                        FingerTwo           = touch;
                    }
                }
                else
                {
                    bool isFirst = (FingerOne != null && touch.fingerId == FingerOne.Value.fingerId);
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
                    {
                        if (isFirst)
                        {
                            FingerOne          = touch;
                            FirstMoveThisFrame = true;
                        }
                        else
                        {
                            FingerTwo           = touch;
                            SecondMoveThisFrame = true;
                        }
                    }

                    if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                    {
                        if (isFirst)
                        {
                            FirstUpThisFrame = true;
                            FingerOne        = null;
                        }
                        else
                        {
                            SecondUpThisFrame = true;
                            FingerTwo         = null;
                        }
                    }
                }
            }
        }
Beispiel #9
0
    private float?MovingByTouchLR()
    {
        Touch?tempTouchCheck = GetTouchFromObject(bottomButton);

        //MovingByLeftAndRight();
        if (tempTouchCheck != null)
        {
            Touch tempTouchReal = (Touch)tempTouchCheck;
            return(tempTouchReal.position.x);
        }
        return(null);
    }
Beispiel #10
0
        //---------------------------------------------------------------------------------------------------------------
        void update()
        {
            if (Time.time != lastUpdateTime)
            {
                lastUpdateTime = Time.time;

                var curMousePos = UnityEngine.Input.mousePosition;
                var delta       = curMousePos - prevMousePos;
                prevMousePos = curMousePos;

                fakeTouch = createTouch(getPhase(delta), delta);
            }
        }
Beispiel #11
0
    private void FakeTouch()
    {
        TouchPhase phase;

        if (currentPoint.MouseDown && currentPoint.MouseChange)
        {
            phase = TouchPhase.Began;
        }
        else if (currentPoint.MouseDown && !currentPoint.MouseChange)
        {
            phase = TouchPhase.Moved;
        }
        else if (!currentPoint.MouseDown && currentPoint.MouseChange)
        {
            phase = TouchPhase.Ended;
        }
        else
        {
            touch = null;
            return;
        }

        Vector2 newPos = new Vector2(currentPoint.x, currentPoint.y);
        Vector2 oldPos;

        if (touch.HasValue)
        {
            oldPos = touch.Value.position;
        }
        else
        {
            oldPos = newPos;
        }

        touch = new Touch
        {
            phase         = phase,
            type          = TouchType.Direct,
            position      = newPos,
            rawPosition   = newPos,
            fingerId      = 0,
            tapCount      = 1,
            deltaTime     = Time.deltaTime,
            deltaPosition = newPos - oldPos
        };
    }
Beispiel #12
0
 private void SetPlayerTouches()
 {
     foreach (Touch touch in Input.touches)
     {
         if (touch.phase == TouchPhase.Began)
         {
             if (touch.position.x / Screen.width > 0.5f)
             {
                 player1Touch = touch;
             }
             else
             {
                 player2Touch = touch;
             }
         }
     }
 }
Beispiel #13
0
 /// <summary>
 /// Common tweak method
 /// Used to provide more encapsulation in the derived classes
 /// Automatically calls the TweakControl method
 /// </summary>
 /// <returns>Whether the Tweak has happend</returns>
 protected virtual bool TweakIfNeeded()
 {
     // Check for touches
     if (IsCurrentlyTweaking)
     {
         // Check this method, it also returns a mouse input if we're in the editor
         Touch?touch = GetTouchByFingerId(CurrentFingerId);
         if (touch == null || touch.Value.phase == TouchPhase.Ended)
         {
             ResetControlState();
             return(false);
         }
         TweakControl(touch.Value.position);
         return(true);
     }
     return(false);
 }
Beispiel #14
0
    // Update is called once per frame
    void Update()
    {
        if (CheckTouchThisObjectByTagDeluxe("JoystickStoper") && 1 == 0)
        {
            Touch?     temp = GetTouchFromObject(JoyStoper);
            RaycastHit?rh   = GetRaycastHitFromObject(JoyStoper);
            if (temp != null || rh != null)
            {
                RaycastHit TempRh = rh.Value;
                _joystick.transform.SetPositionAndRotation(TempRh.transform.position, joystick.transform.rotation);
                Debug.Log(_joystick.transform.position.x + "<-x  y->" + _joystick.transform.position.y);


                //Touch temp2 = temp.Value;
                //Debug.Log(temp2.position + " normal");
                //Debug.Log(temp2.rawPosition + " raw");
                //_joystick.transform.SetPositionAndRotation(temp2.position, joystick.transform.rotation);
                //Debug.Log(_joystick.transform.position.x + "<-x  y->" + _joystick.transform.position.y);



                //joystick.transform.position.x = temp2.position.x;
            }
        }

        //foreach (Touch touch in Input.touches)
        //{
        //    int pointerID = touch.fingerId;
        //    if (EventSystem.current.IsPointerOverGameObject(pointerID))
        //    {

        //        // at least on touch is over a canvas UI
        //        return;
        //    }

        //    if (touch.phase == TouchPhase.Ended)
        //    {
        //        // here we don't know if the touch was over an canvas UI
        //        return;
        //    }
        //}
    }
Beispiel #15
0
        public void UpdateInfo(BallInfo?info)
        {
            if (info == null)
            {
                return;
            }
            Info = info.Value;
            var physics = Info.Physics;

            if (physics != null)
            {
                var location = physics.Value.Location;
                Location = location != null?VectorMapper.Map(location.Value) : null;

                var velocity = physics.Value.Velocity;
                Velocity = velocity != null?VectorMapper.Map(velocity.Value) : null;
            }

            LatestTouch = Info.LatestTouch;
        }
Beispiel #16
0
 private void MovingMethodFinger()
 {
     if (Input.touchCount > 0)
     {
         Touch?fingerDirection = GetTouchFromBottomButton();
         if (fingerDirection.HasValue)
         {
             Touch tempTouch = (Touch)fingerDirection;
             MovingByFollowFinger(tempTouch);
         }
         else
         {
             return;
         }
     }
     else
     {
         Paddle.GetComponent <Paddle>().StopPaddle();
     }
 }
Beispiel #17
0
 bool moveJoystick()
 {
     if (touching)
     {
         Touch?touch = getTouch(currentFingerId);
         if (touch == null || touch.Value.phase == TouchPhase.Ended)
         {
             resetJoystickPosition();
             return(false);
         }
         Vector3 globalTouchPosition = joystickCamera.ScreenToWorldPoint(touch.Value.position);
         Vector3 differenceVector    = globalTouchPosition - stickBase.transform.position;
         if (differenceVector.sqrMagnitude > dragDistance * dragDistance)
         {
             differenceVector.Normalize();
             stick.transform.position = stickBase.transform.position + differenceVector * dragDistance;
         }
         else
         {
             stick.transform.position = globalTouchPosition;
         }
         if (!touchPad)
         {
             currentAxisValue = differenceVector;
         }
         else
         {
             Vector3 difference = globalTouchPosition - previousPosition;
             if (differenceVector.sqrMagnitude > dragDistance * dragDistance)
             {
                 difference.Normalize();
             }
             currentAxisValue = difference;
             previousPosition = globalTouchPosition;
         }
         return(true);
     }
     return(false);
 }
Beispiel #18
0
        /// <summary>
        /// マウス下の画素があるかどうかを確認
        /// </summary>
        /// <param name="cam"></param>
        private void HitTestByOpaquePixel()
        {
            Vector2 mousePos;
                    mousePos = Input.mousePosition;

            //// コルーチン & WaitForEndOfFrame ではなく、OnPostRenderで呼ぶならば、MSAAによって上下反転しないといけない?
            //if (QualitySettings.antiAliasing > 1) mousePos.y = camRect.height - mousePos.y;

            // タッチ開始点が指定されれば、それを調べる
            if (firstTouch != null)
            {
                Touch   touch = (Touch)firstTouch;
                Vector2 pos   = touch.position;

                firstTouch = null;

                if (GetOnOpaquePixel(pos))
                {
                    onObject       = true;
                    activeFingerId = touch.fingerId;
                    return;
                }
            }

            // マウス座標を調べる
            if (GetOnOpaquePixel(mousePos))
            {
                //Debug.Log("Mouse " + mousePos);
                onObject = true;
                //activeFingerId = -1;    // タッチ追跡は解除
                return;
            }
            else
            {
                onObject = false;
            }
        }
 public static Vector3?GetFingerOrMousePos(int fingerID)
 {
     if (touchCount > 0)
     {
         if (fingerID != -1)
         {
             Touch?touch = GetTouchByFingerID(fingerID);
             if (touch.HasValue)
             {
                 return(touch.Value.position);
             }
             else
             {
                 Debug.LogError("Cannot get position of invalid finger ID " + fingerID);
                 return(null);
             }
         }
         else
         {
             return(GetTouch(touchCount - 1).position);
         }
     }
     return(mousePosition);
 }
Beispiel #20
0
    void Update()
    {
        lerpTimer = lerpTimer + Time.deltaTime;
        if (lerpTimer < .333)
        {
            screenPosition     = Mathf.Lerp(lastScreenPosition, lerpPage * -1, lerpTimer * 3);
            lastScreenPosition = screenPosition;
        }

        Touch?touch = null;

        if (Input.touchCount > 0)
        {
            touch = Input.GetTouch(0);
        }

        Vector3 touchPosition = touch.HasValue ? new Vector3(
            touch.Value.position.x,
            touch.Value.position.y,
            0) : Input.mousePosition;

        if ((Input.GetMouseButtonDown(0) || (touch.HasValue && touch.Value.phase == TouchPhase.Began)) &&
            touchPosition.y > scrollZoneYMin && touchPosition.y < scrollZoneYMax)
        {
            canSwipe            = true;
            mousePositionStartX = touchPosition.x;
        }


        if (Input.GetMouseButton(0) || (touch.HasValue && touch.Value.phase == TouchPhase.Moved))
        {
            if (canSwipe)
            {
                mousePositionEndX = touchPosition.x;
                dragAmount        = mousePositionEndX - mousePositionStartX;
                screenPosition    = lastScreenPosition + dragAmount;
            }
        }

        if (Mathf.Abs(dragAmount) > swipeThrustHold && canSwipe)
        {
            canSwipe           = false;
            lastScreenPosition = screenPosition;
            if (pageCount < introImages.Length)
            {
                OnSwipeComplete();
            }
            else if (pageCount == introImages.Length && dragAmount < 0)
            {
                lerpTimer = 0;
            }
            else if (pageCount == introImages.Length && dragAmount > 0)
            {
                OnSwipeComplete();
            }
        }

        if (Input.GetMouseButtonUp(0) || (touch.HasValue && touch.Value.phase == TouchPhase.Ended))
        {
            if (Mathf.Abs(dragAmount) < swipeThrustHold)
            {
                lerpTimer = 0;
            }
        }

        for (int i = 0; i < introImages.Length; i++)
        {
            introImages[i].anchoredPosition = new Vector2(screenPosition + ((wide + spaceBetweenProfileImages) * i), 0);

            if (side == "right")
            {
                float value = i == pageCount - 1 ? 1.4f : 0.7f;
                introImages[i].localScale = Vector3.Lerp(
                    introImages[i].localScale,
                    new Vector3(value, value, value),
                    Time.deltaTime * 5);
            }
            else
            {
                float value = i == pageCount ? 1.4f : 0.7f;
                introImages[i].localScale = Vector3.Lerp(
                    introImages[i].localScale,
                    new Vector3(value, value, value),
                    Time.deltaTime * 5);
            }
        }
    }
Beispiel #21
0
    void Update()
    {
        // Skip when game is paused
        if (Time.timeScale == 0.0f)
        {
            return;
        }

        Touch?latchedTouch = null;

        // If already latched to finger, determine whether still latched
        foreach (Touch touch in Input.touches)
        {
            if (touch.fingerId == _latchedFingerId && _touchZone.Contains(touch.position))
            {
                latchedTouch = touch;
                break;
            }
        }

        // If not latched to finger...
        if (latchedTouch == null)
        {
            // Release latch of this user interface?
            if (_latchedFingerId != -1)
            {
                ResetJoystick();
            }

            // Search for finger to latch with
            foreach (Touch touch in Input.touches)
            {
                // Should finger latch to user interface?
                if (_touchZone.Contains(touch.position))
                {
                    // Latched to touch!
                    _latchedFingerId = touch.fingerId;
                    latchedTouch     = touch;

                    // Initial touch position
                    _touchDownPosition = TransformToPosition(touch.position);
                    position           = _touchDownPosition;

                    // Has broken threshold if threshold is not being used!
                    _brokenThreshold = motionThreshold == 0.0f;
                    // Has threshold already been broken?
                    if (!_brokenThreshold)
                    {
                        // Already broken if both axis have exceeded threshold (diagonal) ?
                        if ((Mathf.Abs(position.x) > motionThreshold && Mathf.Abs(position.y) > motionThreshold) ||
                            (Mathf.Abs(position.x) < 0.45f && Mathf.Abs(position.y) < 0.45f))
                        {
                            _brokenThreshold = true;
                        }
                        else
                        {
                            if (Mathf.Abs(position.x) < motionThreshold)
                            {
                                position.x = 0.0f;
                            }
                            if (Mathf.Abs(position.y) < motionThreshold)
                            {
                                position.y = 0.0f;
                            }
                        }
                    }
                    break;
                }
            }
        }

        // If latched, update position!
        if (latchedTouch != null)
        {
            // Calculate new position
            previousPosition = position;
            position         = TransformToPosition(latchedTouch.Value.position);

            if (!_brokenThreshold)
            {
                // Restore previous position if initial motion threshold constraint not broken
                if (Vector2.Distance(previousPosition, position) > motionThreshold)
                {
                    _brokenThreshold = true;
                }
                else
                {
                    position = previousPosition;
                }
            }
        }
    }
Beispiel #22
0
    // Update is called once per frame
    void Update()
    {
        foreach (Touch myTouch in Input.touches)
        {
            if (myTouch.phase == TouchPhase.Began)
            {
                sticks myStick = determineStick(myTouch);
                if (myStick == sticks.moveStick)
                {
                    //storedTouches.Add(myTouch);
                    Debug.Log("MoveStick Touch Stored");
                    moveTouch = myTouch;
                }
                else if (myStick == sticks.lookStick)
                {
                    //storedTouches.Add(myTouch);
                    Debug.Log("lookStick Touch Stored");
                    lookTouch = myTouch;
                }
            }
            else if (myTouch.phase == TouchPhase.Moved)
            {
                if (moveTouch != null && myTouch.fingerId == ((Touch)moveTouch).fingerId)
                {
                    Debug.Log("MoveTouch has moved");
                    Vector2 myDelta  = myTouch.deltaPosition;
                    Text    debugger = GameObject.Find("Debugger").GetComponent <Text>();
                    debugger.text = "X: " + myDelta.x + "   y: " + myDelta.y;
                    // reference myTouch NOT moveTouch or lookTouch because their values are not updated
                }
                else if (lookTouch != null && myTouch.fingerId == ((Touch)lookTouch).fingerId)
                {
                    Debug.Log("LookTouch has moved");
                    Transform tmpTransform = player.GetComponent <Transform>();
                    Vector2   myDelta      = myTouch.deltaPosition;
                    //Debug.Log("X:  " + myDelta.x + "   y: " + myDelta.y);
                    Text debugger = GameObject.Find("Debugger").GetComponent <Text>();
                    debugger.text = "X: " + myDelta.x + "   y: " + myDelta.y;
                    //player.GetComponent<Transform>().Rotate(myDelta.x, myDelta.y, 0);
                }
            }
            else if (myTouch.phase == TouchPhase.Ended)
            {
                if (moveTouch != null && myTouch.fingerId == ((Touch)moveTouch).fingerId)
                {
                    Debug.Log("moveStick Touch removed");
                    moveTouch = null;
                }
                else if (lookTouch != null && myTouch.fingerId == ((Touch)lookTouch).fingerId)
                {
                    Debug.Log("lookStick Touch removed");
                    lookTouch = null;
                }

                /*
                 * for(int i = 0; i < storedTouches.Count; i++)
                 * {
                 *  if (storedTouches[i].fingerId == myTouch.fingerId)
                 *  {
                 *      storedTouches.RemoveAt(i);
                 *      i = storedTouches.Count;
                 *      //Debug.Log("touch Removed from storage");
                 *  }
                 * } */
            }
        }

        /*
         * This code will not work because the touch is being stored
         * by value and not by reference so the data is never updated.
         * Possible fixes is moving back into all touch loop and ID'ing
         * if a touch has the same fingerID OR updating based on finger ID
         * and doing the translate here
         *
         * I'm just going to do it all above
         *
         * if(moveTouch != null)
         * {
         *  if(((Touch)moveTouch).phase == TouchPhase.Moved)
         *  {
         *      Debug.Log("move has moved");
         *  }
         * }
         *
         * if(lookTouch != null)
         * {
         *  if (((Touch)lookTouch).phase == TouchPhase.Moved)
         *  {
         *      Debug.Log("look has moved");
         *  }
         * }
         */
    }
Beispiel #23
0
 public void ClearTouch()
 {
     touch1 = null;
     touch2 = null;
 }
Beispiel #24
0
 public void SetTouch(Touch t1, Touch t2)
 {
     touch1 = t1;
     touch2 = t2;
 }
Beispiel #25
0
    public void Update()
    {
        if (!GameManager.Instance.IsPlaying)
        {
            return;
        }

        //Detect tap input
        //Sorry for the odd preprocessors, blame unity for not allowing touch simulation in the editor
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            {
                Vector2 position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
#else
        Touch[] touches = Input.touches;
        if (Input.touchCount > 0)
        {
            Touch?touch = null;
            foreach (Touch t in touches)
            {
                //Check for a valid touch
                if (t.phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(t.fingerId))
                {
                    touch = t;
                    break;
                }
            }

            if (touch.HasValue)
            {
                Vector3 position = Camera.main.ScreenToWorldPoint(touch.Value.position);
#endif
                float invertScalar = Config.Invert ? -1 : 1;
                float angle        = 0;

                //Pole angle based controls
                if (Config.ControlScheme == ControlScheme.Angle)
                {
                    //Calculate the angle between the click position and the top of the pole
                    Vector2 top = new Vector2(0, 1);
                    if (ActualRotation > 65)
                    {
                        top = Quaternion.AngleAxis(-15, Vector3.forward) * top;
                    }
                    else if (ActualRotation < -65)
                    {
                        top = Quaternion.AngleAxis(15, Vector3.forward) * top;
                    }

                    Vector2 angleVec = transform.TransformPoint(top);
                    angle = Vector2.Angle(angleVec, position) * Mathf.Sign(position.x * angleVec.y - position.y * angleVec.x);

#if UNITY_EDITOR
                    Debug.DrawLine(Vector3.zero, angleVec * 20, Color.red, 0.5f);
#endif
                }
                //Screen based controls
                else
                {
                    if (position.x > 0)
                    {
                        angle = 1;
                    }
                    else
                    {
                        angle = -1;
                    }
                }

                //Touch was to the left of the pole
                if (angle > 0)
                {
                    //Debug.Log("Left touch");
                    AddForce(1200 * invertScalar);
                }
                //Touch was to the right of the pole
                else
                {
                    //Debug.Log("Right touch");
                    AddForce(-1200 * invertScalar);
                }

                tapSound.Play();

                if (visualFeedback)
                {
                    CreateTouchCircle(position);
                }
            }
        }

        //Update gravity
        gravTimer += Time.deltaTime;
        if (gravTimer > GRAVITY_INCREMENT_TIME_INTERVAL)
        {
            gravTimer -= GRAVITY_INCREMENT_TIME_INTERVAL;
            gravScale += GRAVITY_INCREMENT_AMOUNT;
            GameManager.Instance.MenuManager.SetGravityScaleUI(gravScale);
        }

        if (visualFeedback)
        {
            UpdateCircles();
        }

        //Interpolate rotations between frames
        float alpha = (Time.time - Time.fixedTime) / Time.fixedDeltaTime;
        ActualRotation     = Mathf.LerpAngle(prevRotation, targetRotation, alpha);
        transform.rotation = Quaternion.Euler(0.0f, 0.0f, ActualRotation);
    }
Beispiel #26
0
        /// <summary>
        /// 最大化時以外なら、マウスドラッグによってウィンドウを移動
        /// </summary>
        void DragMove()
        {
            if (uniWin == null)
            {
                return;
            }

            // ドラッグでの移動が無効化されていた場合
            if (!enableDragMove)
            {
                isDragging = false;
                return;
            }

            //Debug.Log(Input.touchCount);

            // 最大化状態ならウィンドウ移動は行わないようにする
            bool isFullScreen = uniWin.IsMaximized;

            // フルスクリーンならウィンドウ移動は行わない
#if !UNITY_EDITOR
            //  エディタだと true になってしまうようなので、エディタ以外でのみ確認
            if (Screen.fullScreen)
            {
                isFullScreen = true;
            }
#endif
            if (isFullScreen)
            {
                isDragging = false;
                return;
            }

            // マウスによるドラッグ開始の判定
            if (Input.GetMouseButtonDown(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2))
            {
                // EventSystemで反応した場合、UI上としてドラッグ対象外
                if (!EventSystem.current.IsPointerOverGameObject())
                {
                    dragStartedPosition = Input.mousePosition;
                    isDragging          = true;
                    wasUsingMouse       = true;
                    //Debug.Log("Start mouse dragging");
                }
            }

            bool touching = (activeFingerId >= 0);

            int targetTouchIndex = -1;
            if (activeFingerId < 0)
            {
                // まだ追跡中の指が無かった場合、Beganとなるタッチがあればそれを追跡候補に挙げる
                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (Input.GetTouch(i).phase == TouchPhase.Began)
                    {
                        //Debug.Log("Touch began");
                        //targetTouchIndex = i;
                        firstTouch = Input.GetTouch(i);     // まだドラッグ開始とはせず、透過画素判定に回す。
                        break;
                    }
                }
            }
            else
            {
                // 追跡中の指がある場合
                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (activeFingerId == Input.GetTouch(i).fingerId)
                    {
                        targetTouchIndex = i;
                        break;
                    }
                }
            }

            // タッチによるドラッグ開始の判定
            if (targetTouchIndex >= 0 && !isDragging)
            {
                dragStartedPosition = Input.GetTouch(targetTouchIndex).position;
                //activeFingerId = Input.GetTouch(targetTouchIndex).fingerId;
                isDragging    = true;
                wasUsingMouse = false;
                //Debug.Log("Start touch dragging");
            }

            // ドラッグ終了の判定
            if (wasUsingMouse && !Input.GetMouseButton(0))
            {
                //Debug.Log("End mouse dragging");
                activeFingerId = -1;
                isDragging     = false;
            }
            else if (!wasUsingMouse && targetTouchIndex < 0)
            {
                //if (touching) Debug.Log("End touch dragging");
                activeFingerId = -1;
                isDragging     = false;
            }

            // ドラッグ中ならば、ウィンドウ位置を更新
            if (isDragging)
            {
                Vector2 mousePos;
                if (wasUsingMouse)
                {
                    mousePos = Input.mousePosition;
                    Vector2 delta = mousePos - dragStartedPosition;
                    delta.y = -delta.y;                            // Y座標は反転

                    Vector2 windowPosition = uniWin.GetPosition(); // 現在のウィンドウ位置を取得
                    windowPosition += delta;                       // ウィンドウ位置に上下左右移動分を加える
                    uniWin.SetPosition(windowPosition);            // ウィンドウ位置を設定
                }
                else
                {
                    Touch   touch = Input.GetTouch(targetTouchIndex);
                    Vector2 delta = touch.position - dragStartedPosition;
                    delta.y = -delta.y;                            // Y座標は反転

                    Vector2 windowPosition = uniWin.GetPosition(); // 現在のウィンドウ位置を取得
                    windowPosition += delta;                       // ウィンドウ位置に上下左右移動分を加える
                    uniWin.SetPosition(windowPosition);            // ウィンドウ位置を設定
                }
            }
        }
Beispiel #27
0
    public void Update()
    {
#if !UNITY_FLASH
        padTouch.enabled = pad.enabled = _Loader.controls == Contr.mouse;
        bool keys = _Loader.controls == Contr.keys;

        left.enabled  = right.enabled = keys;
        nitro.enabled = pl.nitro > 0;

        //Log("Android Mouse " + mouse + " Taps" + Input.touchCount);
        mouse = Vector3.Lerp(mouse, Vector3.zero, Time.deltaTime * 10);
        bool padDown = false;
        if (_Loader.accelometer)
        {
            mouse = new Vector2(Input.acceleration.x, 0) * 2;
        }
        else if (_Loader.enableMouse)
        {
            foreach (var touch in Input.touches)
            {
                Vector3 mpos = touch.position;
                Vector3 pp   = pad.inversePos;
                pp.x *= Screen.width;
                pp.y *= Screen.height;
                if (mpos.x < Screen.width / 2f && pp.x < Screen.width / 2f || mpos.x > Screen.width / 2f && pp.x > Screen.width / 2f)
                {
                    Vector3 mouseTmp = (pp - mpos) / (pad.size.x / 2f) * (pl.secondPlayer ? 1 : -1);
                    mouseTmp.x = Mathf.Clamp(mouseTmp.x, -1, 1);
                    mouseTmp.y = Mathf.Clamp(mouseTmp.y, -1, 1);
                    if (!splitScreen || mpos.y > Screen.height / 2f && pl.secondPlayer || mpos.y < Screen.height / 2f && !pl.secondPlayer)
                    {
                        mouse = mouseTmp;
                        padTouch.screenPos = mpos;
                        padDown            = true;
                    }
                }
            }
#if UNITY_ANDROID
            if (AndroidInput.secondaryTouchEnabled && AndroidInput.touchCountSecondary > 0)
            {
                Vector2 p = AndroidInput.GetSecondaryTouch(0).position;
                p.x  /= AndroidInput.secondaryTouchWidth;
                p.x  -= .5f;
                p.x   = Mathf.Clamp(p.x, -1, 1) * 2;
                mouse = p;
            }
#endif
            if (!padDown)
            {
                padTouch.transform.position = pad.transform.position;
            }
        }
        if (_Game.editControls)
        {
            if (Input.touchCount == 1)
            {
                foreach (KeyHudBool a in dict.Values)
                {
                    Touch?touch = HitTest(a);
                    if (touch != null)
                    {
                        last = a;
                        Vector2 mpos = touch.Value.position;
                        mpos = pl.hud.camera.ScreenToViewportPoint(mpos);
                        a.guitext.inversePos = mpos;
                        a.posx = mpos.x;
                        a.posy = mpos.y;
                    }
                }
            }
            else if (last != null)
            {
                last.scale += GetDoubleTouch() * 0.01f;
                last.scale  = Mathf.Max(.7f, last.scale);
                last.UpdateScale();
            }
        }
        if (!_Game.editControls)
        {
            if (keys && !splitScreen)
            {
                foreach (KeyHudBool a in dict.Values)
                {
                    a.hitTest = null;
                }
                foreach (Touch b in touches)
                {
                    Vector2 pos = b.position;
                    pos.x /= Screen.width;
                    pos.y /= Screen.height;
                    KeyHudBool d = dict.Values.Where(a => a.guitext.enabled).OrderBy(a => Vector2.Distance(pos, a.guitext.pos)).FirstOrDefault();
                    //print(d.guitext.name);
                    d.hitTest = b;
                }
            }
            else
            {
                foreach (KeyHudBool a in dict.Values)
                {
                    a.hitTest = HitTest(a);
                }
            }

            foreach (KeyHudBool a in dict.Values)
            {
                TouchPhase ph = a.hitTest.HasValue ? a.hitTest.Value.phase : ((TouchPhase)221);
                a.hold = ph == TouchPhase.Stationary || ph == TouchPhase.Moved;
                a.up   = ph == TouchPhase.Canceled || ph == TouchPhase.Ended;
                a.down = ph == TouchPhase.Began;
                if (!splitScreen)
                {
                    a.hudColor = padDown && a.guitext == pad || a.hold ? new Color(.5f, .5f, .5f, .5f) : new Color(0, 0, 0, 0);
                }
            }
        }
#endif
    }
Beispiel #28
0
        void Update()
        {
            foreach (InputHandler handler in inputHandlers)
            {
                handler.inputEvent.keys = Input.inputString;                 // Use InputType.AnyKey to see when this changes

                switch (handler.type)
                {
                case InputType.AnyKey:
                    if (Input.anyKeyDown)
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                case InputType.KeyUp:
                    if (Input.GetKeyUp(handler.keyCode))
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                case InputType.KeyDown:
                    if (Input.GetKeyDown(handler.keyCode))
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                case InputType.KeyHeld:
                    if (Input.GetKey(handler.keyCode))
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                case InputType.ButtonUp:
                    if (Input.GetButtonUp(handler.buttonName))
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                case InputType.ButtonDown:
                    if (Input.GetButtonDown(handler.buttonName))
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                case InputType.ButtonHeld:
                    if (Input.GetButton(handler.buttonName))
                    {
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                // Detects a SINGLE touch going down - if multitouch, only initial touch is considered
                case InputType.TouchDown:
                    if (lastTouch == null && Input.touchCount > 0)
                    {
                        handler.inputEvent.touch = Input.GetTouch(0);
                        handler.callback.Invoke(handler.inputEvent);
                    }
                    break;

                // Detects a SINGLE touch coming up - if multitouch, only initial touch is considered
                case InputType.TouchUp:
                    if (lastTouch != null)
                    {
                        break;
                    }

                    foreach (Touch touch in Input.touches)
                    {
                        if (touch.fingerId == ((Touch)lastTouch).fingerId)
                        {
                            handler.inputEvent.touch = touch;
                            handler.callback.Invoke(handler.inputEvent);
                            break;
                        }
                    }
                    break;

                // Detects a SINGLE touch held - if multitouch, it's the oldest touch
                // Fires on first touch and all subsequent touches by same finger
                case InputType.TouchHeld:
                    if (lastTouch == null)
                    {
                        if (Input.touchCount > 0)
                        {                                 // Fire first touch found
                            handler.inputEvent.touch = Input.GetTouch(0);
                            handler.callback.Invoke(handler.inputEvent);
                        }
                    }
                    else
                    {                             // Find last touch
                        foreach (Touch touch in Input.touches)
                        {
                            if (touch.fingerId == ((Touch)lastTouch).fingerId)
                            {
                                handler.inputEvent.touch = touch;
                                handler.callback.Invoke(handler.inputEvent);
                                break;
                            }
                        }
                    }
                    break;

                case InputType.Axis:
                    float axis1 = handler.axisOptions.raw ? Input.GetAxisRaw(handler.axisName1) : Input.GetAxis(handler.axisName1);
                    if (handler.axisOptions.invertAxis1)
                    {
                        axis1 = -axis1;
                    }
                    if (handler.axisOptions.noRepeats && handler.inputEvent.axis.x != axis1)
                    {
                        break;
                    }
                    if (handler.axisOptions.noZeros && axis1 == 0 && handler.inputEvent.axis.y == 0)
                    {
                        break;
                    }

                    handler.inputEvent.axis.Set(axis1, 0);
                    handler.callback.Invoke(handler.inputEvent);
                    break;

                case InputType.DoubleAxis:
                    float daxis1 = handler.axisOptions.raw ? Input.GetAxisRaw(handler.axisName1) : Input.GetAxis(handler.axisName1);
                    float daxis2 = handler.axisOptions.raw ? Input.GetAxisRaw(handler.axisName2) : Input.GetAxis(handler.axisName2);
                    if (handler.axisOptions.invertAxis1)
                    {
                        daxis1 = -daxis1;
                    }
                    if (handler.axisOptions.invertAxis2)
                    {
                        daxis2 = -daxis2;
                    }
                    if (handler.axisOptions.noDiagonals)
                    {
                        if (Mathf.Abs(daxis1) > Mathf.Abs(daxis2))
                        {
                            daxis2 = 0;
                        }
                        else
                        {
                            daxis1 = 0;
                        }
                    }

                    if (handler.axisOptions.noRepeats && (handler.inputEvent.axis.x != daxis1 || handler.inputEvent.axis.y != daxis2))
                    {
                        break;
                    }
                    if (handler.axisOptions.noZeros && daxis1 == 0 && daxis2 == 0)
                    {
                        break;
                    }

                    handler.inputEvent.axis.Set(daxis1, daxis2);
                    handler.callback.Invoke(handler.inputEvent);
                    break;
                }
            }

            // Not sure if this always works with multi-touch; will the held touch at index 0 always be index 0?
            lastTouch = (Input.touchCount > 0 ? Input.GetTouch(0) : (Touch?)null);
        }
    public void Update()
    {
        if (!pl)
        {
            return;
        }

        padTouch.enabled       = pad.enabled = Loader.controls == Contr.mouse;
        rocketLauncher.enabled = _Player.curWeapon.bullets > 0;
        bool keys = Loader.controls == Contr.keys;

        left.enabled = right.enabled = keys;
        //nitro.enabled = pl.nitro > 0;

        //Log("Android Mouse " + mouse + " Taps" + Input.touchCount);
        mouse = Vector3.Lerp(mouse, Vector3.zero, Time.deltaTime * 10);
        bool padDown = false;

        if (Loader.controls == Contr.acel)
        {
            mouse = new Vector2(Mathf.Clamp(Input.acceleration.x * 2, -1, 1), 0);
        }
        else if (Loader.controls == Contr.mouse)
        {
            foreach (var touch in Input.touches)
            {
                Vector3 mpos = touch.position;
                Vector3 pp   = pad.inversePos;
                pp.x *= Screen.width;
                pp.y *= Screen.height;
                if (mpos.x < Screen.width / 2f && pp.x < Screen.width / 2f || mpos.x > Screen.width / 2f && pp.x > Screen.width / 2f)
                {
                    Vector3 mouseTmp = (pp - mpos) / (pad.size.x / 2f) * (InputManager.secondPlayer ? 1 : -1);
                    mouseTmp.x = Mathf.Clamp(mouseTmp.x, -1, 1);
                    mouseTmp.y = Mathf.Clamp(mouseTmp.y, -1, 1);
                    if (!InputManager.splitScreen || mpos.y > Screen.height / 2f && InputManager.secondPlayer || mpos.y < Screen.height / 2f && !InputManager.secondPlayer)
                    {
                        mouse = mouseTmp;
                        padTouch.screenPos = mpos;
                        padDown            = true;
                    }
                }
            }
            #if UNITY_ANDROID
            if (AndroidInput.secondaryTouchEnabled && AndroidInput.touchCountSecondary > 0)
            {
                Vector2 p = AndroidInput.GetSecondaryTouch(0).position;
                p.x  /= AndroidInput.secondaryTouchWidth;
                p.x  -= .5f;
                p.x   = Mathf.Clamp(p.x * 2, -1, 1);
                mouse = p;
            }
#endif
            if (!padDown)
            {
                padTouch.tr.position = pad.tr.position;
            }
        }
        if (_Game.editControls)
        {
            if (Input.touchCount == 1)
            {
                foreach (KeyHudBool a in dict.Values)
                {
                    Touch?touch = HitTest(a);
                    if (touch != null)
                    {
                        last = a;
                        Vector2 mpos = touch.Value.position;
                        mpos = camera.ScreenToViewportPoint(mpos);
                        a.archor.inversePos = mpos;
                        a.posx = mpos.x;
                        a.posy = mpos.y;
                    }
                }
            }
            else if (last != null)
            {
                last.scale += GetDoubleTouch() * 0.01f;
                last.scale  = Mathf.Max(.7f, last.scale);
                last.UpdateScale();
            }
        }
        if (!_Game.editControls)
        {
            if (keys && !InputManager.splitScreen)
            {
                foreach (KeyHudBool a in dict.Values)
                {
                    a.hitTest = null;
                }
                foreach (Touch b in touches)
                {
                    Vector2 pos = b.position;
                    pos.x /= Screen.width;
                    pos.y /= Screen.height;
                    KeyHudBool d = FirstOrDefault(pos);
                    //print(d.guitext.name);
                    if (d != null)
                    {
                        d.hitTest = b;
                    }
                }
            }
            else
            {
                foreach (KeyHudBool a in dict.Values)
                {
                    a.hitTest = HitTest(a);
                }
            }

            foreach (KeyHudBool a in dict.Values)
            {
                TouchPhase ph = a.hitTest.HasValue ? a.hitTest.Value.phase : ((TouchPhase)221);
                a.hold = ph == TouchPhase.Stationary || ph == TouchPhase.Moved;
                a.up   = ph == TouchPhase.Canceled || ph == TouchPhase.Ended;
                a.down = ph == TouchPhase.Began;
                if (!InputManager.splitScreen)
                {
                    a.hudColor = padDown && a.archor == pad || a.hold ? Color.white : Color.white / 2f;
                }
            }
        }
    }
Beispiel #30
0
        /// <summary>
        /// Process touch input - find and associate touches with correct input
        /// </summary>
        protected virtual void ProcessTouches()
        {
            // Clear touches
            m_MovementTouch = null;
            m_FiringTouch   = null;
            m_StoppedMoving = false;
            m_StoppedFiring = false;

            // Update input touch IDs
            for (int i = 0; i < Input.touchCount; ++i)
            {
                Touch touch = Input.GetTouch(i);

                switch (touch.phase)
                {
                case TouchPhase.Began:
                    if (IsValidMovementTouch(touch))
                    {
                        m_MovementTouchId = touch.fingerId;
                        m_MovementTouch   = touch;
                        m_PadCenter       = touch.position;
                    }
                    else if (IsValidFireTouch(touch) && touch.fingerId != m_MovementTouchId)
                    {
                        m_FiringTouchId = touch.fingerId;
                        m_FiringTouch   = touch;
                    }
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    // Look for this touch
                    if (touch.fingerId == m_FiringTouchId)
                    {
                        m_FiringTouchId = -1;
                        m_FiringTouch   = null;
                        m_StoppedFiring = true;
                    }

                    if (touch.fingerId == m_MovementTouchId)
                    {
                        m_MovementTouchId = -1;
                        m_MovementTouch   = null;
                        m_StoppedMoving   = true;
                    }
                    break;

                case TouchPhase.Moved:
                case TouchPhase.Stationary:
                    // Look for this touch
                    if (touch.fingerId == m_FiringTouchId)
                    {
                        m_FiringTouch = touch;
                    }

                    if (touch.fingerId == m_MovementTouchId)
                    {
                        m_MovementTouch = touch;
                    }
                    break;
                }
            }
        }
Beispiel #31
0
    /// <summary>
    /// Decides on current touch phase and classification (single or multiple touches)
    /// </summary>
    void UpdateTouchClassification() {
        singleTouchEnded = false;

        foreach (Touch touch in Input.touches) {
            switch (touch.phase) {
                case TouchPhase.Began:
                    if (singleTouch == null && multiTouches.Count == 0) {
                        singleTouch = touch;
                    } else {
                        if (singleTouch != null) {
                            multiTouches.Add(singleTouch.Value);
                        }
                        multiTouches.Add(touch);
                        
                        singleTouch = null;
                    }
                    break;
                case TouchPhase.Ended:
                case TouchPhase.Canceled:
                    // not passing last touch makes sprites touch actions work
                    if (singleTouch != null) {
                        singleTouch = null;
                    } else {
                        multiTouches.Clear();
                    }
                    singleTouchEnded = true;
                    break;
                default:
                    if (singleTouch != null && singleTouch.Value.fingerId == touch.fingerId) {
                        singleTouch = touch;
                    } else {
                        for (int i = 0; i < multiTouches.Count; ++i) {
                            var multiTouch = multiTouches[i];
                            if (multiTouch.fingerId == touch.fingerId) {
                                multiTouches[i] = touch;
                            }
                        }
                    }
                    break;
            }
        }
    }
Beispiel #32
0
        public void Update()
        {
            FirstDownThisFrame = FirstMoveThisFrame = FirstUpThisFrame = false;
            SecondDownThisFrame = SecondMoveThisFrame = SecondUpThisFrame = false;

            foreach(var touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Began)
                {
                    if (FingerOne == null)
                    {
                        FirstDownThisFrame = true;
                        FingerOne = touch;
                    }
                    else
                    {
                        SecondDownThisFrame = true;
                        FingerTwo = touch;
                    }
                }
                else
                {
                    bool isFirst = (FingerOne != null && touch.fingerId == FingerOne.Value.fingerId);
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
                    {
                        if (isFirst)
                        {
                            FingerOne = touch;
                            FirstMoveThisFrame = true;
                        }
                        else
                        {
                            FingerTwo = touch;
                            SecondMoveThisFrame = true;
                        }
                    }

                    if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                    {
                        if (isFirst)
                        {
                            FirstUpThisFrame = true;
                            FingerOne = null;
                        }
                        else
                        {
                            SecondUpThisFrame = true;
                            FingerTwo = null;
                        }
                    }
                }
            }
        }