示例#1
0
        void UpdateTouchInputs()
        {
            if (Input.GetMouseButtonDown(0) || Input.GetMouseButton(0) || Input.GetMouseButtonUp(0))
            {
                _newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                //catch all touch events
                if (Input.GetMouseButtonDown(0))
                {
                    GetHitObject();
                    if (_dragComponent != null)
                    {
                        _dragComponent.BeingTouched = true;
                        _dragComponent.OnStart();
                    }
                }
                else if (Input.GetMouseButton(0))
                {
                    if (_dragComponent != null)
                    {
                        _dragComponent.OnDrag(_newPosition);
                    }
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    if (_dragComponent != null)
                    {
                        _dragComponent.BeingTouched = false;
                        _dragComponent.OnStop();
                        _dragComponent = null;
                    }
                }
            }
        }
示例#2
0
        void UpdateTouchInputs()
        {
            if (Input.touchCount > 0)
            {
                _newPosition = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);

                //catch all touch events
                switch (Input.GetTouch(0).phase)
                {
                case TouchPhase.Began:
                    GetHitObject();
                    if (_dragComponent != null)
                    {
                        _dragComponent.BeingTouched = true;
                        _dragComponent.OnStart();
                    }
                    break;

                case TouchPhase.Moved:
                    if (_dragComponent != null)
                    {
                        _dragComponent.OnDrag(_newPosition);
                    }
                    break;

                case TouchPhase.Ended:
                    if (_dragComponent != null)
                    {
                        _dragComponent.BeingTouched = false;
                        _dragComponent.OnStop();
                        _dragComponent = null;
                    }
                    break;
                }
            }
        }