Exemplo n.º 1
0
    // 안드로이드 어플리케이션 관리 함수
    private void UpdateApplicationLifecycle()
    {
        // 뒤로가기 클릭시 앱 종료
        if (Input.GetKey(KeyCode.Escape))
        {
            QuitApplication();
        }

        // 모션 트래킹 중 슬립 방지
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            Screen.sleepTimeout = lostTrackingSleepTimeout;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        // 에러, 안드로이드 권한 없을시 종료
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted || Session.Status.IsError())
        {
            ShowAndroidToastMessage("Error with ARCore app.");
            Invoke("QuitApplication", 0.5f);
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
            return;
        }

        if (!sequencer.IsPlaying)
        {
            return;
        }

        // Check that motion tracking is tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            return;
        }
        // Iterate over planes found in this frame and instantiate corresponding planes.
        Session.GetTrackables <DetectedPlane>(newPlanes, TrackableQueryFilter.New);
        for (int i = 0; i < newPlanes.Count; ++i)
        {
            InitializeNewPlane(newPlanes[i]);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Check and update the application lifecycle.
    /// </summary>
    private void Lifecycle()
    {
        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        // Only allow the screen to sleep when not tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            Screen.sleepTimeout = lostTrackingSleepTimeout;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        // Quit if ARCore was unable to connect and give Unity some time for the toast to appear.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            Toast("Camera permission is needed to run this application.");
            Application.Quit();
        }
        else if (Session.Status.IsError())
        {
            Toast("ARCore encountered a problem connecting.  Please start the app again.");
            Application.Quit();
        }
    }
    //앱 생명주기를 업데이트
    private void _UpdateApplicationLifecycle()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            PhotonNetwork.LeaveRoom();
            SceneManager.LoadScene(0);
        }

        var sleepTimeout = SleepTimeout.NeverSleep;

        if (Session.Status != SessionStatus.Tracking)
        {
            sleepTimeout = SleepTimeout.SystemSetting;
        }

        Screen.sleepTimeout = sleepTimeout;

        if (IsQuitting)
        {
            return;
        }

        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            _QuitWithReason("Camera permission is needed to play AR Air Hockey");
        }
    }
    private void _UpdateApplicationLifecycle()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            Screen.sleepTimeout = lostTrackingSleepTimeout;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        if (m_IsQuitting)
        {
            return;
        }
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            _ShowAndroidToastMessage("Camera permission is needed to run this application.");
            m_IsQuitting = true;
            Invoke("_DoQuit", 0.5f);
        }
        else if (Session.Status.IsError())
        {
            _ShowAndroidToastMessage("ARCore encountered a problem connecting.  Please start the app again.");
            m_IsQuitting = true;
            Invoke("_DoQuit", 0.5f);
        }
    }
        /// <summary>
        /// Check and update the application lifecycle.
        /// </summary>
        private void _UpdateApplicationLifecycle()
        {
            if (!m_MatchStarted && m_NetworkManager.IsClientConnected())
            {
                m_MatchStarted = true;
            }

            // Exit the app when the 'back' button is pressed.
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            var sleepTimeout = SleepTimeout.NeverSleep;

#if !UNITY_IOS
            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                sleepTimeout = lostTrackingSleepTimeout;
            }
