Example #1
0
    void OnSwipe(SwipeInfo sw)
    {
        //position the projectile object at the start point of the swipe
        Vector3 p=Camera.main.ScreenToWorldPoint(new Vector3(sw.startPoint.x, sw.startPoint.y, 35));
        projectileObject.position=p;

        //clear the projectile current velocity before apply a new force in the swipe direction, take account of the swipe speed
        body.velocity=new Vector3(0, 0, 0);
        body.AddForce(new Vector3(sw.direction.x, 0, sw.direction.y) * sw.speed*0.0035f);

        //show the swipe info
        string labelText="Swipe Detected\n\n";
        labelText+="direction: "+sw.direction+"\n";
        labelText+="angle: "+sw.angle.ToString("f1")+"\n";
        labelText+="speed: "+sw.speed.ToString("f1")+"\n";
        label.text=labelText;

        //if the label is previous cleared, re-initiate the coroutine to clear it
        if(labelTimer<0){
            StartCoroutine(ClearLabel());
        }
        //else just extend the timer
        else labelTimer=5;

        StartCoroutine(ShowSwipeIndicator(sw));
    }
Example #2
0
    //when a valide swipe is confirm
    void OnSwipe(SwipeInfo sw)
    {
        Ray ray = Camera.main.ScreenPointToRay(sw.startPoint);
        RaycastHit hit;
        //use raycast at the cursor position to detect the object
        if(Physics.Raycast(ray, out hit, Mathf.Infinity)){
            //only if the swipe is started from the source(turret) location
            if(hit.transform==source){
                //instatiate a new shootObject
                GameObject shootObjInstance=(GameObject)Instantiate(shootObject, source.TransformPoint(new Vector3(0, 0.5f, 0.5f)), Quaternion.identity);

                //if using siwpe magnitude as force determining factor
                if(forceFactor==0){
                    //calculate the force, clamp the value between 50 and 2200 so that it's not too slow or too fast that the shootObject is not visible
                    float force=Mathf.Clamp(sw.direction.magnitude*forceModifier*1.5f, 50, 2200);
                    //normalize the direction
                    sw.direction.Normalize();
                    //apply the force according to the direction
                    shootObjInstance.rigidbody.AddForce(new Vector3(sw.direction.x, sw.direction.y, 0)*force);
                }
                //if using siwpe speed as force determining factor
                else if(forceFactor==1){
                    //calculate the force, clamp the value between 50 and 2200 so that it's not too slow or too fast that the shootObject is not visible
                    float force=Mathf.Clamp(sw.speed*forceModifier*1f, 50, 2200);
                    //normalize the direction
                    sw.direction.Normalize();
                    //apply the force according to the direction
                    shootObjInstance.rigidbody.AddForce(new Vector3(sw.direction.x, sw.direction.y, 0)*force);
                }

                //make sure the shootObject is destroy after 3 second
                Destroy(shootObjInstance, 3);
            }
        }
    }
Example #3
0
    void Swiping(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        Vector2   swipeDir = endPos - startPos;
        SwipeInfo sw       = new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);

        IT_Gesture.Swiping(sw);
    }
 //*****************************************************************************//
 //special event swipe/pinch/rotate
 public static void SwipeStart(SwipeInfo sw)
 {
     if (onSwipeStartE != null)
     {
         onSwipeStartE(sw);
     }
 }
    void GetSwipe(SwipeInfo info)
    {
        pivotObj.transform.rotation = defaultRot;
        float length = Vector2.Distance(info.SwipeStartPos, info.SwipeEndPos);

        if (info.isEnd || length < lastLength || (lastLength != 0 && lastSwipeDir != info.SwipeDirection))
        {
            defaultRot = pivotObj.transform.rotation;
            lastLength = 0;
        }
        else
        {
            lastLength = length;
        }

        lastSwipeDir = info.SwipeDirection;

        float multiplier = 1f;

        if (Vector2.SignedAngle(info.SwipeStartPos - centre, info.SwipeEndPos - centre) < 0)
        {
            multiplier *= -1;
        }

        pivotObj.transform.Rotate(Vector3.forward, length * rotationSpeed * multiplier);
    }
 public static void Swiping(SwipeInfo sw)
 {
     if (onSwipingE != null)
     {
         onSwipingE(sw);
     }
 }
