Exemple #1
0
 protected override void InputClicked(GameObject obj, InputClickedEventData eventData)
 {
     if (obj.name == "bnCall")
     {
         Debug.Log("[Receiver::InputClicked] Button clicked to initiate call");
         m_udp.sendUdpMessage("CALL start");
     }
 }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        if (m_newComputation)
        {
            m_sDebugText     = "[TestRaycast::Update] New computation ongoing x=" + m_relativePosX + " y=" + m_relativePosY;
            m_newComputation = false;

            Vector3 userClickedPointTR = Camera.main.ScreenToWorldPoint(new Vector3((int)(Camera.main.pixelWidth * m_relativePosX), (int)(Camera.main.pixelHeight * m_relativePosY), Camera.main.nearClipPlane));
            Vector3 directionTR        = Camera.main.transform.forward;

            Ray ray = Camera.main.ViewportPointToRay(new Vector3(m_relativePosX, m_relativePosY, 0));
            m_ray     = ray;
            m_rayShow = true;

            if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity))
            {
                m_sDebugText = "[TestRaycast::Update] What has been hit: " + hit.collider.gameObject.tag;
                if (hit.collider.gameObject.tag == "Annotations")
                {
                    for (int i = 0; i < m_annotations.Count; i++)
                    {
                        if (m_annotations[i] == hit.collider.gameObject)
                        {
                            Destroy(m_annotations[i]);
                            m_annotations.RemoveAt(i);
                            m_sDebugText = "[TestRaycast::Update] Object removed!";
                        }
                    }
                }
                else
                {
                    bool newAnnotationAdded = false;
                    if (m_iAnnotationSelected == 0)
                    {
                        m_annotations.Add(Instantiate(m_goAnnotationArrow));
                        newAnnotationAdded = true;
                    }
                    else if (m_iAnnotationSelected == 1)
                    {
                        m_annotations.Add(Instantiate(m_goAnnotationNoEntry));
                        newAnnotationAdded = true;
                    }

                    if (newAnnotationAdded)
                    {
                        m_annotations[m_annotations.Count - 1].transform.SetPositionAndRotation(hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
                        m_annotations[m_annotations.Count - 1].SetActive(true);
                    }
                }
            }
            else
            {
                m_udpListener.sendUdpMessage("WARNING noHits");
            }
        }
        else if (m_gestureToManage)
        {
            Debug.Log("[AnnotationsManager::Update] Gesture detected");
            m_sDebugText      = "[TestRaycast::Update] Handling gesture";
            m_gestureToManage = false;
            var headPosition  = Camera.main.transform.position;
            var gazeDirection = Camera.main.transform.forward;

            RaycastHit hitInfo;
            if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
            {
                for (int i = 0; i < m_annotations.Count; i++)
                {
                    if (m_annotations[i] == hitInfo.collider.gameObject)
                    {
                        Destroy(m_annotations[i]);
                        m_annotations.RemoveAt(i);
                        m_sDebugText = "[TestRaycast::Update] Object removed by user!";
                    }
                }
            }
        }

        m_goArrowGuidance.SetActive(m_bGuidanceArrowEnabled);


        if (m_iDebugStatus == 0)
        {
            m_debugCube.SetActive(false);
            m_lr.gameObject.SetActive(false);
            m_tmDebug.gameObject.SetActive(false);
        }
        else if (m_iDebugStatus == 3)
        {
            m_debugCube.SetActive(true);
            m_lr.gameObject.SetActive(true);
            m_tmDebug.gameObject.SetActive(true);

            if (m_rayShow)
            {
                Vector3 endPosition = m_ray.origin + (10 * m_ray.direction);

                m_lr.SetPosition(0, m_ray.origin);
                m_lr.SetPosition(1, endPosition);
                m_lr.SetColors(Color.green, Color.green);
                m_debugCube.transform.SetPositionAndRotation(m_ray.origin, m_debugCube.transform.rotation);

                m_sDebugText = "Camera resolution: " + Camera.main.pixelWidth + " " + Camera.main.pixelHeight;
            }

            m_tmDebug.text = m_sDebugText;
        }

        // Handling timer
        if (m_bTimerEnabled)
        {
            m_tmChat.gameObject.SetActive(true);
            m_dTimer -= Time.deltaTime;
            if (m_dTimer <= 0.0)
            {
                m_bTimerEnabled = false;
                m_tmChat.gameObject.SetActive(false);
                m_sChat = "";
            }
        }

        m_tmChat.text = m_sChat;
    }