Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //Enable hand gesture inputs if object is being focused. Maybe I need to create an invisible bubble to expand the raycast-hitable area.
        if (m_gFocusOfGaze)
        {
            deviceUI.SetActive(true);
            popupAnim.SetTrigger("OpenPopup");

            if (lastLeftHandPose != CurrentLeftHandPose.OpenHand && m_magicLeapController.m_currentLeftPose == CurrentLeftHandPose.OpenHand)
            {
                Debug.Log("inside device if openhand");
                currentMaterial         = m_defaultMaterial;
                m_meshRenderer.material = currentMaterial;
                lastLeftHandPose        = CurrentLeftHandPose.OpenHand;
            }
            else if (lastLeftHandPose != CurrentLeftHandPose.Finger && m_magicLeapController.m_currentLeftPose == CurrentLeftHandPose.Finger)
            {
                Debug.Log("inside device if finger");
                currentMaterial         = m_mat1;
                m_meshRenderer.material = currentMaterial;
                lastLeftHandPose        = CurrentLeftHandPose.Finger;
            }
            else if (lastLeftHandPose != CurrentLeftHandPose.Fist && m_magicLeapController.m_currentLeftPose == CurrentLeftHandPose.Fist)
            {
                Debug.Log("inside device if fist");
                currentMaterial         = m_mat2;
                m_meshRenderer.material = currentMaterial;
                lastLeftHandPose        = CurrentLeftHandPose.OpenHand;
            }
            else if (lastLeftHandPose != CurrentLeftHandPose.Ok && m_magicLeapController.m_currentLeftPose == CurrentLeftHandPose.Ok)
            {
                Debug.Log("inside device if ok");
                currentMaterial         = m_mat3;
                m_meshRenderer.material = currentMaterial;
                lastLeftHandPose        = CurrentLeftHandPose.Ok;
            }
            //else if (lastLeftHandPose != CurrentLeftHandPose.None && m_magicLeapController.m_currentLeftPose == CurrentLeftHandPose.None)
            //{
            //    //this isn't necessary. it just ends up resetarting the current state.
            //    Debug.Log("inside device if none");
            //    currentMaterial = m_defaultMaterial;
            //    m_meshRenderer.material = currentMaterial;
            //    lastLeftHandPose = CurrentLeftHandPose.None;
            //}
            //else
            //{
            //    Debug.Log("inside device - else");
            //    //m_meshRenderer.material = currentMaterial;
            //    currentMaterial = m_defaultMaterial;
            //    m_meshRenderer.material = currentMaterial;
            //}
        }
        else
        {
            StartCoroutine(WaitToDisableDeviceUI());
            popupAnim.SetTrigger("ClosePopup");
        }
    }
    // Update is called once per frame
    void Update()
    {
        Ray        ray     = new Ray(transform.position, transform.forward);
        RaycastHit hitInfo = new RaycastHit();

        if (Physics.Raycast(ray, out hitInfo, 100, layerMask))
        {
            Debug.Log("Gaze Raycast hit: " + hitInfo.transform.gameObject.name);
            FocusDevice(hitInfo.transform.gameObject);
        }
        else
        {
            if (currentFocusedDevice)
            {
                ClearFocus();
            }
        }

        // lets see what this does. Ok no dice i cant access the actual ray it uses easily, so I'm just gonna do this from scratch.
        //if (Physics.Raycast(_raycastHead.transform.position, out hitInfo, 100, layerMask))
        //{
        //    //StartCoroutine(SmoothMoveToHand(hitInfo.collider.transform));
        //}

        //Hand Tracking - Setting Hand Poses.
        if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Thumb))
        {
            Debug.Log("Left hand thumb pose detected - on");
            m_currentLeftPose = CurrentLeftHandPose.Thumb;
        }
        else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Fist))
        {
            Debug.Log("Left hand fist pose detected - off");
            m_currentLeftPose = CurrentLeftHandPose.Fist;
        }
        else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Finger))
        {
            Debug.Log("Left hand finger pose detected - Mode 1");
            m_currentLeftPose = CurrentLeftHandPose.Finger;
        }
        else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.OpenHand))
        {
            Debug.Log("Left hand Open Hand pose detected - Mode 2");
            m_currentLeftPose = CurrentLeftHandPose.OpenHand;
        }
        else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Ok))
        {
            Debug.Log("Left hand OK pose detected - Mode 3");
            m_currentLeftPose = CurrentLeftHandPose.Ok;
        }
        else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.NoPose))
        {
            Debug.Log("Left hand no pose detected");
            m_currentLeftPose = CurrentLeftHandPose.None;
        }
        else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.NoHand))
        {
            Debug.Log("Left hand no hand detected");
            m_currentLeftPose = CurrentLeftHandPose.None;
        }
        //If Right hand
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.Thumb))
        {
            Debug.Log("Right hand thumb pose detected - on");
            m_currentRightPose = CurrentRightHandPose.Thumb;
        }
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.Fist))
        {
            Debug.Log("Right hand fist pose detected - off");
            m_currentRightPose = CurrentRightHandPose.Fist;
        }
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.Finger))
        {
            Debug.Log("Right hand finger pose detected - Mode 1");
            m_currentRightPose = CurrentRightHandPose.Finger;
        }
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.OpenHand))
        {
            Debug.Log("Right hand Open Hand pose detected - Mode 2");
            m_currentRightPose = CurrentRightHandPose.OpenHand;
        }
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.Ok))
        {
            Debug.Log("Right hand OK pose detected - Mode 3");
            m_currentRightPose = CurrentRightHandPose.Ok;
        }
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.NoPose))
        {
            Debug.Log("Right hand no pose detected");
            m_currentRightPose = CurrentRightHandPose.None;
        }
        else if (GetGesture(MLHandTracking.Right, MLHandTracking.HandKeyPose.NoHand))
        {
            Debug.Log("Right hand no hand detected");
            m_currentRightPose = CurrentRightHandPose.None;
        }
    }