Example #7
0
    private void SwipeEnd(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        if (onlyFireWhenLiftCursor)
        {
            if (!isMouse)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    Touch touch = Input.touches[i];
                    if (touch.fingerId == index)
                    {
                        return;
                    }
                }
            }
            else if (mouseIndex.Contains(index) || Time.realtimeSinceStartup - timeStartSwipe > maxSwipeDuration)
            {
                return;
            }
        }
        Vector2   dir = endPos - startPos;
        SwipeInfo sw  = new SwipeInfo(startPos, endPos, dir, timeStartSwipe, index, isMouse);

        IT_Gesture.SwipeEnd(sw);
        if (!(dir.magnitude < minDistance * IT_Gesture.GetDPIFactor()) && !(Time.time - lastSwipeTime < minDurationBetweenSwipe))
        {
            lastSwipeTime = Time.time;
            IT_Gesture.Swipe(sw);
        }
    }
 public static void SwipeEnd(SwipeInfo sw)
 {
     if (onSwipeEndE != null)
     {
         onSwipeEndE(sw);
     }
 }
Example #9
0
    public void testFlick(SwipeInfo swipe)
    {
        float swipeFast = swipe.duration;
        //Get start and end swipe points for use later
        Vector3 start = new Vector3(swipe.startPoint.x, swipe.startPoint.y, spawnPosition.z);
        Vector3 end   = new Vector3(swipe.endPoint.x, swipe.endPoint.y, (spawnPosition.z + speedMultiplier));

        float changeY = swipe.startPoint.y - swipe.endPoint.y;
        float changeX = swipe.endPoint.x - swipe.endPoint.x;
        //Need to add more versatility here to manage distance based on swipe length
        float changeZ = transform.position.z + speedMultiplier;

        //Get local position vectors that correspond to start/end swipe points
        Vector3 selfStart = transform.position;
        //Vector3 selfEnd =
        //end = Camera.main.ScreenToWorldPoint(end);
//        Vector3 ray = end - start;
        //Ray point = Camera.main.ScreenPointToRay(ray);
        //Debug.DrawLine(start, end, Color.blue, 20f);
        //Debug.DrawRay(point.origin, point.direction*20, Color.red, 20f);
        //Vector3 cameraToSpawn = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, (Camera.main.transform.position.z + spawnPosition.z));
        //spawnPosition = cameraToSpawn;
        //GameObject seed = Instantiate(seedPrefab, spawnPosition, Camera.main.transform.rotation) as GameObject;
        //seed.GetComponent<Rigidbody>().AddForce(ray, ForceMode.Impulse);
    }
Example #10
0
 public static void Swipe(SwipeInfo sw)
 {
     if (IT_Gesture.onSwipeE != null)
     {
         IT_Gesture.onSwipeE(sw);
     }
 }
Example #11
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            m_SwipeInfo = new SwipeInfo(RectTransform.position);
            m_CanvasGroup.blocksRaycasts = false;

            m_InitialPosition         = RectTransform.position;
            m_HandleGroupInitialWidth = m_HandleGroupRectTransform.rect.width;
        }
Example #12
0
 public static void Swipe(SwipeInfo sw)
 {
     Debug.Log("In Gesture.Swipe - handler: " + (onSwipeE != null));
     if (onSwipeE != null)
     {
         onSwipeE(sw);
     }
 }
Example #13
0
 public void Defense(SwipeInfo swipe)
 {
     Debug.Log("DEFENSE");
     shield.SetActive(true);
     this.boxColl.enabled = false;
     StopAllCoroutines();
     StartCoroutine(WaitToDefense(1.0f));
 }
Example #14
0
 //special
 public static void Swipe(SwipeInfo sw)
 {
     //Debug.Log("swipe start at "+"   "+pos);
     if (onSwipeE != null)
     {
         onSwipeE(sw);
     }
 }
Example #15
0
    private void DetectSwipe()
    {
        SwipeInfo swipeInfo = new SwipeInfo(fingerUpPosition, fingerDownPosition);

        if (swipeInfo.Magnitude > minSwipeDistance)
        {
            // We have detected a valid swipe
            OnSwipe(swipeInfo);
        }
    }
Example #16
0
 void GetSwipe(SwipeInfo info)
 {
     if (info.SwipeDirection == ESwipeDirection.Swipe_Left)
     {
         //currentIncoming.RotateLeft();
     }
     else if (info.SwipeDirection == ESwipeDirection.Swipe_Right)
     {
         //currentIncoming.RotateRight();
     }
 }