#endif

            Screen.sleepTimeout = sleepTimeout;

            if (m_IsQuitting)
            {
                return;
            }

            // Quit if ARCore was unable to connect and give Unity some time for the toast to
            // appear.
            if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
            {
                UIController.ShowErrorMessage(
                    "Camera permission is needed to run this application.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 5.0f);
            }
            else if (Session.Status.IsError())
            {
                UIController.ShowErrorMessage(
                    "ARCore encountered a problem connecting.  Please start the app again.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 5.0f);
            }
            else if (m_MatchStarted && !m_NetworkManager.IsClientConnected())
            {
                UIController.ShowErrorMessage(
                    "Network session disconnected!  Please start the app again.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 5.0f);
            }
        }
Exemplo n.º 7
0
    private void Update()
    {
        //앱 생명주기
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        var _SleepTimeout = SleepTimeout.SystemSetting;

        Screen.sleepTimeout = _SleepTimeout;
    }
Exemplo n.º 8
0
        public void Update()
        {
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            _QuitOnConnectionErrors();

            // Check that motion tracking is tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                Screen.sleepTimeout = lostTrackingSleepTimeout;
                if (!m_IsQuitting && Session.Status.IsValid())
                {
                    SearchingForPlaneUI.SetActive(true);
                }

                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
            Session.GetTrackables <TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New);
            for (int i = 0; i < m_NewPlanes.Count; i++)
            {
                // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
                // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
                // coordinates.
                GameObject planePrefab = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                     transform);
                planePrefab.GetComponent <TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
            }

            // Disable the ARUI when no planes are valid.
            Session.GetTrackables <TrackedPlane>(m_AllPlanes);
            bool showSearchingUI = true;

            for (int i = 0; i < m_AllPlanes.Count; i++)
            {
                if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    showSearchingUI = false;
                    break;
                }
            }

            SearchingForPlaneUI.SetActive(showSearchingUI);
        }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        // Example code to show toast on screen tap
        //Touch touch;
        //if (Input.touchCount != 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) return;
        //ShowAndroidToastMessage("Testing, 1... 2... 3...");

        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        // Only allow the screen to sleep when not tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            Screen.sleepTimeout = SleepTimeout.SystemSetting;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        if (m_IsQuitting)
        {
            return;
        }

        // Quit if ARCore was unable to connect and give Unity some time for the toast to
        // appear.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            ShowAndroidToastMessage("Camera permission is needed to run this application.");
            m_IsQuitting = true;
            Invoke("_DoQuit", 0.5f);
        }
        else if (Session.Status.IsError())
        {
            ShowAndroidToastMessage(
                "ARCore encountered a problem connecting.  Please start the app again.");
            m_IsQuitting = true;
            Invoke("_DoQuit", 0.5f);
        }
    }
    private void _UpdateApplicationLifecycle()
    {
        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        var sleepTimeout = SleepTimeout.NeverSleep;

        // Only allow the screen to sleep when not tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            sleepTimeout = lostTrackingSleepTimeout;
        }

        Screen.sleepTimeout = sleepTimeout;
    }
Exemplo n.º 11
0
    private bool OnBackButtonClicked()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
                                             .GetStatic <AndroidJavaObject>("currentActivity");
                activity.Call <bool>("moveTaskToBack", true);
            }
            else
            {
                Application.Quit();
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 12
0
    /// <summary>
    /// Check and update the application lifecycle.
    /// </summary>
    private void UpdateApplicationLifecycle()
    {
        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        // Only allow the screen to sleep when not tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            Screen.sleepTimeout = SleepTimeout.SystemSetting;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        if (_isQuitting)
        {
            return;
        }

        // Quit if ARCore was unable to connect and give Unity some time for the toast to
        // appear.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            ShowAndroidToastMessage("Camera permission is needed to run this application.");
            _isQuitting = true;
            Invoke("DoQuit", 0.5f);
        }
        else if (Session.Status.IsError())
        {
            ShowAndroidToastMessage(
                "ARCore encountered a problem connecting.  Please start the app again.");
            _isQuitting = true;
            Invoke("DoQuit", 0.5f);
        }
    }
    /// <summary>
    /// Está relacionado ao ciclo de vida do aplicativo e lida com comandos para
    /// sair do aplicativo, manter a tela ligada enquanto estiver rastreando e
    /// com mensagens de erro.
    /// </summary>
    private void UpdateApplicationLifecycle()
    {
        // Sair do aplicativo quando "Voltar for pressionado
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        // Só permitir apagar a tela quando não estiver rastreando
        if (Session.Status != SessionStatus.Tracking)
        {
            Screen.sleepTimeout = SleepTimeout.SystemSetting;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        if (_isQuitting)
        {
            return;
        }

        // Sair se ARCore não conseguiu se conectar e dar tempo pro Unity mostrar a mensagem torrada.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            ShowAndroidToastMessage("Precisamos da permissão do uso da câmera para o aplicativo funcionar.");
            _isQuitting = true;
            Invoke("DoQuit", 0.5f); // Invoca o DoQuit em 0.5 segundos.
        }
        else if (Session.Status.IsError())
        {
            ShowAndroidToastMessage(
                "ARCore encontrou um problema ao se conectar. Por favor, inicie o aplicativo novamente."
                );
            _isQuitting = true;
            Invoke("DoQuit", 0.5f);
        }
    }
