Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (g_ButtonManager.g_InitCameraButtonClicked)
        {
            g_JsonManager.createReInitCamera();
            g_ButtonManager.g_InitCameraButtonClicked = false;
        }

        if (g_ButtonManager.g_ShowUltrasoundButtonClicked)
        {
            UltrasoundButtonClicked = true;
            g_ButtonManager.g_ShowUltrasoundButtonClicked = false;
        }

        try
        {
            // Verify that there was a touch event
            if (EventSystem.current != null && Input.touchCount > 0)
            {
                Touch[] myTouches = Input.touches;

                Vector3 touchedPoint3D = new Vector3(myTouches[0].position.x, myTouches[0].position.y, 0.0f);

                //Raycasting to see if the UI was hit from the camera perspective
                PointerEventData pointer = new PointerEventData(EventSystem.current);
                pointer.position = new Vector2(touchedPoint3D[0], touchedPoint3D[1]);
                List <RaycastResult> raycastResults = new List <RaycastResult>();
                EventSystem.current.RaycastAll(pointer, raycastResults);

                // The touch was performed on an element that was part of the UI (and if pixel is not transparent)
                if (raycastResults.Count > 0)
                {
                    // The touch was performed in one of the Icon annotations
                    if (raycastResults[0].gameObject.transform.parent.gameObject.name == "IconAnnotationsContainer")
                    {
                        // Single touch interactions
                        if (Input.touchCount == 1)
                        {
                            if (!isPixelTransparent(raycastResults) && !isUserLineAnnotating)
                            {
                                performIconUniFingerInteraction(myTouches, raycastResults);
                            }
                            else
                            {
                                performLineUniFingerInteraction(myTouches, touchedPoint3D);
                            }
                        }
                        // Multi finger touch performed over an icon annotation
                        // This could just be an else, but we are leaving it open in case of "more-than-two-touch-points" interactions
                        else if (Input.touchCount == 2)
                        {
                            if (!isPixelTransparent(raycastResults))
                            {
                                performIconMultiFingerInteraction(myTouches, raycastResults);
                            }
                            else
                            {
                                performBackgroundMultiFingerInteraction(myTouches, touchedPoint3D);
                            }
                        }
                    }
                    // UI Interaction. The bulk of these functions is at the ButtonClicking module
                    else
                    {
                        if (g_SelectedElementTransform != null)
                        {
                            // Deselect other buttons in the panel that might have been pressed
                            g_ButtonManager.SetObjectForColorChange(false, g_SelectedElementTransform);
                        }
                    }
                }
                // Touch interaction on the background image
                else
                {
                    // Single touch interaction. These are performed to create line annotations
                    if (Input.touchCount == 1)
                    {
                        if (!isUserIconAnnotating)
                        {
                            performLineUniFingerInteraction(myTouches, touchedPoint3D);
                        }
                        else
                        {
                            performIconUniFingerInteraction(myTouches, raycastResults);
                        }
                    }
                    // Multi touch interaction. These are performed to zoom the background image
                    // This could just be an else, but we are leaving it open in case of "more-than-two-touch-points" interactions
                    else if (Input.touchCount == 2)
                    {
                        if (isUserIconAnnotating)
                        {
                            performIconMultiFingerInteraction(myTouches, raycastResults);
                        }
                        else
                        {
                            performBackgroundMultiFingerInteraction(myTouches, touchedPoint3D);
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
    }