Example #17
0
    void SwipeEnd(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        if (onlyFireWhenLiftCursor)
        {
            if (!isMouse)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    Touch touch = Input.touches[i];
                    if (touch.fingerId == index)
                    {
                        return;
                    }
                }
            }
            else
            {
                if (mouseIndex.Contains(index))
                {
                    //Debug.Log("mouse still down");
                    return;
                }
                if (Time.realtimeSinceStartup - timeStartSwipe > maxSwipeDuration)
                {
                    //Debug.Log("too long   "+(Time.realtimeSinceStartup-timeStartSwipe));
                    return;
                }
            }
        }



        Vector2   swipeDir = endPos - startPos;
        SwipeInfo sw       = new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);

        IT_Gesture.SwipeEnd(sw);

        if ((swipeDir).magnitude < minDistance * IT_Gesture.GetDPIFactor())
        {
            //GameMessage.DisplayMessage("too short");
            return;
        }

        if (Time.time - lastSwipeTime < minDurationBetweenSwipe)
        {
            return;
        }
        lastSwipeTime = Time.time;

        IT_Gesture.Swipe(sw);

        //GameMessage.DisplayMessage("swiped");
    }
    // Once the swipe has been detected and it's ready, send the data.
    // The data sent is retrieved by the registered delegates.
    private void SendSwipeData(ESwipeDirection dir, bool hasEnded)
    {
        SwipeInfo swipeInfo = new SwipeInfo()
        {
            SwipeDirection = dir,
            SwipeStartPos  = m_touchDownPos,
            SwipeEndPos    = m_touchUpPos,
            isEnd          = hasEnded
        };

        OnSwipe(swipeInfo);
    }
Example #19
0
    //when a swipe has started, valid or not
    //if the starting position is on the source(turret), scale it up to give some visual feedback
    void OnSwipeStart(SwipeInfo sw)
    {
        Ray        ray = Camera.main.ScreenPointToRay(sw.startPoint);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            if (hit.transform == source)
            {
                source.localScale = new Vector3(2.2f, 2.2f, 2.2f);
            }
        }
    }
Example #20
0
    public void CreateFloor(SwipeInfo si)
    {
        swipeInfo = si;
        Vector2 touchStartPosition = swipeInfo.startPosition;
        int     d        = swipeInfo.direction == SwipeDirection.Right ? 1 : -1;
        Vector2 floorPos = new Vector2(touchStartPosition.x + d * swipeInfo.deltaX / 2, touchStartPosition.y);

        if (CheckLadder(floorPos))
        {
            floorPos = new Vector2(touchStartPosition.x + d * swipeInfo.deltaX / 2, touchStartPosition.y);
        }
        GameObject floor = (GameObject)Instantiate(floorPrefab, floorPos, transform.rotation);

        floor.transform.localScale = new Vector2(swipeInfo.deltaX, floor.transform.localScale.y);
    }
 public static Directions ConvertSwipeToDirection(SwipeInfo swipe)
 {
     Vector2 direction = swipe.direction;
     Vector2 normalized = (swipe.endPoint - swipe.startPoint).normalized;
     if (normalized.x > 0 && Math.Abs(normalized.y) < normalized.x)
         return Directions.Right;
     if (normalized.y > 0 && Math.Abs(normalized.x) < normalized.y)
         return Directions.Up;
     if (normalized.x < 0 && Math.Abs(normalized.y) > normalized.x)
         return Directions.Left;
     if (normalized.y < 0 && Math.Abs(normalized.x) > normalized.y)
         return Directions.Down;
     Debug.Log("Converting Swipe to Directions Failed");
     return Directions.None;
 }
Example #22
0
    void OnSwipe(SwipeInfo sw)
    {
        Debug.Log("swipe");

        //position the projectile object at the start point of the swipe
        Vector3 p = Camera.main.ScreenToWorldPoint(new Vector3(sw.startPoint.x, sw.startPoint.y, 35));

        projectileObject.position = p;

        //clear the projectile current velocity before apply a new force in the swipe direction, take account of the swipe speed
        body.velocity = new Vector3(0, 0, 0);
        float speed = Mathf.Min(sw.speed * 0.0035f / IT_Gesture.GetDPIFactor(), 15);

        //apply the DPI scaling
        sw.direction /= IT_Gesture.GetDPIFactor();
        body.AddForce(new Vector3(sw.direction.x, 0, sw.direction.y) * speed);

        //show the swipe info
        string labelText = "Swipe Detected, ";

        if (sw.isMouse)
        {
            labelText += "mouse " + sw.index.ToString() + "\n\n";
        }
        else
        {
            labelText += "finger " + sw.index.ToString() + "\n\n";
        }

        //labelText+="\n\n";
        labelText += "direction: " + sw.direction + "\n";
        labelText += "angle: " + sw.angle.ToString("f1") + "\n";
        labelText += "speed: " + sw.speed.ToString("f1") + "\n";
        label.text = labelText;

        //if the label is previous cleared, re-initiate the coroutine to clear it
        if (labelTimer < 0)
        {
            StartCoroutine(ClearLabel());
        }
        //else just extend the timer
        else
        {
            labelTimer = 5;
        }

        StartCoroutine(ShowSwipeIndicator(sw));
    }
