예제 #1
0
        void Update()
        {
            // Menu constants.
            int         numItems         = menuItems.Length;
            float       radiansPerItem   = 2.0f * Mathf.PI / numItems;
            const float MIN_INNER_RADIUS = 0.02f;
            const float MAX_OUTER_RADIUS = 0.25f;
            const float SELECT_RADIUS    = 0.04f;

            // Touchpad constants.
            bool    touching = GvrControllerInput.IsTouching;
            Vector2 touchPos = GvrControllerInput.TouchPos;

            touchPos.y = -touchPos.y;

            // Set the origin of the touch.
            if (touching && firstTouch)
            {
                touchOrigin = touchPos;
                firstTouch  = false;
            }
            else if (!touching)
            {
                firstTouch = true;
            }

            if (GvrControllerInput.ClickButton)
            {
                touchOrigin = touchPos;
            }

            // Get the touch delta from the origin.
            Vector2 p    = (touchPos - touchOrigin) * MAX_OUTER_RADIUS;
            float   pMag = p.magnitude;

            for (int i = 0; i < numItems; ++i)
            {
                float   theta   = radiansPerItem * i;
                Vector2 dir2D   = new Vector2(Mathf.Sin(theta), Mathf.Cos(theta));
                Vector3 dir     = new Vector3(Mathf.Sin(theta), 0.0f, Mathf.Cos(theta));
                Vector3 lerpPos = Vector3.Lerp(menuItems[i].transform.localPosition, dir * iconRadius, 0.1f);
                menuItems[i].transform.localPosition = lerpPos;

                if (touching && pMag > MIN_INNER_RADIUS &&
                    Mathf.Deg2Rad * Vector2.Angle(dir2D, p) < radiansPerItem * 0.5f)
                {
                    float blendDist = Mathf.Min(1.0f, (pMag - MIN_INNER_RADIUS) / SELECT_RADIUS);
                    float dist      = slotRadius * blendDist + iconRadius * (1.0f - blendDist);
                    menuItems[i].transform.localPosition = dir * dist;
                    if (pMag - MIN_INNER_RADIUS >= SELECT_RADIUS)
                    {
                        OnSwipeSelect.Invoke(i);
                    }
                }
            }
        }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        // Menu constants.

        float       radiansPerItem   = 2.0f * Mathf.PI / numItems;
        const float MIN_INNER_RADIUS = 0.02f;
        const float MAX_OUTER_RADIUS = 0.25f;
        const float SELECT_RADIUS    = 0.04f;

        // Touchpad constants.
        bool    touching = GvrControllerInput.IsTouching;
        Vector2 touchPos = GvrControllerInput.TouchPos;

        touchPos.y = -touchPos.y;

        // Set the origin of the touch.
        if (touching && firstTouch)
        {
            touchOrigin = touchPos;
            firstTouch  = false;
        }
        else if (!touching)
        {
            firstTouch = true;
        }

        if (GvrControllerInput.ClickButton)
        {
            touchOrigin = touchPos;
        }

        // Get the touch delta from the origin.
        Vector2 p    = (touchPos - touchOrigin) * MAX_OUTER_RADIUS;
        float   pMag = p.magnitude;

        for (int i = 0; i < numItems; ++i)
        {
            float   theta = radiansPerItem * i;
            Vector2 dir2D = new Vector2(Mathf.Sin(theta), Mathf.Cos(theta));
            Vector3 dir   = new Vector3(Mathf.Sin(theta), 0.0f, Mathf.Cos(theta));


            if (touching && pMag > MIN_INNER_RADIUS &&
                Mathf.Deg2Rad * Vector2.Angle(dir2D, p) < radiansPerItem * 0.5f)
            {
                float blendDist = Mathf.Min(1.0f, (pMag - MIN_INNER_RADIUS) / SELECT_RADIUS);
                if (pMag - MIN_INNER_RADIUS >= SELECT_RADIUS)
                {
                    if (OnSwipeSelect != null)
                    {
                        OnSwipeSelect.Invoke((SwipeAngle)i);
                    }
                }
            }
        }
    }