Esempio n. 1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "ButtonHover")
        {
            // It has passed over 0.5 second (timeThreshBetweenEvents) since the last time a hover event fired.
            if (Time.time - lastHoverBeganTime > timeThreshBetweenEvents)
            {
                GameObject          parent = other.gameObject.transform.parent.gameObject;
                FingoStandardButton button = parent.GetComponent <FingoStandardButton>();

                if (button != null && button.OnEnterHover != null)
                {
                    button.OnEnterHover.Invoke();
                }

                lastHoverBeganTime = Time.time;
            }
        }
        else if (other.tag == "Button")
        {
            FingoStandardButton button = other.gameObject.GetComponent <FingoStandardButton>();

            Vector3 clickVelocity = (velocityCalculator != null) ? velocityCalculator.CalculateVelocity() : Vector3.zero;

            // Project velocity to object axes
            float vx = Vector3.Dot(clickVelocity, other.gameObject.transform.right);
            float vy = Vector3.Dot(clickVelocity, other.gameObject.transform.up);
            float vz = Vector3.Dot(clickVelocity, -other.gameObject.transform.forward); //invert z

            // If speed along z-axis is greater than that along x-axis and y-axis, then user is clicking towards the button.
            bool isClickingForward = (vz > zSpeedThresh && vz > Mathf.Abs(vx) && vz > Mathf.Abs(vy));

            // If all three conditions below are met, then it is a valid click:
            // (1) user is clicking forward,
            // (2) user collides the button with a clicking gesture, and
            // (3) it has passed over 0.5 second (timeThreshBetweenEvents) since the last click.
            bool clicked = (isClickingForward && IsClickingGesture() &&
                            (Time.time - lastClickTime > timeThreshBetweenEvents));

            if (clicked)
            {
                if (button != null && button.OnClick != null)
                {
                    button.OnClick.Invoke();
                }
                OnClickSucceeded.Invoke();

                lastClickTime = Time.time;
            }
            else
            {
                if (button != null && button.OnEnterButNotClick != null)
                {
                    button.OnEnterButNotClick.Invoke();
                }
            }
        }
    }
Esempio n. 2
0
    void OnTriggerExit(Collider other)
    {
        FingoStandardButton button = other.gameObject.GetComponent <FingoStandardButton>();

        if (button != null && button.OnExit != null)
        {
            button.OnExit.Invoke();
        }
    }
Esempio n. 3
0
    void OnTriggerEnter(Collider other)
    {
        FingoStandardButton button = other.gameObject.GetComponent <FingoStandardButton>();

        if (button != null && button.OnEnter != null)
        {
            button.OnEnter.Invoke();
        }

        if (button != null && button.OnCollide != null)
        {
            if (isCollidingForward && isCollidingGesture && collideCounter > collideInterval)
            {
                button.OnCollide.Invoke();
                collideCounter = 0;
            }
        }
    }
Esempio n. 4
0
    void OnTriggerExit(Collider other)
    {
        if (other.tag == "ButtonHover")
        {
            GameObject          parent = other.gameObject.transform.parent.gameObject;
            FingoStandardButton button = parent.GetComponent <FingoStandardButton>();

            if (button != null && button.OnExitHover != null)
            {
                button.OnExitHover.Invoke();
            }
        }
        else if (other.tag == "Button")
        {
            FingoStandardButton button = other.gameObject.GetComponent <FingoStandardButton>();

            if (button != null && button.OnExit != null)
            {
                button.OnExit.Invoke();
            }
        }
    }