Example #23
0
    public void flickObject(SwipeInfo swipeData)
    {
        Debug.Log("testing swipe");
        float swipeLength = swipeData.GetMagnitude();

        //Find velocity from the length as compared to the duration
        velocity = swipeLength / (swipeLength - swipeData.duration);
        //Multiply velocity times multiplier to get speed
        speed = velocity * speedMultiplier;

        speed = speed * speedLimiter;
        //speed = speed - (speed * speedLimiter);
        worldAngle = Camera.main.ScreenToWorldPoint(new Vector3(swipeData.endPoint.x, (swipeData.endPoint.y + offset), (Camera.main.nearClipPlane - offset)));

        GameObject seed = Instantiate(seedPrefab, spawnPosition, Quaternion.identity) as GameObject;
    }
Example #24
0
    void JudgeInputIsRight()
    {
        if (timeBegin > 0 && timeEnd > 0)
        {
            float timeDelta = timeEnd - timeBegin;

            Vector2 touchDelta = touchEnd - touchBegin;
            Vector2 direction  = GetDirection(ref touchDelta);
            if (direction != Vector2.zero)
            {
                if (directionFirst == Vector2.zero)
                {
                    directionFirst = direction;
                }

                var swipeInfo = new SwipeInfo {
                    touchBegin     = touchBegin,
                    direction      = direction,
                    directionFirst = directionFirst,
                    touchDelta     = touchDelta,
                    timeDelta      = timeDelta,
                    hasFreePass    = false,
                };

                if (isCancelable && directionFirst != direction)
                {
                    onSwipeCancel.Invoke();
                    Reset();
                }
                else if (Math.Max(Math.Abs(touchDelta.x), Math.Abs(touchDelta.y)) > threshold)
                {
                    onSwipeEnd.Invoke(swipeInfo);
                    Reset();
                }
                else if (isTouchDown)
                {
                    onSwipeMove.Invoke(swipeInfo);
                }
                else
                {
                    onSwipeEnd.Invoke(swipeInfo);
                    Reset();
                }
            }
        }
    }
Example #25
0
    void SwipeEnd(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        Vector2   swipeDir = endPos - startPos;
        SwipeInfo sw       = new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);

        Gesture.SwipeEnd(sw);

        if ((swipeDir).magnitude < minDistance)
        {
            //GameMessage.DisplayMessage("too short");
            return;
        }

        Gesture.Swipe(sw);

        //GameMessage.DisplayMessage("swiped");
    }
Example #26
0
    private bool CheckFloors(SwipeInfo swipeInfo, Vector2 pos)
    {
        float   ladderBlockHalfWidth = ladderBlockPrefab.renderer.bounds.size.x / 2;
        float   ladderBlockHeight    = ladderBlockPrefab.renderer.bounds.size.y;
        Vector2 pos1 = new Vector2(pos.x - ladderBlockHalfWidth, pos.y + ladderBlockHeight / 2);
        Vector2 pos2 = new Vector2(pos.x + ladderBlockHalfWidth, pos.y + ladderBlockHeight);

        Collider2D[] hits = Physics2D.OverlapAreaAll(pos1, pos2);
        foreach (Collider2D c in hits)
        {
            if (c.tag == "Floor")
            {
                return(true);
            }
        }
        return(false);
    }
Example #27
0
    //when a valide swipe is confirm
    void OnSwipe(SwipeInfo sw)
    {
        Ray        ray = Camera.main.ScreenPointToRay(sw.startPoint);
        RaycastHit hit;

        //use raycast at the cursor position to detect the object
        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            //only if the swipe is started from the source(turret) location
            if (hit.transform == source)
            {
                //instatiate a new shootObject
                GameObject shootObjInstance = (GameObject)Instantiate(shootObject, source.TransformPoint(new Vector3(0, 0.5f, 0.5f)), Quaternion.identity);

                //if using siwpe magnitude as force determining factor
                if (forceFactor == 0)
                {
                    //apply the DPI scaling
                    sw.direction /= IT_Gesture.GetDPIFactor();
                    //calculate the force, clamp the value between 50 and 2200 so that it's not too slow or too fast that the shootObject is not visible
                    float force = Mathf.Clamp(sw.direction.magnitude * forceModifier * 1.5f / IT_Gesture.GetDPIFactor(), 50, 2200);
                    //normalize the direction
                    sw.direction.Normalize();
                    //apply the force according to the direction
                    Rigidbody rigidbody = shootObjInstance.GetComponent <Rigidbody>();
                    rigidbody.AddForce(new Vector3(sw.direction.x, sw.direction.y, 0) * force);
                }
                //if using siwpe speed as force determining factor
                else if (forceFactor == 1)
                {
                    //apply the DPI scaling
                    sw.direction /= IT_Gesture.GetDPIFactor();
                    //calculate the force, clamp the value between 50 and 2200 so that it's not too slow or too fast that the shootObject is not visible
                    float force = Mathf.Clamp(sw.speed * forceModifier * 1f / IT_Gesture.GetDPIFactor(), 50, 2200);
                    //normalize the direction
                    sw.direction.Normalize();
                    //apply the force according to the direction
                    Rigidbody rigidbody = shootObjInstance.GetComponent <Rigidbody>();
                    rigidbody.AddForce(new Vector3(sw.direction.x, sw.direction.y, 0) * force);
                }

                //make sure the shootObject is destroy after 3 second
                Destroy(shootObjInstance, 3);
            }
        }
    }