Exemplo n.º 14
0
        /// <summary>
        /// 어플리케이션의 생명주기를 확인 및 업데이트하는 함수
        /// </summary>
        private void _UpdateApplicationLifecycle()
        {
            // '뒤로가기' 버튼을 눌렀을 경우 어플리케이션이 꺼질 수 있게 함
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            // 트레킹 되지 않을 경우에만 화면이 꺼지도록 함
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                Screen.sleepTimeout = lostTrackingSleepTimeout;
            }
            else
            {
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
            }

            if (m_IsQuitting)
            {
                return;
            }

            // Quit if ARCore was unable to connect and give Unity some time for the toast to appear.
            if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
            {
                _ShowAndroidToastMessage("현재 어플리케이션을 실행하려면 카메라 접근을 허용해주셔야 합니다.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 0.5f);
            }
            else if (Session.Status.IsError())
            {
                _ShowAndroidToastMessage("ARCore 연결 중 오류가 발생되었습니다. 어플리케이션을 다시 시작해주세요.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 0.5f);
            }
        }
Exemplo n.º 15
0
    private void UpdateApplicationLifeCycle()
    {
        //Go back to Camp when the back button is pressed
        if (Input.GetKey(KeyCode.Escape))
        {
            GameController.sharedInstance.ChangeScene("Ranch");
        }

        // Only allow the screen to sleep when not tracking
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            Screen.sleepTimeout = lostTrackingSleepTimeout;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        if (isQuitting)
        {
            return;
        }

        // Quit if ARCore was unable to connect and give Unity some time for the toast to appear.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            ShowAndroidToastMessage("Camera permission is needed to run this application");
            isQuitting = true;
            Invoke("DoQuit", 0.5f);
        }
        else if (Session.Status.IsError())
        {
            ShowAndroidToastMessage("An error has occurred, please restart the app.");
            isQuitting = true;
            Invoke("DoQuit", 0.5f);
        }
    }
Exemplo n.º 16
0
        /// <summary>
        /// Check and update the application lifecycle.
        /// </summary>
        private void _UpdateApplicationLifecycle()
        {
            // Exit the app when the 'back' button is pressed.
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            var sleepTimeout = SleepTimeout.NeverSleep;

#if !UNITY_IOS
            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 50;
                sleepTimeout = lostTrackingSleepTimeout;
            }
#endif

            if (m_IsQuitting)
            {
                return;
            }

            // Quit if ARCore was unable to connect and give Unity some time for the toast to appear.
            if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
            {
                Toast.ShowAndroidToastMessage("Camera permission is needed to run this application.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 0.5f);
            }
            else if (Session.Status.IsError())
            {
                Toast.ShowAndroidToastMessage("ARCore encountered a problem connecting.  Please start the app again.");
                m_IsQuitting = true;
                Invoke("_DoQuit", 0.5f);
            }
        }
Exemplo n.º 17
0
    /// <summary>
    /// The Unity Update() method.
    /// </summary>
    public void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        _QuitOnConnectionErrors();


        if (!Session.Status.IsValid())
        {
            return;
        }

        using (var image = Frame.CameraImage.AcquireCameraImageBytes())
        {
            if (!image.IsAvailable)
            {
                return;
            }
            _OnImageAvailable(image.Width, image.Height, image.YRowStride, image.Y, 0);
        }
    }
    /// <summary>
    /// Check and update the application lifecycle.
    /// </summary>
    private void _UpdateApplicationLifecycle()
    {
        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        var sleepTimeout = SleepTimeout.NeverSleep;

        // Only allow the screen to sleep when not tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            sleepTimeout = lostTrackingSleepTimeout;
        }

        Screen.sleepTimeout = sleepTimeout;

        if (m_IsQuitting)
        {
            return;
        }

        // Quit if ARCore was unable to connect and give Unity some time for the toast to
        // appear.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            m_IsQuitting = true;
            Invoke("_DoQuit", 5.0f);
        }
        else if (Session.Status.IsError())
        {
            m_IsQuitting = true;
            Invoke("_DoQuit", 5.0f);
        }
    }
