Пример #1
0
    public void OnPlaceBtn()
    {
        InsightARUserHitAnchor userHitAnchor = m_ARInterface.GetHitTestResult(0.5f, 0.5f);

        if (userHitAnchor.isValid == 1)
        {
            _enableShowIndicator = false;
            if (_cube != null)
            {
                _cube.SetActive(true);
                _cube.transform.position = userHitAnchor.position;
            }
        }
    }
Пример #2
0
    void Update()
    {
        #if UNITY_ANDROID
        if (QuitOnEscOrBack && Input.GetKeyDown(KeyCode.Escape))
        {
            DoStopAR();
            SceneManager.LoadScene("login");
        }
        #endif

        if (!isRunningAR)
        {
            return;
        }

        m_ARInterface.Update();

        updateStatusLabel();

        InsightARState arState = m_ARInterface.CurrentState;

        if (arState == InsightARState.Tracking || arState == InsightARState.Track_Limited)
        {
            if (_axis != null)
            {
                _axis.SetActive(true);
            }

            if (_enableShowIndicator)
            {
                Vector3 camPos = Camera.main.transform.position;
                Vector3 hitPos = camPos + Camera.main.transform.forward * hitDist;
                if (_indicator != null)
                {
                    _indicator.SetActive(true);
                    _indicator.transform.position = hitPos;
                    MeshRenderer r = _indicator.GetComponent <MeshRenderer>();
                    if (r != null)
                    {
                        r.sharedMaterial.SetColor("_Color", Color.white);
                    }
                }
            }
            else
            {
                if (_indicator != null)
                {
                    _indicator.SetActive(false);
                }
            }
        }
        else
        {
            if (_axis != null)
            {
                _axis.SetActive(false);
            }
            if (_cube != null)
            {
                _cube.SetActive(false);
            }
            if (_indicator != null)
            {
                _indicator.SetActive(false);
            }
        }

        if (Input.touchCount > 0 && !hasObjectCreated)
        {
            var touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved)
            {
                InsightARUserHitAnchor userHitAnchor = m_ARInterface.GetHitTestResult(touch);
                if (userHitAnchor.isValid == 1)
                {
                    _enableShowIndicator = false;
                    if (_cube != null)
                    {
                        hasObjectCreated = true;
                        _cube.SetActive(true);
                        _cube.transform.position = userHitAnchor.position;
                        _cube.transform.rotation = userHitAnchor.rotation;
                    }
                }
            }
        }
    }