Example #28
0
    private void ControlSpawner(SwipeInfo swipe)
    {
        if (handlingSwipe)
        {
            return;
        }
        handlingSwipe = true;
        switch (swipe.Direction)
        {
        case SwipeInfo.SwipeDirection.UP:
            spawning = false;
            break;

        case SwipeInfo.SwipeDirection.DOWN:
            spawning = true;
            break;
        }
    }
Example #29
0
    void SwipeEnd(Vector2 pos)
    {
        swipeState = _SwipeState.End;
        swipeDir   = pos - swipeStartPos;

        if ((swipeDir).magnitude < minDistance)
        {
            //Debug.Log("too short");
            //GameMessage.DisplayMessage("too short");
            return;
        }

        //GameMessage.DisplayMessage("swipe end "+pos);

        SwipeInfo sw = new SwipeInfo(swipeStartPos, pos, swipeDir, timeStartSwipe);

        Gesture.Swipe(sw);
    }
Example #30
0
    public void CreateLadder(SwipeInfo swipeInfo)
    {
        GameObject ladder             = (GameObject)Instantiate(ladderPrefab, transform.position, transform.rotation);
        Vector2    touchStartPosition = swipeInfo.startPosition;
        float      ladderBlockHeight  = ladderBlockPrefab.renderer.bounds.size.y;
        int        loopNum            = (int)Mathf.Ceil(swipeInfo.deltaY / ladderBlockHeight);

        for (int i = 0; i < loopNum; i++)
        {
            Vector2    ladderBlockPos = new Vector2(touchStartPosition.x, touchStartPosition.y + ladderBlockHeight * i);
            GameObject ladderBlock    = (GameObject)Instantiate(ladderBlockPrefab, ladderBlockPos, Quaternion.identity);
            ladderBlock.transform.parent = ladder.transform;
            if (CheckFloors(swipeInfo, ladderBlockPos))
            {
                break;
            }
        }
    }
Example #31
0
    private void SwipeHandler(SwipeInfo swipeInfo)
    {
        if (0.1f < (1 - (swipeInfo.startPoint.x / swipeInfo.endPoint.x)) &&
            (1 - (swipeInfo.startPoint.x / swipeInfo.endPoint.x)) < 0.9f)
        {
            if (swipeInfo.startPoint.x < swipeInfo.endPoint.x)
            {
                Debug.Log("Derecha " + swipeInfo.startPoint.x + " " + swipeInfo.endPoint.x + " " + (swipeInfo.duration));
                motor.DoMove(1, Vector2.zero);
            }
        }

        if (0.1f < (1 - (swipeInfo.endPoint.x / swipeInfo.startPoint.x)) &&
            (1 - (swipeInfo.endPoint.x / swipeInfo.startPoint.x)) < 0.9f)
        {
            if (swipeInfo.startPoint.x > swipeInfo.endPoint.x)
            {
                Debug.Log("Izquierda " + swipeInfo.startPoint.x + " " + swipeInfo.endPoint.x + " " + (swipeInfo.duration));
                motor.DoMove(-1, Vector2.zero);
            }
        }



        if (0.25f < (1 - (swipeInfo.startPoint.y / swipeInfo.endPoint.y)) &&
            (1 - (swipeInfo.startPoint.y / swipeInfo.endPoint.y)) < 0.75f)
        {
            if (swipeInfo.duration < 0.1)
            {
                // Swipe Rápido resultando en un Hop
                motor.DoJump(0.5f, swipeInfo.endPoint);
            }
            else
            {
                // Swipe Lento resultando en un Jump
                motor.DoJump(1, swipeInfo.endPoint);
            }
        }
        else
        {
            // Swipe hacia abajo resultado en un slide
            motor.DoSlide(1, Vector2.zero);
        }
    }