Exemplo n.º 19
0
        /// <summary>
        /// Check and update the application lifecycle.
        /// </summary>
        private void _UpdateApplicationLifecycle()
        {
            // Exit the app when the 'back' button is pressed.
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            var sleepTimeout = SleepTimeout.NeverSleep;

#if !UNITY_IOS
            // Only allow the screen to sleep when not tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                sleepTimeout = lostTrackingSleepTimeout;
            }
#endif

            Screen.sleepTimeout = sleepTimeout;

            if (m_IsQuitting)
            {
                return;
            }

            // Quit if ARCore was unable to connect.
            if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
            {
                _QuitWithReason("Camera permission is needed to run this application.");
            }
            else if (Session.Status.IsError())
            {
                _QuitWithReason("ARCore encountered a problem connecting. " +
                                "Please start the app again.");
            }
        }
Exemplo n.º 20
0
    private void _UpdateApplicationLifeCycle()
    {
        // exit app on back pressed
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        // Only allow the screen to sleep when not tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            Screen.sleepTimeout = lostTrackingSleepTimeout;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }
        if (_IsQuitting)
        {
            return;
        }

        // Quit if ARCore was unable to connect and give Unity some time for the toast to appear.
        if (Session.Status == SessionStatus.ErrorPermissionNotGranted)
        {
            AndroidUtils.ShowAndroidToastMessage("Camera permission is needed to run this application");
            _IsQuitting = true;
            StartCoroutine(_DoQuitWithDelay(0.5f));
        }
        else if (Session.Status.IsError())
        {
            AndroidUtils.ShowAndroidToastMessage("ARCore connecting problem. Please start the app again.");
            _IsQuitting = true;
            StartCoroutine(_DoQuitWithDelay(0.5f));
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// The Unity Update() method.
    /// </summary>
    public void Update()
    {
        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
        _QuitOnConnectionErrors();
        // Check that motion tracking is tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            const int lostTrackingSleepTimeout = 15;
            Screen.sleepTimeout = lostTrackingSleepTimeout;
            if (!m_IsQuitting && Session.Status.IsValid())
            {
                SearchingForPlaneUI.SetActive(true);
            }
            return;
        }
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
        Session.GetTrackables <TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New);
        for (int i = 0; i < m_NewPlanes.Count; i++)
        {
            // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
            // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
            // coordinates.
            GameObject planeObject = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                 transform);
            planeObject.GetComponent <TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
        }
        // Hide snackbar when currently tracking at least one plane.
        Session.GetTrackables <TrackedPlane>(m_AllPlanes);
        bool showSearchingUI = true;

        for (int i = 0; i < m_AllPlanes.Count; i++)
        {
            if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
            {
                showSearchingUI = false;
                break;
            }
        }
        SearchingForPlaneUI.SetActive(showSearchingUI);
        // If the player has not touched the screen, we are done with this update.
        if (hasSetDoor)
        {
            return;
        }
        Touch touch;

        if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
        {
            return;
        }
        // Raycast against the location the player touched to search for planes.
        TrackableHit      hit;
        TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                          TrackableHitFlags.FeaturePointWithSurfaceNormal;

        if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
        {
            // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
            // world evolves.
            var anchor = hit.Trackable.CreateAnchor(hit.Pose);
            ARWorld.transform.position = anchor.transform.position + new Vector3(0, 1, 0);
            ARWorld.transform.SetParent(anchor.transform);
            ARWorld.transform.LookAt(new Vector3(FirstPersonCamera.transform.position.x, ARWorld.transform.position.y, FirstPersonCamera.transform.position.z));
            ARWorld.SetActive(true);
        }
    }
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            _QuitOnConnectionErrors();

            // Check that motion tracking is tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                Screen.sleepTimeout = lostTrackingSleepTimeout;
                if (!m_IsQuitting && Session.Status.IsValid())
                {
                    SearchingForPlaneUI.SetActive(true);
                }

                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
            Session.GetTrackables <TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New);
            for (int i = 0; i < m_NewPlanes.Count; i++)
            {
                // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
                // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
                // coordinates.
                GameObject planeObject = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                     transform);
                m_scenePlanes.Add(planeObject);
                planeObject.GetComponent <TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
            }

            // Disable the snackbar UI when no planes are valid.
            Session.GetTrackables <TrackedPlane>(m_AllPlanes);
            bool showSearchingUI = true;

            for (int i = 0; i < m_AllPlanes.Count; i++)
            {
                if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    showSearchingUI = false;
                    break;
                }
            }

            SearchingForPlaneUI.SetActive(showSearchingUI);

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1)
            {
                return;
            }
            touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began) //nandle a single touch
            {
                RaycastHit rayHit;
                if (Physics.Raycast(FirstPersonCamera.ScreenPointToRay(touch.position), out rayHit, 2))
                {
                    var outliner = rayHit.collider.gameObject.GetComponent <ObjectOutliner>();
                    if (outliner != null && outliner.outlineOn == false)
                    {
                        outliner.Outline();
                    }
                }
                else
                {
                    //touched outside, reset all outlined objects
                    foreach (var obj in m_sceneObjects)
                    {
                        var outliner = obj.GetComponentInChildren <ObjectOutliner>();
                        if (outliner != null && outliner.outlineOn)
                        {
                            outliner.Outline();
                        }
                    }
                    // Raycast against the location the player touched to search for planes.
                    TrackableHit      hit;
                    TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                                      TrackableHitFlags.FeaturePointWithSurfaceNormal;

                    if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
                    {
                        var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);
                        m_sceneObjects.Add(andyObject);
                        // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                        // world evolves.
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                        // Andy should look at the camera but still be flush with the plane.
                        if ((hit.Flags & TrackableHitFlags.PlaneWithinPolygon) != TrackableHitFlags.None)
                        {
                            // Get the camera position and match the y-component with the hit position.
                            Vector3 cameraPositionSameY = FirstPersonCamera.transform.position;
                            cameraPositionSameY.y = hit.Pose.position.y;

                            // Have Andy look toward the camera respecting his "up" perspective, which may be from ceiling.
                            andyObject.transform.LookAt(cameraPositionSameY, andyObject.transform.up);
                        }

                        // Make Andy model a child of the anchor.
                        andyObject.transform.parent = anchor.transform;
                    }
                }
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                var change = FirstPersonCamera.transform.forward * touch.deltaPosition.y;
                change += FirstPersonCamera.transform.right * touch.deltaPosition.x;
                change *= Time.deltaTime * MoveSpeed;
                //Debug.Log("mouse " + touch.deltaPosition.x + ":" + touch.deltaPosition.y);
                foreach (var obj in m_sceneObjects)
                {
                    var outliner = obj.GetComponentInChildren <ObjectOutliner>();
                    if (outliner != null && outliner.outlineOn)
                    {
                        obj.transform.position += change;
                    }
                }
            }
        }
