Ejemplo n.º 1
0
    private void CalculateTouchInput(SimpleTouch currentTouch)
    {
        // the normalized property of Vector2 returns the same vector but with
        // a magnitude of 1. We only care about direction here.
        Vector2 touchDirection =
            (currentTouch.currentTouchLocation - currentTouch.startTouchLocation).normalized;

        // here we only get the distance, aka the magnitude.
        float touchDistance =
            (currentTouch.startTouchLocation - currentTouch.currentTouchLocation).magnitude;

        // get time elapsed from beginning of touch til now
        TimeSpan timeGap       = System.DateTime.Now - currentTouch.startTime;
        double   touchTimeSpan = timeGap.TotalSeconds;

        // if touch meets our requirements for what constitutes a swipe, we label it a swipe,
        // otherwise we consider it a tap
        string touchType =
            (touchDistance > swipeDistance && touchTimeSpan > swipeTime) ? "Swipe" : "Tap";

        print(touchType);

        if (gameCharacter != null)
        {
            if (!gameCharacter.isDead)
            {
                gameCharacter.ReceiveInput(touchDistance, touchDirection);
            }
        }
    }
Ejemplo n.º 2
0
    private void CalculateTouchInput(SimpleTouch CurrentTouch)
    {
        Vector2  touchDirection = (CurrentTouch.CurrentTouchLocation - CurrentTouch.StartTouchLocation).normalized;
        float    touchDistance  = (CurrentTouch.StartTouchLocation - CurrentTouch.CurrentTouchLocation).magnitude;
        TimeSpan timeGap        = System.DateTime.Now - CurrentTouch.StartTime;
        double   touchTimeSpan  = timeGap.TotalSeconds;

        // Set Game Character (Unknown for now)
    }
Ejemplo n.º 3
0
    private void CalculateTouchInput(SimpleTouch CurrentTouch)
    {
        Vector2 touchDirection = (CurrentTouch.CurrentTouchLocation - CurrentTouch.StartTouchLocation);
        float touchDistance = (CurrentTouch.StartTouchLocation - CurrentTouch.CurrentTouchLocation).magnitude;

        if (GameCharacter != null) {
            RaycastHit2D hitInfo = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (
            CurrentTouch.StartTouchLocation), Vector2.zero);
            if (hitInfo && hitInfo.transform.CompareTag("Player")) {
                GameCharacter.ReceiveInput (touchDirection, touchDistance);
            }
        }
    }
Ejemplo n.º 4
0
    private void CalculateTouchInput(SimpleTouch CurrentTouch)
    {
        Vector2 touchDirection = (CurrentTouch.CurrentTouchLocation - CurrentTouch.StartTouchLocation);
        float   touchDistance  = (CurrentTouch.StartTouchLocation - CurrentTouch.CurrentTouchLocation).magnitude;

        //if (_pivot != null)
        //{
        //    RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(
        //    CurrentTouch.StartTouchLocation), Vector2.zero);
        //    if (hitInfo && hitInfo.transform.CompareTag("Player"))
        //    {
        //        _pivot.ReceiveInput(touchDirection, touchDistance);
        //    }
        //}
    }
Ejemplo n.º 5
0
	private void CalculateTouchInput(SimpleTouch CurrentTouch)
	{
		Vector2 touchDirection  = (CurrentTouch.CurrentTouchLocation - CurrentTouch.StartTouchLocation).normalized;
		float touchDistance     = (CurrentTouch.StartTouchLocation - CurrentTouch.CurrentTouchLocation).magnitude;
		TimeSpan timeGap        = System.DateTime.Now - CurrentTouch.StartTime;
		double touchTimeSpan    = timeGap.TotalSeconds;

		//string touchType        = ( touchDistance > SwipeDistance && touchTimeSpan > SwipeTime ) ? "Swipe" : "Tap";

		if (GameCharacter != null)
		{
			hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(CurrentTouch.StartTouchLocation),Vector2.zero);
			if (hit) {
				print ("name="+hit.collider.name);
				if (hit.collider.name == "Gold") {
					GameCharacter.ReceiveInput (touchDistance, touchDirection);
				}
			}
			
		}
	}
Ejemplo n.º 6
0
	private void CalculateSwipe(SimpleTouch CurrentTouch) {
		theSwipe = CurrentTouch.CurrentTouchLocation - CurrentTouch.StartTouchLocation;
	}
Ejemplo n.º 7
0
 private void CalculateSwipe(SimpleTouch CurrentTouch)
 {
     theSwipe = CurrentTouch.CurrentTouchLocation - CurrentTouch.StartTouchLocation;
 }
Ejemplo n.º 8
0
    void Update()
    {
        SimpleTouch newTouch = new SimpleTouch();

        Vector2 newHovered;

        if (touchMode == TouchMode.Viewport)
        {
            newHovered = Camera.main.ScreenToViewportPoint(Input.mousePosition + Vector3.forward * 5);
        }
        else// if (touchMode == TouchMode.World)
        {
            newHovered = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 5);
        }


        if (Input.GetMouseButton(0))
        {
            touching          = true;
            newTouch.position = newHovered;
            if (Input.GetMouseButtonDown(0))
            {
                newTouch.phase         = SimpleTouch.TouchPhase.Began;
                newTouch.deltaPosition = Vector2.zero;
                OnTouchBegin?.Invoke(newTouch);
            }
            else
            {
                newTouch.deltaPosition = newTouch.position - touch.position;
                if (newTouch.deltaPosition != Vector2.zero)
                {
                    newTouch.phase = SimpleTouch.TouchPhase.Moved;
                }
                else
                {
                    newTouch.phase = SimpleTouch.TouchPhase.Stationary;
                }
                OnTouchContinue?.Invoke(newTouch);
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            touching               = false;
            newTouch.phase         = SimpleTouch.TouchPhase.Ended;
            newTouch.position      = touch.position;
            newTouch.deltaPosition = touch.deltaPosition;
            OnTouchEnd?.Invoke(newTouch);
        }
        else
        {
            touching               = false;
            newTouch.phase         = SimpleTouch.TouchPhase.Hovered;
            newTouch.position      = newHovered;
            newTouch.deltaPosition = newTouch.position - touch.position;
            OnHover?.Invoke(newTouch);
        }

        OnTouch?.Invoke(newTouch);

        touch = newTouch;
    }
Ejemplo n.º 9
0
 private void Awake()
 {
     Input.simulateMouseWithTouches = true;
     touch = new SimpleTouch();
 }