Example #32
0
    public override void Update()
    {
        base.Update();
        if (Input.GetMouseButtonUp(0))
        {
            swipeInfo = GetSwipeInfo();
            switch (swipeInfo.direction)
            {
            case SwipeDirection.Up:
                ladder.CreateLadder(swipeInfo);
                break;

            case SwipeDirection.Right:
            case SwipeDirection.Left:
                floor.CreateFloor(swipeInfo);
                break;
            }
        }
    }
Example #33
0
    IEnumerator ShowSwipeIndicator(SwipeInfo sw)
    {
        //position the projectile object at the start point of the swipe
        Vector3 p = Camera.main.ScreenToWorldPoint(new Vector3(sw.startPoint.x, sw.startPoint.y, 5));

        swipeIndicator.position = p;

        float t = 0;

        while (t <= 1)
        {
            p = Vector2.Lerp(sw.startPoint, sw.endPoint, t);
            p = Camera.main.ScreenToWorldPoint(new Vector3(p.x, p.y, 5));
            //Debug.Log(sw.startPoint+"  "+sw.endPoint+"   "+p);
            swipeIndicator.position = p;
            t += 0.2f;
            yield return(null);
        }
    }
Example #34
0
 void OnSwipe(SwipeInfo sw)
 {
     //Debug.Log("swipe"); :v
     if (sw.angle >= 45 && sw.angle < 135)
     {
         Debug.Log("swipe up");
     }
     else if (sw.angle >= 135 && sw.angle < 225)
     {
         Debug.Log("swipe left");
     }
     else if (sw.angle >= 225 && sw.angle < 315)
     {
         Debug.Log("swipe down");
     }
     else
     {
         Debug.Log("swipe right");
     }
 }
Example #35
0
    //    private bool useTouch = false;
    //    private bool isSwipe = false;
    //    private float swipeStartTime  = 0.0f;
    // Use this for initialization
    void Start()
    {
        if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) {
            useTouch = true;
        }
        else {
            maxTouchFingers = 1;
        }

        swipeInfo = new SwipeInfo[maxTouchFingers];
        for( int i=0; i<maxTouchFingers; ++i ) {
            swipeInfo[i] = new SwipeInfo();
            swipeInfo[i].swipe_state = SwipeState.NONE;
        }

        line = Instantiate(linerenderer, transform.position, Quaternion.identity) as LineRenderer;
        line.name = "InputHandler_Line";
    }
Example #36
0
 void OnSwipeStart(SwipeInfo sw)
 {
     if (!this.swipingFlag)
     {
         this.swipeStartPos = sw.startPoint;
         this.swipingFlag = true;
     }
 }
Example #37
0
    void OnSwiping(SwipeInfo sw)
    {
        Vector2 swipePos = this.swipeStartPos - sw.endPoint;

        if (this.swipingFlag)
        {
            this.quizImage.transform.position = this.startPos - new Vector3(swipePos.x, 0, 0);
        }
    }
Example #38
0
 //special
 public static void Swipe(SwipeInfo sw)
 {
     //Debug.Log("swipe start at "+"   "+pos);
     if(onSwipeE!=null) onSwipeE(sw);
 }
Example #39
0
    void SwipeEnd(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        if(onlyFireWhenLiftFinger){
            if(!isMouse){
                for(int i=0; i<Input.touchCount; i++){
                    Touch touch=Input.touches[i];
                    if(touch.fingerId==index){
                        return;
                    }
                }
            }
            else{
                if(mouseIndex.Contains(index)) return;
                if(Time.realtimeSinceStartup-timeStartSwipe>maxSwipeDuration) return;
            }
        }

        Vector2 swipeDir=endPos-startPos;
        SwipeInfo sw=new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);

        IT_Gesture.SwipeEnd(sw);

        if((swipeDir).magnitude<minDistance) {
            //GameMessage.DisplayMessage("too short");
            return;
        }

        IT_Gesture.Swipe(sw);

        //GameMessage.DisplayMessage("swiped");
    }
 public void OnSwiping(SwipeInfo swipe)
 {
     this._statusLabel.text = swipe.ToString();
 }
Example #41
0
 //*****************************************************************************//
 //special event swipe/pinch/rotate
 public static void SwipeStart(SwipeInfo sw)
 {
     if(onSwipeStartE!=null) onSwipeStartE(sw);
 }
 private void OnSwipe(SwipeInfo swipe)
 {
     for (int i = 0; i < this._listeners.Count; i++)
         this._listeners[i].OnSwipe(swipe, ConvertSwipeToDirection(swipe));
 }