Exemplo n.º 23
0
    //private const float ModelRotation = 180.0f;

    public void Update()
    {
        // 이미 배치되었으면 종료
        if (IsSpawn)
        {
            return;
        }

        // 터치 없으면 업데이트 종료
        Touch touch;

        if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
        {
            return;
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            PhotonNetwork.LeaveRoom();
            SceneManager.LoadScene(0);
        }

        /* Canvas를 통한 eventSystem이 존재하면 설치
         * // UI 터치하고 있으면 업데이트 종료
         * if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
         * {
         *  return;
         * }
         */

        //이미지로 발동
        Session.GetTrackables <AugmentedImage>(ImageList, TrackableQueryFilter.Updated);
        foreach (var image in ImageList)
        {
            if (image.TrackingState == TrackingState.Tracking && !IsSpawn)
            {
                SnackBarText.text = "Tracking now";
                Anchor anchor    = image.CreateAnchor(image.CenterPose);
                var    gameTable = Instantiate(HockeyTablePrefab, anchor.transform.position, anchor.transform.rotation);
                //Instantiate(HockeyTablePrefab, anchor.transform);
            }
            else if (image.TrackingState == TrackingState.Stopped)
            {
                SnackBarText.text = "not Tracking now";
            }
        }

        // 평면 찾기 위한 Raycast 설정
        TrackableHit      hit;
        TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                          TrackableHitFlags.FeaturePointWithSurfaceNormal;

        //Debug.Log(touch.position);
        if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
        {
            //Ray가 부딪힌 장소와 카메라 포지션을 이용해서 생성된 평면 뒤가 아닌가 확인
            if ((hit.Trackable is DetectedPlane) &&
                Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                            hit.Pose.rotation * Vector3.up) < 0)
            {
                Debug.Log("Hit at back of the current DetectedPlane");
            }
            else
            {
                Debug.Log("Touched");
                Debug.Log(hit.Trackable);
                if (hit.Trackable is DetectedPlane)
                {
                    DetectedPlane detectedPlane = hit.Trackable as DetectedPlane;
                    //수평 윗면인지 확인해서 인스턴스 생성
                    if (detectedPlane.PlaneType == DetectedPlaneType.HorizontalUpwardFacing)
                    {
                        var gameTable = PhotonNetwork.Instantiate(HockeyTablePrefab.name, hit.Pose.position, hit.Pose.rotation);
                        Debug.Log("Table is set");
                        gameTable.transform.Rotate(0, 0, 0, Space.Self);
                        var anchor = hit.Trackable.CreateAnchor(hit.Pose);
                        gameTable.transform.parent = anchor.transform;
                        IsSpawn = true;
                    }
                }
                Debug.Log("No trackable");
            }
        }
    }
