Пример #1
0
 // Start is called before the first frame update
 void Start()
 {
     Input.multiTouchEnabled = true;
     // m_Cam = GameObject.FindGameObjectWithTag("MainCamera"); ;
     // _camCon = m_Cam.GetComponent<CameraController>();
     _dir = eSlideDirection.NODIRECTION;
 }
Пример #2
0
    void DetermineAlpha()
    {
        float dist = 0;
        float perc = 0;

        //determine wether themenu is sliding in or out to determine which axis to use for alpha testing
        eSlideDirection slideDirection = (slideState == eSlideState.Opening) ? slideInDirection : slideOutDirection;

        switch (slideDirection)
        {
        case eSlideDirection.Up:
        case eSlideDirection.Down:
            dist = targetPos.y - curPos.y;
            break;

        case eSlideDirection.Right:
        case eSlideDirection.Left:
            dist = targetPos.x - curPos.x;
            break;
        }

        //speed up fading so the menu fades in half the tranvel distance
        if (dist < 0)
        {
            dist *= -1;
        }
        if (dist != 0)
        {
            dist *= 2;
        }

        //test the difference between current pos and target location
        //target location being the position the menu should display at
        //or the position right next to it, offset by exactly the size of the menu
        //return the distance as a percentage and set alpha to that percentage
        switch (slideDirection)
        {
        case eSlideDirection.Up:
        case eSlideDirection.Down:
            perc = 1 - (dist / targetPos.height);
            break;

        case eSlideDirection.Right:
        case eSlideDirection.Left:
            perc = 1 - (dist / targetPos.width);
            break;
        }

        if (perc > 1)
        {
            perc = 1;
        }
        if (perc < 0)
        {
            perc = 0;
        }
        alpha = perc;
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount < 1)
        {
            return;
        }

        switch (Input.GetTouch(0).phase)
        {
        case TouchPhase.Began:
            _touchPointStart = Input.GetTouch(0).position;
            break;

        case TouchPhase.Moved:
            var deltaPos  = Input.GetTouch(0).deltaPosition;
            var fingerPos = Input.GetTouch(0).position;
            switch (_dir)
            {
            case eSlideDirection.NODIRECTION:
                if (Mathf.Abs(deltaPos.x) >= Mathf.Abs(deltaPos.y))
                {
                    _dir = eSlideDirection.HORIZONTAL;
                }
                else
                {
                    _dir = eSlideDirection.VERTICAL;
                }
                break;

            case eSlideDirection.HORIZONTAL:
                fingerPos.y = _touchPointStart.y;
                break;

            case eSlideDirection.VERTICAL:
                fingerPos.x = _touchPointStart.x;
                break;
            }
            var fingerPosVP  = Camera.main.ScreenToViewportPoint(fingerPos);
            var touchBeganVP = Camera.main.ScreenToViewportPoint(_touchPointStart);
            _UIManager.MovePage(touchBeganVP, fingerPosVP);
            break;

        case TouchPhase.Ended:
            _touchPointEnd = Input.GetTouch(0).position;
            switch (_dir)
            {
            case eSlideDirection.NODIRECTION:
                break;

            case eSlideDirection.HORIZONTAL:
                _moveDist = _touchPointEnd.x - _touchPointStart.x;
                _UIManager.SlidePage(new Vector2(_moveDist, 0));
                break;

            case eSlideDirection.VERTICAL:
                _moveDist = _touchPointEnd.y - _touchPointStart.y;
                _UIManager.SlidePage(new Vector2(0, _moveDist));
                break;
            }
            _dir = eSlideDirection.NODIRECTION;
            break;
        }
    }