Example #43
0
    void SwipeEnd(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        Vector2 swipeDir=endPos-startPos;
        SwipeInfo sw=new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);

        //Gesture.SwipeEnd(sw);

        if((swipeDir).magnitude<minDistance) {
            Debug.Log("too short");
            //GameMessage.DisplayMessage("too short");
            return;
        }

        //GameMessage.DisplayMessage("swipe end "+pos);

        Debug.Log("pre swipe at " + startPos);

        Gesture.Swipe(sw);

        Debug.Log("post swipe at " + startPos);
        //GameMessage.DisplayMessage("swiped");
    }
Example #44
0
 void Swiping(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
 {
     Vector2 swipeDir=endPos-startPos;
     SwipeInfo sw=new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);
     IT_Gesture.Swiping(sw);
 }
Example #45
0
        public void OnSwipe(SwipeInfo swipe, Directions direction)
        {
            if (this.Paused) return;
            //Debug.Log(DateTime.Now + " Swiped");
            if (!this.IsAlive) return;
            double rotation = 1 + Math.Abs(swipe.startPoint.x - swipe.endPoint.x) / this.RotationDivide;
            //Debug.Log(String.Format("Rotation: {0} - {1} ( {2}:{3} )", rotation, Math.Abs(swipe.startPoint.x - swipe.endPoint.x), swipe.startPoint, swipe.endPoint));

            switch (direction)
            {
                case Directions.None:
                    break;
                case Directions.Up:
                    this.Jump();
                    break;
                case Directions.Down:
                    break;
                case Directions.Left:
                    this._startRotationTargetY = this.transform.eulerAngles.y;
                    this._rotateInterval = 0;
                    this._rotationTargetY = this._startRotationTargetY - (float)rotation;
                    this._toRotate = true;
                    break;
                case Directions.Right:
                    this._startRotationTargetY = this.transform.eulerAngles.y;
                    this._rotateInterval = 0;
                    this._rotationTargetY = this._startRotationTargetY + (float)rotation;
                    this._toRotate = true;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("direction", direction, null);
            }
        }
Example #46
0
 public void OnSwiping(SwipeInfo swipe)
 {
 }
Example #47
0
    void OnSwipeEnd(SwipeInfo sw)
    {
        this.swipingFlag = false;

        if (sw.direction.x <= -this.SwipeDistance)
        {
            this.currentAnswerDirection = Direction.Left;
            this.gameObject.GetPlayMakerFsm().SendEvent("CHECK_ANSWER");

        }
        else if (sw.direction.x >= this.SwipeDistance)
        {
            this.currentAnswerDirection = Direction.Right;
            this.gameObject.GetPlayMakerFsm().SendEvent("CHECK_ANSWER");
        }
        else
        {
            this.quizImage.transform.DOMoveX(this.startPos.x, 1);
        }
    }
 public void OnSwipe(SwipeInfo swipe, Directions direction)
 {
     this._statusLabel.text = direction.ToString();
 }
Example #49
0
    void OnSwipe(SwipeInfo sw)
    {
        //Debug.Log("swipe");

        //position the projectile object at the start point of the swipe
        Vector3 p=Camera.main.ScreenToWorldPoint(new Vector3(sw.startPoint.x, sw.startPoint.y, 35));
        projectileObject.position=p;

        //clear the projectile current velocity before apply a new force in the swipe direction, take account of the swipe speed
        body.velocity=new Vector3(0, 0, 0);
        float speed=Mathf.Min(sw.speed*0.0035f/IT_Gesture.GetDPIFactor(), 15);
        //apply the DPI scaling
        sw.direction/=IT_Gesture.GetDPIFactor();
        body.AddForce(new Vector3(sw.direction.x, 0, sw.direction.y)*speed);

        //show the swipe info
        string labelText="Swipe Detected, ";
        if(sw.isMouse) labelText+="mouse "+sw.index.ToString()+"\n\n";
        else labelText+="finger "+sw.index.ToString()+"\n\n";

        //labelText+="\n\n";
        labelText+="direction: "+sw.direction+"\n";
        labelText+="angle: "+sw.angle.ToString("f1")+"\n";
        labelText+="speed: "+sw.speed.ToString("f1")+"\n";
        label.text=labelText;

        //if the label is previous cleared, re-initiate the coroutine to clear it
        if(labelTimer<0){
            StartCoroutine(ClearLabel());
        }
        //else just extend the timer
        else labelTimer=5;

        StartCoroutine(ShowSwipeIndicator(sw));
    }