Exemplo n.º 24
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        protected override void Update()
        {
            base.Update();
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            _QuitOnConnectionErrors();

            // Check that motion tracking is tracking.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int lostTrackingSleepTimeout = 15;
                Screen.sleepTimeout = lostTrackingSleepTimeout;
                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
            Session.GetTrackables <DetectedPlane>(m_NewPlanes, TrackableQueryFilter.New);
            for (int i = 0; i < m_NewPlanes.Count; i++)
            {
                // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
                // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
                // coordinates.
                GameObject planeObject = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                     transform);
                planeObject.GetComponent <DetectedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
            }

            // Disable the snackbar UI when no planes are valid.
            Session.GetTrackables <DetectedPlane>(m_AllPlanes);
            bool showSearchingUI = true;

            for (int i = 0; i < m_AllPlanes.Count; i++)
            {
                if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    showSearchingUI = false;
                    break;
                }
            }
            //SearchingForPlaneUI.SetActive(showSearchingUI);

            // If the player has not touched the screen, we are done with this update.
            Touch touch;

            if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
            {
                return;
            }

            // Raycast against the location the player touched to search for planes.
            TrackableHit      hit;
            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                              TrackableHitFlags.FeaturePointWithSurfaceNormal;

            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
            {
                var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);

                // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                // world evolves.
                var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                // Andy should look at the camera but still be flush with the plane.
                if ((hit.Flags & TrackableHitFlags.PlaneWithinPolygon) != TrackableHitFlags.None)
                {
                    // Get the camera position and match the y-component with the hit position.
                    Vector3 cameraPositionSameY = mainCamera.transform.position;
                    cameraPositionSameY.y = hit.Pose.position.y;

                    // Have Andy look toward the camera respecting his "up" perspective, which may be from ceiling.
                    andyObject.transform.LookAt(cameraPositionSameY, andyObject.transform.up);
                }

                // Make Andy model a child of the anchor.
                andyObject.transform.parent = anchor.transform;
            }
        }
