// Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            GameManager.Instance.Quit();
        }
        if (Input.GetMouseButtonDown(0))
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 20.0f, 1 << LayerMask.NameToLayer("TouchEvent"));
            if (null != hit.collider)
            {
                TouchEvent touchEvent = hit.collider.gameObject.GetComponent <TouchEvent>();
                if (null != touchEvent.onTouchDown)
                {
                    touchEvent.onTouchDown(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                }
                touchEvents.Add(touchEvent, touchEvent);
            }
            lastMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        foreach (var v in touchEvents)
        {
            TouchEvent touchEvent = v.Value;
            if (null != touchEvent.onTouchDrag)
            {
                touchEvent.onTouchDrag(Camera.main.ScreenToWorldPoint(Input.mousePosition) - lastMousePosition);
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            foreach (var v in touchEvents)
            {
                TouchEvent touchEvent = v.Value;
                if (null != touchEvent.onTouchUp)
                {
                    touchEvent.onTouchUp(Input.mousePosition);
                }
            }
            touchEvents.Clear();
        }

        lastMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }