Ejemplo n.º 1
0
    public static bool TouchHitGameObject(SimTouch touch, out GameObject result, float rayCastDepth = 1500f)
    {
        result = null;

        //Raycast 3D
        Ray ray = Camera.main.ScreenPointToRay(touch.screenPosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, rayCastDepth))
        {
            if (hit.collider != null)
            {
                result = hit.collider.gameObject;
                return true;
            }
        }

        //Raycast 2D
        Vector3 worldPosition = Camera.main.ScreenToWorldPoint(touch.screenPosition);
        RaycastHit2D hit2D = Physics2D.Raycast(new Vector2(worldPosition.x, worldPosition.y), Vector2.zero, rayCastDepth);
        if (hit2D.collider != null)
        {
            result = hit2D.collider.gameObject;
            return true;
        }

        //no cigar
        return false;
    }
Ejemplo n.º 2
0
    public override void OnBeganTouch(SimTouch touch)
    {
        Debug.Log ("ON BEGAN TOUCH "+touch.time);

        GameObject target;
        if (InputHandler.TouchHitGameObject(touch, out target))
            Debug.Log("Hit object: "+target.name);
    }
Ejemplo n.º 3
0
 public override void OnMovedTouch(SimTouch touch)
 {
     if (isScrolling && touch.fingerID == scrollFinger)
     {
         if (allowScrolling)
             Scroll(touch.deltaScreenPosition);
         else
             isScrolling = false;
     }
 }
Ejemplo n.º 4
0
 public override void OnBeganTouch(SimTouch touch)
 {
     if (allowScrolling)
     {
         if (!isScrolling && TouchHitNothing(touch))
         {
             isScrolling = true;
             scrollFinger = touch.fingerID;
         }
     }
 }
Ejemplo n.º 5
0
 public override void OnBeganTouch(SimTouch touch)
 {
     if (TouchHitTarget(touch, _gameObject))
     {
         if (ShipPositionMarker.Instance.currentPort != this)
             LocationInfoPanel.Open(this);
     //			if (ShipPositionMarker.Instance.TravelToPort(this))
     //			{
     //				SoundManager.PlaySfx(Sfx.Click);
     //			}
     }
 }
Ejemplo n.º 6
0
    public static bool TouchHitNothing(SimTouch touch, float rayCastDepth = 1500f)
    {
        //Raycast 3D
        Ray ray = Camera.main.ScreenPointToRay(touch.screenPosition);
        if (Physics.Raycast(ray))
            return false;

        //Raycast 2D
        Vector3 worldPosition = Camera.main.ScreenToWorldPoint(touch.screenPosition);
        RaycastHit2D hit2D = Physics2D.Raycast(new Vector2(worldPosition.x, worldPosition.y), Vector2.zero, rayCastDepth);
        if (hit2D.collider != null)
            return false;

        return true;
    }
Ejemplo n.º 7
0
 private void HandleMouseEvents()
 {
     if (Input.GetMouseButtonDown(0))
     {
         trackMouse = true;
         SimTouch touch = new SimTouch();
         touch.fingerID = 1;
         touch.phase = TouchPhase.Began;
         touch.deltaTime = 0f;
         touch.time = Time.time;
         touch.screenPosition = Input.mousePosition;
         touch.deltaScreenPosition = Vector3.zero;
         lastTouches.Add(touch);
     }
     else if (trackMouse)
     {
         UpdateMouseTouch(1);
     }
 }
Ejemplo n.º 8
0
    private void UpdateMouseTouch(int id)
    {
        SimTouch lastTouch = GetLastTouchWithID(id);
        SimTouch touch = new SimTouch();

        touch.fingerID = id;
        touch.time = Time.time;
        touch.deltaTime = Time.time - lastTouch.time;
        touch.totalTime = lastTouch.totalTime + touch.deltaTime;
        touch.screenPosition = Input.mousePosition;

        touch.deltaScreenPosition = touch.screenPosition - lastTouch.screenPosition;

        if (Input.GetMouseButtonUp(0))
            touch.phase = TouchPhase.Ended;
        else if (Input.GetMouseButton(0))
        {
            if (screenRect.Contains(Input.mousePosition))
            {
                if (touch.deltaScreenPosition == Vector3.zero)
                    touch.phase = TouchPhase.Stationary;
                else
                    touch.phase = TouchPhase.Moved;
            }
            else
                touch.phase = TouchPhase.Canceled;
        }

        lastTouches.Add(touch);
        lastTouches.Remove(lastTouch);

        if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
            trackMouse = false;
    }
Ejemplo n.º 9
0
    private void HandleTouchEvents()
    {
        if (Input.touchCount > 0)
        {
            foreach (Touch touch in Input.touches) {

                SimTouch simTouch = new SimTouch();
                simTouch.fingerID = touch.fingerId;
                simTouch.phase = touch.phase;
                simTouch.deltaTime = touch.deltaTime;
                simTouch.screenPosition = touch.position;
                simTouch.deltaScreenPosition = touch.deltaPosition;
                simTouch.time = Time.time;
                simTouch.totalTime = 0f;

                if (simTouch.phase != TouchPhase.Began)
                {
                    SimTouch lastTouch = GetLastTouchWithID(touch.fingerId);
                    simTouch.totalTime = lastTouch.totalTime + simTouch.deltaTime;
                    lastTouches.Remove(lastTouch);
                }
                lastTouches.Add(simTouch);
            }
        }
    }
Ejemplo n.º 10
0
 public override void OnEndedOrCanceledTouch(SimTouch touch)
 {
     if (isScrolling && touch.fingerID == scrollFinger)
         isScrolling = false;
 }
Ejemplo n.º 11
0
 public virtual void OnStationaryTouch(SimTouch touch)
 {
 }
Ejemplo n.º 12
0
 public virtual void OnMovedTouch(SimTouch touch)
 {
 }
Ejemplo n.º 13
0
 public virtual void OnEndedOrCanceledTouch(SimTouch touch)
 {
 }
Ejemplo n.º 14
0
 public virtual void OnBeganTouch(SimTouch touch)
 {
 }