Exemplo n.º 25
0
        public void Update()
        {
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            _QuitOnConnectionErrors();

            touch = Input.GetTouch(0);

            //Debug
            Text hitCounter = DebugUI.GetComponent <Text>();

            hitCount = Input.touchCount;
            if (hitCount > 0)
            {
                hitCounter.text = hitCount.ToString();
            }

            if (Input.touchCount >= 1 || (touch = Input.GetTouch(0)).phase == TouchPhase.Began)
            {
                CurrentState = GAME_STATE.STARTING;

                return;
            }

            //// Check that motion tracking is tracking.
            //if (Session.Status != SessionStatus.Tracking) {
            //    const int lostTrackingSleepTimeout = 15;
            //    Screen.sleepTimeout = lostTrackingSleepTimeout;
            //    if (!m_IsQuitting && Session.Status.IsValid()) {
            //        SearchingForPlaneUI.SetActive(true);
            //    }

            //    return;
            //}

            //Screen.sleepTimeout = SleepTimeout.NeverSleep;

            //// Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
            //Session.GetTrackables<TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New);
            //for (int i = 0; i < m_NewPlanes.Count; i++) {
            //    // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
            //    // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
            //    // coordinates.
            //    GameObject planePrefab = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
            //        transform);
            //    planePrefab.GetComponent<TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
            //}

            //// Disable the ARUI when no planes are valid.
            //Session.GetTrackables<TrackedPlane>(m_AllPlanes);
            //bool showSearchingUI = true;
            //for (int i = 0; i < m_AllPlanes.Count; i++) {
            //    if (m_AllPlanes[i].TrackingState == TrackingState.Tracking) {
            //        showSearchingUI = false;
            //        break;
            //    }
            //}

            //SearchingForPlaneUI.SetActive(showSearchingUI);
        }
Exemplo n.º 26
0
        //COROUTINES
        IEnumerator RoundStarting()
        {
            while (currentstate == GAME_STATE.STARTING)
            {
                StartingUI.SetActive(true);
                StatusUI.text = "Starting";

                if (Input.GetKey(KeyCode.Escape))
                {
                    Application.Quit();
                }

                _QuitOnConnectionErrors();

                // Check that motion tracking is tracking.
                if (Session.Status != SessionStatus.Tracking)
                {
                    const int lostTrackingSleepTimeout = 15;
                    Screen.sleepTimeout = lostTrackingSleepTimeout;
                    if (!m_IsQuitting && Session.Status.IsValid())
                    {
                        SearchingForPlaneUI.SetActive(true);
                    }

                    yield break;
                }

                Screen.sleepTimeout = SleepTimeout.NeverSleep;

                // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
                Session.GetTrackables <TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New);
                for (int i = 0; i < m_NewPlanes.Count; i++)
                {
                    // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
                    // the origin with an identity rotation since the mesh for our prefab is updated in Unity World
                    // coordinates.
                    GameObject planePrefab = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                                                         transform);
                    planePrefab.GetComponent <TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
                }

                // Disable the ARUI when no planes are valid.
                Session.GetTrackables <TrackedPlane>(m_AllPlanes);
                bool showSearchingUI = true;
                for (int i = 0; i < m_AllPlanes.Count; i++)
                {
                    if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                    {
                        showSearchingUI = false;
                        break;
                    }
                }

                SearchingForPlaneUI.SetActive(showSearchingUI);

                //Touch touch = Input.GetTouch(0);



                if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
                {
                    yield break;
                }

                // Raycast against the location the player touched to search for planes.
                TrackableHit      hit;
                TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                                  TrackableHitFlags.FeaturePointWithSurfaceNormal;

                if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && !placeModel)
                {
                    var StageInstance = Instantiate(StagePrefab, hit.Pose.position, hit.Pose.rotation);

                    var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                    if ((hit.Flags & TrackableHitFlags.PlaneWithinPolygon) != TrackableHitFlags.None)
                    {
                        Vector3 cameraPositionSameY = FirstPersonCamera.transform.position;
                        cameraPositionSameY.y = hit.Pose.position.y;

                        StageInstance.transform.LookAt(cameraPositionSameY, StageInstance.transform.up);
                        placeModel = true;
                    }

                    StageInstance.transform.parent = anchor.transform;

                    //yield return new WaitForSeconds(3);

                    //StartCoroutine(SpawnPlayers());

                    //if (allPlayersSpawned.Value == true) {

                    //yield return new WaitForSeconds(3);
                    CurrentState = GAME_STATE.PLAYING;

                    yield break;

                    //}
                }

                yield return(null);
            }
        }