// Update is called once per frame void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); switch (touch.phase) { case TouchPhase.Began: startTouchPos = touch.position; break; case TouchPhase.Ended: if ((touch.position.y - startTouchPos.y) > 1.5) { if (OnSwipedUp != null) { OnSwipedUp(touch.position.y - startTouchPos.y); } } else { if (OnClicked != null) { OnClicked(); } } break; } } }
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]); } }
void Update() { //Update the Text on the screen depending on current TouchPhase, and the current direction vector // Track a single touch as a direction control. if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); // Handle finger movements based on TouchPhase switch (touch.phase) { //When a touch has first been detected, change the message and record the starting position case TouchPhase.Began: // Record initial touch position. startPos = touch.position; Debug.Log("Begun", gameObject); break; //Determine if the touch is a moving touch case TouchPhase.Moved: // Determine direction by comparing the current touch position with the initial one direction = touch.position - startPos; Debug.Log("Moving", gameObject); break; case TouchPhase.Ended: // Report that the touch has ended when it ends Debug.Log("Ending", gameObject); break; } } }
void ProcessTouch() { if (EventSystem.current.IsPointerOverGameObject()) { return; } Touch touch; if (Input.touchCount != 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { if (marker.Count > 2) { // spanwRoom.spawnARoom(hit, marker[0].transform.position, new Vector3()); } else { SpawnMarker(hit.Trackable as DetectedPlane); } } }
public void Update() { _UpdateApplicationLifecycle(); // Hide snackbar when tracking at least one plane. 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 touched the screen, spawn the selected model. Touch touch = Input.GetTouch(0); if (Input.touchCount >= 1 || (touch.phase == TouchPhase.Began)) { SpawnModel(touch); } }
public void Update() { ShowSearchingUI(); // if player has not touched screen, exit Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } // raycast against 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)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. if (!((hit.Trackable is DetectedPlane) && Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0)) { StartGame(hit); } } }
IEnumerator WaitForTouchToCharacterInstantiate() { while (true) { Touch touch; print(Input.touchCount); if (Input.touchCount == 1 && (touch = Input.GetTouch(0)).phase == TouchPhase.Began) { TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { if (hit.Trackable is DetectedPlane) { var chara = Instantiate(_characterVRMPrefab, hit.Pose.position, hit.Pose.rotation, _characterManager.transform); chara.transform.localScale = Vector3.one * _characterScale; _characterManager.Initialize(chara, _animatiorController); break; } } } yield return(null); } }
// Update is called once per frame void Update() { UpdateApplicationLifecycle(); Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } Debug.Log("射线击中了!"); TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.PlaneWithinBounds; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { if ((hit.Trackable is DetectedPlane) && Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("射线击中了DetectedPlane的背面!"); } else { var FoxObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); FoxObject.transform.Rotate(-90.0f, mModelRotation, 0, Space.Self); var anchor = hit.Trackable.CreateAnchor(hit.Pose); FoxObject.transform.parent = anchor.transform; } } }
// 안드로이드 어플리케이션 관리 함수 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); } }
// Update is called once per frame void Update() { if (!firstTime) { return; } if (Input.touchCount < 1) { return; } Touch touch = Input.GetTouch(0); Ray raycast = Camera.main.ScreenPointToRay(touch.position); RaycastHit raycastHit; if (Physics.Raycast(raycast, out raycastHit)) { if (raycastHit.transform.tag == "icecream") { GameObject curveObject = Instantiate(curvePrefab, raycastHit.transform.position + new Vector3(0, 0.2f, 0), Quaternion.identity); curveObject.transform.parent = raycastHit.transform; firstTime = false; } } }
void Update() { _UpdateApplicationLifecycle(); // 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; } // Should not handle input if the player is pointing on UI. if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { 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)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. 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 { // Choose the prefab based on the Trackable that got hit. GameObject prefab; if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.HorizontalUpwardFacing) { if (!Gate.activeInHierarchy) { Gate.SetActive(true); } hitPosition = new Vector3(hit.Pose.position.x, hit.Pose.position.y + GateHieght, hit.Pose.position.z); Gate.transform.position = hitPosition; hitRotation = hit.Pose.rotation; Gate.transform.rotation = hitRotation; //prefab.transform.Rotate(0, 0, 0, Space.Self); var anchor = hit.Trackable.CreateAnchor(hit.Pose); Gate.transform.parent = anchor.transform; AssuranceCanvus.SetActive(true); modelToShow.GetComponent <FollowObject>().FollowTheObject(hitPosition, hitRotation); } } } } }
//This will detect if user touches the screen. //if so then cast ray from camera to the touched position and check if it hits a ARCore detected plane private void ProcessTouches() { Touch touch; if ((Input.touchCount != 1) || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { //anchor hopefully keeps the players character model in a good place. Anchor anchor = _gm.detectedPlane.CreateAnchor(new Pose(hit.Pose.position, Quaternion.identity)); if (_characterToSpawn == Minions[0]) { Instantiate(_characterToSpawn, hit.Pose.position + new Vector3(0f, (_characterToSpawn.transform.localScale.y / 2), 0f), Quaternion.identity, anchor.transform); _ttc.IncrementTutText(); OnTogglePlanes(false); //currentMinionText.text = "Current Minion:" + _characterToSpawn.name; //Debugging } else { Instantiate(_characterToSpawn, hit.Pose.position, Quaternion.identity, anchor.transform); } if (_characterToSpawn == Minions[0]) { _playerCharacterSpawned = true; } } } }
/**<summary> Fire the weapon, raycast from touch position forward </summary>*/ override public int Fire() { if (Time.time > fireTime && Input.touchCount > 0) { fireTime = Time.time + weaponData.fireRate; RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.GetTouch(0).position); if (Physics.Raycast(ray, out hit, weaponData.range, hitMask)) { hit.collider.SendMessageUpwards("Damage", weaponData.damage, SendMessageOptions.DontRequireReceiver); if (hit.collider.attachedRigidbody) { hit.collider.attachedRigidbody.AddForce(-hit.normal * weaponData.hitForce); } Effects(hit.point); } else { Effects(ray.origin + (ray.direction * weaponData.range)); } return(weaponData.energyCost); } return(0); }
//앱 생명주기를 업데이트 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"); } }
/// <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)) { 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> /// 添加模型 /// </summary> void AddPrefab() { //光线投射命中的类型 TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast( Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, raycastFilter, out TrackableHit hit)) { //检查是否投射在了检测平面的背面 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 { //添加追踪锚点 Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose); //添加模型 Instantiate(prefab, hit.Pose.position, hit.Pose.rotation, anchor.transform); } } }
// Update is called once per frame void Update() { // 게임오버일 때 재시작 처리 if (gameOver) { if (Input.touchCount > 0) { Touch restart = Input.GetTouch(0); if (restart.phase == TouchPhase.Began) { Application.LoadLevel(Application.loadedLevel); } } } if (Input.touchCount > 0) { //Debug.Log(Input.touchCount); Touch touch = Input.GetTouch(0);; RaycastHit hit; touchPosition = Input.GetTouch(0).position; Ray ray = Camera.main.ScreenPointToRay(touchPosition); //Destroy(gameObject); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.tag == "Moles") { if (touch.phase == TouchPhase.Began) { hit.transform.GetComponent <StatusController>().MoleHit(); } } } } }
/// <summary> /// Funkcja wykrywająca kliknięcia na ekranie i wywołująca na odpowienich obiektach event kliknięcia /// </summary> private void OnScreenClick() { if (GameplayController.instance.session.gameState == GameState.running && boardVisible) { for (int i = 0; i < Input.touchCount; i++) { //Wykrywa tylko kliknięcia, które się rozpoczęły if (Input.GetTouch(i).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(i).fingerId)) { Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position); if (Physics.Raycast(ray, out RaycastHit hit)) { Visualiser visualiser = hit.collider.gameObject.GetComponent <Visualiser>(); if (visualiser != null) { visualiser.OnClick(); } } else //Jeśli dotkniemy poza budynkami środkowy budynek jest usuwany { centerBuilding.GetComponent <CenterVisualiser>().ToggleVisibility(false); } } } } }
void Update() { //管理应用的生命周期 UpdateApplicationLifecycle(); Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } //TrackableHit:保存的是发生碰撞检测时的检测到相关信息 TrackableHit hit; //TrackableHitFlags:用来过滤需要进行碰撞检测的对象类型,其值可以一个,也可以是几个 TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.PlaneWithinBounds; //ARCore在Frame中为我们准备了四种发射射线检测物体的方法,具体参考文章 if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { if ((hit.Trackable is DetectedPlane) && Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("射线击中了DetectedPlane的背面!"); } else { var prefabIns = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); prefabIns.transform.Rotate(0, mModelRotation, 0, Space.Self); var anchor = hit.Trackable.CreateAnchor(hit.Pose); prefabIns.transform.parent = anchor.transform; } } }
// Update is called once per frame void Update() { _UpdateApplicationLifecycle(); //If the y / cloud anchor is set, return if (m_IsStarted) { return; } if (auto_setup) { UI_Snackbar.text = "Initialize Settings Called"; SetFloorY(-1f); FloorCaptureControl.SetFloorY(-1); WorldOriginHelp.SetNoPlanes(true); IllusionModeStart(); m_IsStarted = true; } // 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; } // Should not handle input if the player is pointing on UI. if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { return; } // Raycast against the location the player touched to search for planes. TrackableHit arcoreHitResult = new TrackableHit(); m_LastHitPose = null; if (WorldOriginHelp.Raycast(touch.position.x, touch.position.y, TrackableHitFlags.PlaneWithinPolygon, out arcoreHitResult)) { m_LastHitPose = arcoreHitResult.Pose; } if (m_LastHitPose != null) { m_WorldOriginAnchor = arcoreHitResult.Trackable.CreateAnchor(arcoreHitResult.Pose); SetWorldOrigin(m_WorldOriginAnchor.transform); _InstantiateAnchor(); WorldOriginHelp.SetNoPlanes(true); SetFloorY(arcoreHitResult.Pose.position.y); FloorCaptureControl.SetFloorY(arcoreHitResult.Pose.position.y); IllusionModeStart(); // UI_Snackbar.text = "Take a picture of only your floor in the frame"; m_IsStarted = true; } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { _UpdateApplicationLifecycle(); // Hide snackbar when currently tracking at least one plane. 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)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. 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 { // Instantiate Andy model at the hit pose. AndyAndroidPrefab.SetActive(true); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). AndyAndroidPrefab.transform.Rotate(0, k_ModelRotation, 0, Space.Self); // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical // world evolves. var anchor = hit.Trackable.CreateAnchor(hit.Pose); // Make Andy model a child of the anchor. AndyAndroidPrefab.transform.parent = anchor.transform; } } }
// Update is called once per frame void Update() { //check AR session status if (Session.Status != SessionStatus.Tracking) { return; } //The following function will fill m_NewTrackedPlanes with the planes that ARCore detected in the current frame Session.GetTrackables <TrackedPlane>(m_NewTrackedPlanes, TrackableQueryFilter.New); //Instantiate a Grid for each TrackedPlane in m_NewTrackedPlanes for (int i = 0; i < m_NewTrackedPlanes.Count; ++i) { GameObject grid = Instantiate(GridPrefab, Vector3.zero, Quaternion.identity, transform); //This function will set the position of grid and modify the vertices of the attached mesh grid.GetComponent <GridVisualiser>().Initialize(m_NewTrackedPlanes[i]); } //Check if the user touches the screen Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } //Check if the user touched any of the tracked planes TrackableHit hit; if (Frame.Raycast(touch.position.x, touch.position.y, TrackableHitFlags.PlaneWithinPolygon, out hit)) { //Now place the portal on top of the tracked plane that we touched //Enable the portal PostBox.SetActive(true); //Create a new Anchor Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose); //Set the position pf the portal to be the same as the hit position PostBox.transform.position = hit.Pose.position; PostBox.transform.rotation = hit.Pose.rotation; //We want the portal to face the camera Vector3 cameraPosition = ARCamera.transform.position; //The portal should only rotate the Y axis cameraPosition.y = hit.Pose.position.y; //Rotate the portal to face the camera PostBox.transform.LookAt(cameraPosition, PostBox.transform.up); PostBox.transform.Rotate(new Vector3(0, 180, 0)); //ARCore will keep unstanding the world and update the anchor accordingly hence we need to attach our portal to the anchor PostBox.transform.parent = anchor.transform; } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { // 시작화면인지 아닌지 확인 if (this.PlayingLoginView) { return; } // 트레킹 중에는 Snakbar가 사라지게끔 함 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; } } if (!showHUD) { SearchingForPlaneUI.SetActive(showSearchingUI); ScanningForPlaneUI.SetActive(!showSearchingUI); } // if(!showOver){ // if(!showClear){ // if(!showShop){ // ScanningForPlaneUI.SetActive(!showHUD); // ShopUI.SetActive(!showHUD); // HUDUI.SetActive(showHUD); // } // else { // ClearUI.SetActive(!showShop); // ShopUI.SetActive(showShop); // } // } // else { // HUDUI.SetActive(!showClear); // ClearUI.SetActive(showClear); // } // } // else { // HUDUI.SetActive(!showOver); // GameOverUI.SetActive(showOver); // } // } // 화면에 터치가 되지 않을 경우, Update함수를 여기까지만 사용할 수 있게 설정 Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } }
// Update is called once per frame void Update() { // Check AR core session status if (Session.Status != SessionStatus.Tracking) { return; } //The following function will fill m_newTrackedPlanes with planes that ARCore deteced in the current frame Session.GetTrackables <DetectedPlane>(m_NewDetectedPlanes, TrackableQueryFilter.New); for (int i = 0; i < m_NewDetectedPlanes.Count; ++i) { GameObject grid = Instantiate(GridPrefab, Vector3.zero, Quaternion.identity, transform); //this function will set the position of the grid and modify the vertacies of the mesh grid.GetComponent <GridVisualizer>().Initialize(m_NewDetectedPlanes[i]); } //Check if the user touched the screen Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } //Let's now check if the user touched any of the tracked planes TrackableHit hit; if (Frame.Raycast(touch.position.x, touch.position.y, TrackableHitFlags.PlaneWithinPolygon, out hit)) { // Let's now place the portal on top of the tracked plane that we touched //Enable the portal Portal.SetActive(true); // Create a new anchor Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose); //set the position and rotation of the portal Portal.transform.position = hit.Pose.position; Portal.transform.rotation = hit.Pose.rotation; // we want to always make the portal instatiate towards the scrteen Vector3 cameraPosition = ARCamera.transform.position; // only rotate around the Y axis cameraPosition.y = hit.Pose.position.y; Portal.transform.LookAt(cameraPosition, Portal.transform.up); Portal.transform.parent = anchor.transform; } }
// Update is called once per frame void Update() { if (Session.Status != SessionStatus.Tracking) { return; } Session.GetTrackables <DetectedPlane>(m_NewTrackedPlanes, TrackableQueryFilter.New); var angle = DegreeBearing(50.36389, -4.15694, 42.35111, -71.04083); var distance = 0; var location = UnityEngine.Input.location; var lat = location.lastData.latitude; var longitude = location.lastData.longitude; GameObjectGPS obj = ReturnObjectToRender(); obj.objeto.transform.rotation = Quaternion.Euler(0, (float)angle, 0); obj.objeto.transform.Translate(new Vector3(0, 0, distance)); for (int i = 0; i < m_NewTrackedPlanes.Count; i++) { GameObject grid = Instantiate(GridPrefab, Vector3.zero, Quaternion.identity, transform); List <Vector3> bounds = new List <Vector3>(); m_NewTrackedPlanes[i].GetBoundaryPolygon(bounds); grid.GetComponent <GridVisualiser>().Initialize(m_NewTrackedPlanes[i]); } Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } TrackableHit hit; if (Frame.Raycast(touch.position.x, touch.position.y, TrackableHitFlags.PlaneWithinPolygon, out hit)) { Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose); Vector3 position = hit.Pose.position; position.y = 0.1f; GameObject myCylinder = Instantiate(Cylinder, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; myCylinder.transform.localScale = myCylinder.transform.localScale / 10; myCylinder.transform.position = position; myCylinder.transform.rotation = hit.Pose.rotation; myCylinder.transform.parent = anchor.transform; myCylinder.SetActive(true); } }
void ProcessTouch() { if (EventSystem.current.IsPointerOverGameObject()) { return; } Touch touch; if (Input.touchCount != 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { if (marker == null) { SpawnMarker(hit.Trackable as DetectedPlane); Constants.dataContainer.SetCurrentState(States.MarkerPlacement); } else if (!markerSet) { if (touch.position.y < Screen.height / 10) { markerSet = true; Constants.dataContainer.SetCurrentState(States.MarkerRotation); timeup = false; StartCoroutine(Timer()); } } else if (!roomSet && markerSet && timeup) { if (touch.position.x > Screen.width / 2 && touch.position.y > Screen.height / 10) { rotateMarker(2); } else if (touch.position.x < Screen.width / 2 && touch.position.y > Screen.height / 10) { rotateMarker(-2); } else { spawnRoom.spawnARoom(hit, marker.transform.position, marker.transform.rotation); roomSet = true; marker.SetActive(false); Constants.dataContainer.SetCurrentState(States.ModelPlacement); } } } }
// Update is called once per frame void Update() { if (Input.touchCount == 2) { Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; float prevMagnitude = (touchZeroPrevPos - touchOnePrevPos).magnitude; float currentMagnitude = (touchZero.position - touchOne.position).magnitude; float difference = currentMagnitude - prevMagnitude; Zoom(difference * 0.1f); } // if (Input.GetMouseButton(0)) // { // textPro.text = "pressed!"; // RaycastHit hit = new RaycastHit(); // Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // if (Physics.Raycast(ray, out hit, 30)) // { // if (hit.collider.gameObject.name == "gray_cirlce_ratator") test = true; // else test = false; // } // if (test) // { // cameraPoseoffset = Input.mousePosition - cameraPreviousPose; // cameraPoseoffset = new Vector3( // cameraPoseoffset.x % 20.0f, // cameraPoseoffset.y % 20.0f, // cameraPoseoffset.z % 20.0f // ); // transform.Rotate(transform.up, -Vector3.Dot(cameraPoseoffset, Camera.main.transform.right), Space.World); // gameObject.transform.parent.transform.Rotate(transform.up, -Vector3.Dot(cameraPoseoffset, Camera.main.transform.right), Space.World); // } // } // if (Input.GetMouseButtonUp(0)) // { // test = false; // } // cameraPreviousPose = Input.mousePosition; }
// Update is called once per frame void Update() { _UpdateApplicationLifecycle(); if (SetupCompleted == false) { // ORSetup(); } else { Debug.Log(string.Format("OT self: {0} hierarchy:{1} null:{2}", OperationTheater.activeSelf, OperationTheater.activeInHierarchy, OperationTheater == null)); Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(touch.position); if (Physics.Raycast(ray, out hit)) { GameObject Instrument = hit.collider.gameObject; InstrumentScript instrumentScript = Instrument.GetComponent <InstrumentScript>(); if (Instrument.tag == "Instruments") { if (Input.touchCount == 2) { Debug.Log("Double Touch detected"); instrumentScript.isActive = instrumentScript.isActive? false:true; } else if (currentInstrument == Instrument) { Instrument.transform.SetParent(OperationTheater.transform); currentInstrument = null; instrumentScript.isEquipped = false; } else { if (currentInstrument != null) { currentInstrument.transform.SetParent(Instrument.transform.parent); currentInstrument.transform.position = Instrument.transform.position; currentInstrument.transform.rotation = Instrument.transform.rotation; currentInstrument.GetComponent <InstrumentScript>().isEquipped = false; } Instrument.transform.SetParent(ARCamera.transform); Instrument.transform.localPosition = equippedInstrumentPosOffset; Instrument.transform.localEulerAngles = equippedInstrumenRotOffset; currentInstrument = Instrument; instrumentScript.isEquipped = true; } } } } }
/// <summary> /// The Unity Update() method. /// </summary> protected override void Update() { base.Update(); _UpdateApplicationLifecycle(); // Check that motion tracking is tracking. if (Session.Status != SessionStatus.Tracking) { return; } // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them. Session.GetTrackables <DetectedPlane>(m_NewPlanes, TrackableQueryFilter.New); // Hide snackbar when currently tracking at least one plane. 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)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. if ((hit.Trackable is DetectedPlane) && Vector3.Dot(mainCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("Hit at back of the current DetectedPlane"); } else { } } }