Example #50
0
    IEnumerator ShowSwipeIndicator(SwipeInfo sw)
    {
        //position the projectile object at the start point of the swipe
        Vector3 p=Camera.main.ScreenToWorldPoint(new Vector3(sw.startPoint.x, sw.startPoint.y, 5));
        swipeIndicator.position=p;

        float t=0;
        while(t<=1){
            p=Vector2.Lerp(sw.startPoint, sw.endPoint, t);
            p=Camera.main.ScreenToWorldPoint(new Vector3(p.x, p.y, 5));
            //Debug.Log(sw.startPoint+"  "+sw.endPoint+"   "+p);
            swipeIndicator.position=p;
            t+=0.2f;
            yield return null;
        }
    }
Example #51
0
 //when a swipe has end, valid or not
 void OnSwipeEnd(SwipeInfo sw)
 {
     //make sure we adjust the source(turret) scale back to original
     source.localScale=new Vector3(1.8f, 1.8f, 1.8f);
 }
Example #52
0
 //when a swipe has started, valid or not
 //if the starting position is on the source(turret), scale it up to give some visual feedback
 void OnSwipeStart(SwipeInfo sw)
 {
     Ray ray = Camera.main.ScreenPointToRay(sw.startPoint);
     RaycastHit hit;
     if(Physics.Raycast(ray, out hit, Mathf.Infinity)){
         if(hit.transform==source){
             source.localScale=new Vector3(2.2f, 2.2f, 2.2f);
         }
     }
 }
Example #53
0
 public static void SwipeEnd(SwipeInfo sw)
 {
     if(onSwipeEndE!=null) onSwipeEndE(sw);
 }
Example #54
0
    void SwipeEnd(Vector2 startPos, Vector2 endPos, float timeStartSwipe, int index, bool isMouse)
    {
        if(onlyFireWhenLiftCursor){
            if(!isMouse){
                for(int i=0; i<Input.touchCount; i++){
                    Touch touch=Input.touches[i];
                    if(touch.fingerId==index){
                        return;
                    }
                }
            }
            else{
                if(mouseIndex.Contains(index)){
                    //Debug.Log("mouse still down");
                    return;
                }
                if(Time.realtimeSinceStartup-timeStartSwipe>maxSwipeDuration){
                    //Debug.Log("too long   "+(Time.realtimeSinceStartup-timeStartSwipe));
                    return;
                }
            }
        }

        Vector2 swipeDir=endPos-startPos;
        SwipeInfo sw=new SwipeInfo(startPos, endPos, swipeDir, timeStartSwipe, index, isMouse);

        IT_Gesture.SwipeEnd(sw);

        if((swipeDir).magnitude<minDistance*IT_Gesture.GetDPIFactor()) {
            //GameMessage.DisplayMessage("too short");
            return;
        }

        if(Time.time-lastSwipeTime<minDurationBetweenSwipe) return;
        lastSwipeTime=Time.time;

        IT_Gesture.Swipe(sw);

        //GameMessage.DisplayMessage("swiped");
    }
Example #55
0
 public static void Swiping(SwipeInfo sw)
 {
     if(onSwipingE!=null) onSwipingE(sw);
 }
Example #56
0
 void HandleSwipe(SwipeInfo sw)
 {
     if (isDragging) return;
     ShowMarkerAt(sw.startPoint, 1);
     if (TestTouchPoint(sw.startPoint)) {
         ShowMarkerAt(firstTouchPos, 2);
         sw.startPoint = firstTouchPos;
     }
     Transform puck = PickObject (sw.startPoint);
     if (puck) {
         markerDisc.transform.position = puck.position;
         ResetPuck();
         DisplayText ("From: " + sw.startPoint + " to " + sw.endPoint + " Speed: " + sw.speed + " Angle: " + sw.angle);
         PuckMover mover = puck.GetComponent<PuckMover>();
         Debug.Log("Moving puck " + sw.speed + " angle: " + sw.angle);
         mover.Move(sw.speed, sw.angle);
     }
 }
Example #57
0
 void OnSwiping(SwipeInfo sw)
 {
 }
Example #58
0
 public void OnSwipe(SwipeInfo swipe)
 {
 }
 private void OnSwiping(SwipeInfo swipe)
 {
     for (int i = 0; i < this._listeners.Count; i++)
         this._listeners[i].OnSwiping(swipe);
 }
Example #60
0
 public static void Swipe(SwipeInfo sw)
 {
     Debug.Log("In Gesture.Swipe - handler: " + (onSwipeE != null));
     if(onSwipeE!=null) onSwipeE(sw);
 }