/// <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 (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); } }
//public Text scoreText; /// <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; } if (!hoopPlaced) { //scoreText.text = "not placed hoop : " + Input.touchCount.ToString(); _placeBasketballHoop(touch); _ShowAndroidToastMessage("Hoop Placed."); } else { //scoreText.text = "placed "; } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } _QuitOnConnectionErrors(); _UpdateFrameRate(); // Change the CPU resolution checkbox visibility. LowResConfigToggle.gameObject.SetActive(EdgeDetectionBackgroundImage.enabled); HighResConfigToggle.gameObject.SetActive(EdgeDetectionBackgroundImage.enabled); m_ImageTextureToggleText.text = EdgeDetectionBackgroundImage.enabled ? "Switch to GPU Texture" : "Switch to CPU Image"; 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); } var cameraIntrinsics = EdgeDetectionBackgroundImage.enabled ? Frame.CameraImage.ImageIntrinsics : Frame.CameraImage.TextureIntrinsics; string intrinsicsType = EdgeDetectionBackgroundImage.enabled ? "CPU Image" : "GPU Texture"; CameraIntrinsicsOutput.text = _CameraIntrinsicsToString(cameraIntrinsics, intrinsicsType); }
void PlaceObjectInInstantPreview() { 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. if (InstantPlacementMenu.IsInstantPlacementEnabled()) { foundHit = Frame.RaycastInstantPlacement(touch.position.x, touch.position.y, 1.0f, out hit); } else { TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; foundHit = Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit); } }
// 생성 후에,, // 피킹한다. void ObjectSelect() { if (Input.touchCount == 1) //if (Input.GetMouseButton(0)) { RaycastHit hit; Ray ray = FirstPersonCamera.ScreenPointToRay(Input.GetTouch(0).position); //Ray ray = FirstPersonCamera.ScreenPointToRay(Input.mousePosition); bool bCheck = Physics.Raycast(ray, out hit, 30f); if (true == bCheck) { int iLayer = hit.collider.gameObject.layer; //Debug.Log("layer: " + iLayer); if (11 == iLayer) // curry 선택시에 { // event 발생... EventObjectSelect(TABLE_SET.CURRY); } else if (12 == iLayer) // Rice Noodle { // event 발생... EventObjectSelect(TABLE_SET.RICE_NOODLE); } else if (13 == iLayer) // China Noodle { // event 발생... EventObjectSelect(TABLE_SET.CHINA_NOODLE); } else if (14 == iLayer) // Miso Soup { // event 발생... EventObjectSelect(TABLE_SET.MISO_SOUP); } } } }
public void _InstantiateOnTouch() { // If the player has not touched the screen, we are done with this update. Touch touch; int numberOfMonsAllowed = 1; 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)) { Debug.Log("Screen Touched"); if (CurrentNumberOfMon < numberOfMonsAllowed) { Debug.Log("Current Mons " + CurrentNumberOfMon); MonsterObject = Instantiate(MonsterPrefab, hit.Pose.position, hit.Pose.rotation); CurrentNumberOfMon = CurrentNumberOfMon + 1; // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical world evolves. var anchor = hit.Trackable.CreateAnchor(hit.Pose); if ((hit.Flags & TrackableHitFlags.PlaneWithinPolygon) != TrackableHitFlags.None) // Andy should look at the camera but still be flush with the plane. { Vector3 cameraPositionSameY = FirstPersonCamera.transform.position; // Get the camera position and match the y-component with the hit position. cameraPositionSameY.y = hit.Pose.position.y; MonsterObject.transform.LookAt(cameraPositionSameY, MonsterObject.transform.up); // Have Andy look toward the camera respecting his "up" perspective, which may be from ceiling. } MonsterObject.transform.parent = anchor.transform; // Make Monster model a child of the anchor. } } return; }
/// <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)) { appController.LoadScene("MainMenuScene"); } // Only allow the screen to sleep when not tracking. if (Session.Status != SessionStatus.Tracking) { Screen.sleepTimeout = SleepTimeout.SystemSetting; } else { Screen.sleepTimeout = SleepTimeout.NeverSleep; } // If the app is already in a quitting state, skip the next verifications if (isQuitting) { return; } if (Session.Status == SessionStatus.ErrorPermissionNotGranted) { ShowAndroidToastMessage("Camera permission is needed to run this application."); isQuitting = true; Invoke("QuitTheApplication", 0.5f); } else if (Session.Status.IsError()) { ShowAndroidToastMessage("ARCore encountered a problem connecting. Please start the app again."); isQuitting = true; Invoke("QuitTheApplication", 0.5f); } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } _QuitOnConnectionErrors(); // Toggle background to edge detection. if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { EdgeDetectionBackgroundImage.enabled = !EdgeDetectionBackgroundImage.enabled; } if (!Session.Status.IsValid()) { return; } if (UseCustomResolutionImage) { return; } using (var image = Frame.CameraImage.AcquireCameraImageBytes()) { if (!image.IsAvailable) { return; } _OnImageAvailable(TextureReaderApi.ImageFormatType.ImageFormatGrayscale, image.Width, image.Height, image.Y, 0); } }
public void _PinchtoZoom() { if (Input.touchCount == 2) { // Store both touches. Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); // Find the position in the previous frame of each touch. Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; // Find the magnitude of the vector (the distance) between the touches in each frame. float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; // Find the difference in the distances between each frame. float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; float pinchAmount = deltaMagnitudeDiff * pinchSpeed * Time.deltaTime; ARObject.transform.localScale -= new Vector3(pinchAmount, pinchAmount, pinchAmount); } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { //_UpdateApplicationLifecycle(); Ray ray; RaycastHit hit; if (Input.touchCount > 0 && (Input.GetTouch(0)).phase == TouchPhase.Began) { ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.collider.tag == "R1") { index[0]++; index[0] = index[0] % 4; hit.collider.gameObject.GetComponent <MeshRenderer>().material = mats[index[0]]; if (index[0] == 0) { correct[0] = 1; } else { correct[0] = 0; } } else if (hit.collider.tag == "R2") { index[1]++; index[1] = index[0] % 4; hit.collider.gameObject.GetComponent <MeshRenderer>().material = mats[index[1]]; if (index[1] == 1) { correct[1] = 1; } else { correct[1] = 0; } } else if (hit.collider.tag == "R3") { index[2]++; index[2] = index[2] % 4; hit.collider.gameObject.GetComponent <MeshRenderer>().material = mats[index[2]]; if (index[2] == 2) { correct[2] = 1; } else { correct[2] = 0; } } else if (hit.collider.tag == "R4") { index[3]++; index[3] = index[3] % 4; hit.collider.gameObject.GetComponent <MeshRenderer>().material = mats[index[3]]; if (index[3] == 3) { correct[3] = 1; } else { correct[3] = 0; } } if (checkCorrect()) { LoadingScreen.SetActive(true); // Persistent Update PersistentDataController PDC = GameObject.FindGameObjectWithTag("persistentDataController").GetComponent <PersistentDataController>(); PDC.addCollectible(3, "Milk", planetSprite); PDC.relayMessage = "You got the milk"; PDC.sceneChange = 1; SceneManager.LoadScene("PeacefulForest", LoadSceneMode.Single); } } } }
/// <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 { // Choose the Andy model for the Trackable that got hit. GameObject prefab = null; if (hit.Trackable is FeaturePoint) { prefab = AndyPointPrefab; } else if (portalInstance == null || !portalInstance.gameObject.activeInHierarchy) { prefab = spawnPrefab; } else { return; } // Instantiate Andy model at the hit pose. prefab.SetActive(true); Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose); prefab.transform.position = hit.Pose.position; prefab.transform.rotation = hit.Pose.rotation; Vector3 cameraposition = FirstPersonCamera.transform.position; cameraposition.y = hit.Pose.position.y; prefab.transform.LookAt(cameraposition, prefab.transform.up); prefab.transform.parent = anchor.transform; portalInstance = prefab; } } }
/// <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 (DataScript.resetCar) { car = null; DataScript.resetCar = false; GameObject prefab = AndyPlanePrefab; car = Instantiate(prefab, start, startRotation); car.transform.position = start; car.transform.rotation = startRotation; // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). car.transform.Rotate(0, k_ModelRotation, 0, Space.Self); var anchor = initHit.Trackable.CreateAnchor(initHit.Pose); // Make Andy model a child of the anchor. car.transform.parent = anchor.transform; car.tag = "Player"; var rb = car.AddComponent<Rigidbody>(); rb.position = start; BoxCollider bc = car.AddComponent<BoxCollider>(); bc.size = new Vector3(0.1f, 0.1f, 0.1f); bc.isTrigger = true; rb.useGravity = false; move = false; orientation = 0; } if (car != null && DataScript.isRunning) { MoveCreation.showControls = false; if (!move) { if (DataScript.moveCtr >= DataScript.moves.Length) { DataScript.isRunning = false; Destroy(car); CrashedMenuController.codeFinished = true; } else { char c = DataScript.moves[DataScript.moveCtr]; switch (c) { case 'F': initForward(); break; case 'R': rotate(true); break; case 'L': rotate(false); break; } DataScript.moveCtr++; } } else { forward(); } } else if (car) { MoveCreation.showControls = true; } PlacingTrack.SetActive(!showSearchingUI && !MoveCreation.showControls && !setCourse); // 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 || setCourse) { 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 { if(renderCar) { // Choose the Andy model for the Trackable that got hit. GameObject prefab; if (hit.Trackable is FeaturePoint) { prefab = AndyPointPrefab; } else { prefab = AndyPlanePrefab; } // Instantiate Andy model at the hit pose. car = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); start = hit.Pose.position; startRotation = hit.Pose.rotation; // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). car.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); initHit = hit; // Make Andy model a child of the anchor. car.transform.parent = anchor.transform; var rb = car.AddComponent<Rigidbody>(); BoxCollider bc = car.AddComponent<BoxCollider>(); bc.size = new Vector3(0.1f, 0.1f, 0.1f); bc.isTrigger = true; rb.useGravity = false; orientation = 0; PlacingTrack.SetActive(false); //GameObject w = Wall; //var obj = Instantiate(w, hit.Pose.position + new Vector3(0.0f, 0.0f, -.12f), hit.Pose.rotation); int[,] path = DataScript.levels[DataScript.level]; for(int i = 0; i<path.GetLength(0); i++) { for (int j = 0; j < path.GetLength(1); j++) { if(path[i,j] == 1) { var w = Wall; var obj = Instantiate(w, hit.Pose.position + new Vector3(0.3f - 0.1f * j, 0.0f,0.1f + -0.1f * i), hit.Pose.rotation); }else if(path[i,j] == 2) { var s = Star; var obj = Instantiate(s,hit.Pose.position + new Vector3(0.3f - 0.1f * j, 0.0f, 0.1f + -0.1f * i), hit.Pose.rotation); var rbStar = obj.AddComponent<Rigidbody>(); rbStar.useGravity = false; rbStar.angularVelocity = new Vector3(0.0f, 0.5f, 0.0f); rbStar.angularDrag = 0; var boxCol = obj.AddComponent<BoxCollider>(); boxCol.size = new Vector3(0.05f, 0.05f, 0.05f); boxCol.isTrigger = true; } } } setCourse = 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 { if (CurrentDataModel.bundlepath == "") { return; } // Instantiate Andy model at the hit pose. var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation); var asset = andyObject.GetComponent <DynamicAsset>(); asset.DataModel = CurrentDataModel; asset.Instantiate(); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). andyObject.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. andyObject.transform.parent = anchor.transform; _anchors.Add(anchor.gameObject); } } }
/// <summary> /// The Unity Update() method. /// </summary> public 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 FeaturePoint) { prefab = GameObjectPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = GameObjectVerticalPlanePrefab; } else { prefab = GameObjectHorizontalPlanePrefab; } } else { prefab = GameObjectHorizontalPlanePrefab; } // hit.Pose.position.Set(hit.Pose.position.x, hit.Pose.position.y + 100f, hit.Pose.position.z); // Instantiate prefab at the hit pose. if (!wasSpawn) { var gameObject = GameObject.Find("EventSystem").GetComponent <constructor>().MyStart(hit.Pose); wasSpawn = true; } // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). //gameObject.transform.Rotate(0, k_PrefabRotation, 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 game object a child of the anchor. gameObject.transform.parent = anchor.transform; //gameObject.transform.position.Set(gameObject.transform.position.x, gameObject.transform.position.y + 100f, gameObject.transform.position.z); } } }
/// <summary> /// The Unity Update() method. /// </summary> public 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 FeaturePoint) { prefab = GameObjectPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = GameObjectVerticalPlanePrefab; } else { prefab = GameObjectHorizontalPlanePrefab; } } else { prefab = GameObjectHorizontalPlanePrefab; } // trying to instantiate only one dragon instead of the many that one can instantiate otherwise in HelloAR orignal code //one dragon is easier to control if (numDragons < 2) { // Instantiate prefab at the hit pose. gameObject2 = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). gameObject2.transform.Rotate(0, k_PrefabRotation, 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 game object a child of the anchor. gameObject2.transform.parent = anchor.transform; numDragons += 1; } //trying to move dragon around based on screen tilt if (Input.deviceOrientation == DeviceOrientation.FaceDown) { gameObject2.transform.Translate(Vector3.forward * Time.deltaTime, Space.World); } if (Input.deviceOrientation == DeviceOrientation.FaceUp) { gameObject2.transform.Translate(Vector3.back * Time.deltaTime, Space.World); } if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) { gameObject2.transform.Translate(Vector3.left * Time.deltaTime, Space.World); } if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { gameObject2.transform.Translate(Vector3.right * Time.deltaTime, Space.World); } if (Input.touchCount > 0) { //if there is any touch touchDuration += Time.deltaTime; touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Ended && touchDuration < 0.2f) //making sure it only check the touch once && it was a short touch/tap and not a dragging. { StartCoroutine("singleOrDouble"); } } else { touchDuration = 0.0f; } } // trying to make the zombie jump on double tap IEnumerator singleOrDouble() { yield return(new WaitForSeconds(0.3f)); if (touch.tapCount == 1) { Debug.Log("Single"); } else if (touch.tapCount == 2) { //this coroutine has been called twice. We should stop the next one here otherwise we get two double tap StopCoroutine("singleOrDouble"); Debug.Log("Double"); gameObject2.transform.Translate(Vector3.up * 260 * Time.deltaTime, Space.World); } } } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { _UpdateApplicationLifecycle(); if (startedDownloading && this.ARCaptLoader.WWWLoader != null && this.ARCaptLoader.WWWLoader.isDone) { startedDownloading = !this.ARCaptLoader.WWWLoader.isDone; if (this.ARCaptLoader.WWWLoader.progress < 1) { this.ARCaptLoader.StatusMsg = "Downloading 3D model.. " + (int)(this.ARCaptLoader.WWWLoader.progress * 100) + "%"; } } if (this.TextMessages.text != this.ARCaptLoader.StatusMsg) { this.TextMessages.text = this.ARCaptLoader.StatusMsg; } // 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 (GroupModel3D != null) { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Began) { oldTouchPosition = Input.GetTouch(0).position.x; } else if (Input.GetTouch(0).phase == TouchPhase.Moved) { if (Math.Abs(oldTouchPosition - Input.GetTouch(0).position.x) < 50) { return; } if (oldTouchPosition > Input.GetTouch(0).position.x) { GroupModel3D.transform.Rotate(0, 5f, 0, Space.Self); } else { GroupModel3D.transform.Rotate(0, -5f, 0, Space.Self); } oldTouchPosition = Input.GetTouch(0).position.x; } } if (Input.touchCount == 2) { this.RotateModel(); } } else { // 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; } // If the mode is still loading, we are done with this update again. if (this.isModelLoading) { 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 { this.Hit = hit; if (string.IsNullOrEmpty(this.ARCaptLoader.ModelPath)) { return; } this.isModelLoading = true; this.ARCaptLoader.StatusMsg = "Loading 3D model. Please wait..."; var loader = new FileLoader(Path.GetDirectoryName(this.ARCaptLoader.ModelPath)); var sceneImporter = new GLTFSceneImporter(this.ARCaptLoader.ModelPath, loader); StartCoroutine(sceneImporter.LoadScene(0, true, OnImportedModel)); } } } }
private static IEnumerator UpdateLoop() { var renderEventFunc = NativeApi.GetRenderEventFunc(); var shouldConvertToBgra = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11; var loggedAspectRatioWarning = false; // Waits until the end of the first frame until capturing the screen size, // because it might be incorrect when first querying it. yield return(k_WaitForEndOfFrame); // Creates a target texture to capture the preview window onto. // Some video encoders prefer the dimensions to be a multiple of 16. var targetWidth = RoundUpToNearestMultipleOf16(Screen.width); var targetHeight = RoundUpToNearestMultipleOf16(Screen.height); var screenTexture = new RenderTexture(targetWidth, targetHeight, 0); var targetTexture = screenTexture; RenderTexture bgrTexture = null; if (shouldConvertToBgra) { bgrTexture = new RenderTexture(screenTexture.width, screenTexture.height, 0, RenderTextureFormat.BGRA32); targetTexture = bgrTexture; } // Begins update loop. The coroutine will cease when the // ARCoreSession component it's called from is destroyed. for (;;) { yield return(k_WaitForEndOfFrame); NativeApi.Update(); InstantPreviewInput.Update(); AddInstantPreviewTrackedPoseDriverWhenNeeded(); Graphics.Blit(null, screenTexture); if (shouldConvertToBgra) { Graphics.Blit(screenTexture, bgrTexture); } var cameraTexture = Frame.CameraImage.Texture; if (!loggedAspectRatioWarning && cameraTexture != null) { var sourceWidth = cameraTexture.width; var sourceHeight = cameraTexture.height; var sourceAspectRatio = (float)sourceWidth / sourceHeight; var destinationWidth = Screen.width; var destinationHeight = Screen.height; var destinationAspectRatio = (float)destinationWidth / destinationHeight; if (Mathf.Abs(sourceAspectRatio - destinationAspectRatio) > k_MaxTolerableAspectRatioDifference) { Debug.LogWarning(string.Format(k_MismatchedAspectRatioWarningFormatString, sourceWidth, sourceHeight)); loggedAspectRatioWarning = true; } } NativeApi.SendFrame(targetTexture.GetNativeTexturePtr()); GL.IssuePluginEvent(renderEventFunc, 1); } }
private static IEnumerator UpdateLoop(string adbPath) { var renderEventFunc = NativeApi.GetRenderEventFunc(); var shouldConvertToBgra = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11; var loggedAspectRatioWarning = false; // Waits until the end of the first frame until capturing the screen size, // because it might be incorrect when first querying it. yield return(k_WaitForEndOfFrame); var currentWidth = 0; var currentHeight = 0; var needToStartActivity = true; var prevFrameLandscape = false; RenderTexture screenTexture = null; RenderTexture targetTexture = null; RenderTexture bgrTexture = null; // Begins update loop. The coroutine will cease when the // ARCoreSession component it's called from is destroyed. for (;;) { yield return(k_WaitForEndOfFrame); var curFrameLandscape = Screen.width > Screen.height; if (prevFrameLandscape != curFrameLandscape) { needToStartActivity = true; } prevFrameLandscape = curFrameLandscape; if (needToStartActivity) { string activityName = curFrameLandscape ? "InstantPreviewLandscapeActivity" : "InstantPreviewActivity"; string output; string errors; ShellHelper.RunCommand(adbPath, "shell am start -S -n com.google.ar.core.instantpreview/." + activityName, out output, out errors); needToStartActivity = false; } // Creates a target texture to capture the preview window onto. // Some video encoders prefer the dimensions to be a multiple of 16. var targetWidth = RoundUpToNearestMultipleOf16(Screen.width); var targetHeight = RoundUpToNearestMultipleOf16(Screen.height); if (targetWidth != currentWidth || targetHeight != currentHeight) { screenTexture = new RenderTexture(targetWidth, targetHeight, 0); targetTexture = screenTexture; if (shouldConvertToBgra) { bgrTexture = new RenderTexture( screenTexture.width, screenTexture.height, 0, RenderTextureFormat.BGRA32); targetTexture = bgrTexture; } currentWidth = targetWidth; currentHeight = targetHeight; } NativeApi.Update(); InstantPreviewInput.Update(); if (NativeApi.AppShowedTouchWarning()) { Debug.LogWarning(k_InstantPreviewInputWarning); NativeApi.UnityLoggedTouchWarning(); } AddInstantPreviewTrackedPoseDriverWhenNeeded(); Graphics.Blit(null, screenTexture); if (shouldConvertToBgra) { Graphics.Blit(screenTexture, bgrTexture); } var cameraTexture = Frame.CameraImage.Texture; if (!loggedAspectRatioWarning && cameraTexture != null) { var sourceWidth = cameraTexture.width; var sourceHeight = cameraTexture.height; var sourceAspectRatio = (float)sourceWidth / sourceHeight; var destinationWidth = Screen.width; var destinationHeight = Screen.height; var destinationAspectRatio = (float)destinationWidth / destinationHeight; if (Mathf.Abs(sourceAspectRatio - destinationAspectRatio) > k_MaxTolerableAspectRatioDifference) { Debug.LogWarningFormat( k_MismatchedAspectRatioWarningFormatString, sourceAspectRatio, destinationAspectRatio, sourceWidth, sourceHeight); loggedAspectRatioWarning = true; } } NativeApi.SendFrame(targetTexture.GetNativeTexturePtr()); GL.IssuePluginEvent(renderEventFunc, (int)ApiRenderEvent.UpdateCubemapTexture); } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { _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]); } // 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 || (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)) { StartCoroutine(WaitForReq()); castle = Instantiate(castle, hit.Pose.position, hit.Pose.rotation); //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 = FirstPersonCamera.transform.position; cameraPositionSameY.y = hit.Pose.position.y; // Have Andy look toward the camera respecting his "up" perspective, which may be from ceiling. castle.transform.LookAt(cameraPositionSameY, castle.transform.up); } // Make Andy model a child of the anchor. castle.transform.parent = anchor.transform; } }
/// <summary> /// The Unity Update() method. /// </summary> public void UpdateObjectPlacer() { _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; } //Check if it collided with another object if (!IsReplacing && !IsPlacing) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit firstHit; if (Physics.Raycast(ray, out firstHit)) { if (firstHit.collider.tag == "Object") { IsPlacing = true; IsReplacing = true; //SELECT OBJECT SelectedObject = firstHit.collider.gameObject; AppManager.Instance.ActivatePlacingUI(); //CHANTE MATERIAL ChangeObjectMaterial(SelectedObject, SelectedColor); 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 Andy model for the Trackable that got hit. GameObject prefab; //Remove trackable points intantiation if (hit.Trackable is FeaturePoint) { prefab = AndyPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { //Vertical prefab = CurrentCatalogObject.Prefab; } else { //Horizontal plane prefab = CurrentCatalogObject.Prefab; } } else { //Horizontal prefab = CurrentCatalogObject.Prefab; } GameObject andyObject; if (IsPlacing) { if (IsReplacing) { andyObject = SelectedObject; andyObject.transform.position = hit.Pose.position; andyObject.transform.rotation = hit.Pose.rotation; } else { andyObject = placedModels[placedModels.Count - 1]; andyObject.transform.position = hit.Pose.position; andyObject.transform.rotation = hit.Pose.rotation; } } //If not placing a object, Instantiante new one else { //// Instantiate Andy model at the hit pose. andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); placedModels.Add(andyObject); IsPlacing = true; // 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. andyObject.transform.parent = anchor.transform; //CHANGE COLOR ChangeObjectMaterial(andyObject, SelectedColor); AppManager.Instance.ActivatePlacingUI(); } // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self); } } }
/// <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 there are two touches on the device... if (PenguinBehaviour.Pengnum == (int)ModelConst.M_NUMBER && Input.touchCount == 2) { // Store both touches. Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); // Find the position in the previous frame of each touch. Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; // Find the magnitude of the vector (the distance) between the touches in each frame. float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; // Find the difference in the distances between each frame. float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; Vector3 m_anchorvec = m_anchor.transform.localScale; m_anchorvec += new Vector3(0.01f, 0.01f, 0.01f) * deltaMagnitudeDiff; m_anchorvec.x = Mathf.Clamp(m_anchorvec.x, 0.5f, 2.5f); m_anchorvec.y = Mathf.Clamp(m_anchorvec.y, 0.5f, 2.5f); m_anchorvec.z = Mathf.Clamp(m_anchorvec.z, 0.5f, 2.5f); m_anchor.transform.localScale = m_anchorvec; } // 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 CUSTOM // button control part using raycast #region /* * switch (touch.phase) * { * case TouchPhase.Began: * Vector3 touchPosToVector3 = new Vector3(touch.position.x, touch.position.y, 100); * //touchPos = FirstPersonCamera.ScreenToWorldPoint(touchPosToVector3); * ray = FirstPersonCamera.ScreenPointToRay(touchPosToVector3); * * // thrid param : distance * if (Physics.Raycast(ray, out rayhit, 100)) * { * if (rayhit.collider.tag == "Cube") * { * // maybe can approach animator of parent * // rayhit.collider.GetComponentsInParent<>; * animator.SetTrigger(atkhash); * return; * } * } * break; * case TouchPhase.Moved: * // 터치 이동 시. * // Debug.Log("터치 이동"); * break; * * case TouchPhase.Stationary: * // 터치 고정 시. * // Debug.Log("터치 고정"); * break; * * case TouchPhase.Ended: * // 터치 종료 시. ( 손을 뗐을 시 ) * // Debug.Log("터치 종료"); * break; * * case TouchPhase.Canceled: * // 터치 취소 시. ( 시스템에 의해서 터치가 취소된 경우 (ex: 전화가 왔을 경우 등) ) * // Debug.Log("터치 취소"); * break; * } */ #endregion // put model on the polygon floor if (PenguinBehaviour.Pengnum < (int)ModelConst.M_NUMBER && 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 Andy model for the Trackable that got hit. // Animator needed for each instantiated GameObject GameObject prefab; GameObject eprefab; // Animator animator; if (hit.Trackable is FeaturePoint) { //prefab = CustomPrefab; return; } else { prefab = CustomPrefab; eprefab = EnvironPrefab; } // Instantiate Andy model at the hit pose. //hit.Pose.position + new Vector3(0, 0.1f, 0); var customObject = Instantiate(prefab, hit.Pose.position + new Vector3(0, 0.005f, 0), hit.Pose.rotation); var customEnvironObject = Instantiate(eprefab, hit.Pose.position + new Vector3(0, 0.005f, 0), hit.Pose.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). customObject.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. customObject.transform.parent = anchor.transform; customEnvironObject.transform.parent = anchor.transform; m_anchor = anchor; //GameObject.Find("Plane Generator").transform.chi Transform trPlaneGenObj = GameObject.Find("Plane Generator").transform; for (int i = 0; i < trPlaneGenObj.childCount; i++) { trPlaneGenObj.GetChild(i).gameObject.SetActive(false); } ButtonContainer.SetActive(true); GameObject.Find("peng_roundimg").SetActive(false); #else 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 Andy model for the Trackable that got hit. GameObject prefab; if (hit.Trackable is FeaturePoint) { prefab = AndyPointPrefab; } else { prefab = AndyPlanePrefab; } // Instantiate Andy model at the hit pose. var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). andyObject.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. andyObject.transform.parent = anchor.transform; #endif } } }
/// <summary> /// The Unity Update() method. /// </summary> public 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 (Session.Status == SessionStatus.LostTracking) { spawned = false; var session = GameObject.Find("ARCore Device").GetComponent <ARCoreSession>(); session.SessionConfig.PlaneFindingMode = DetectedPlaneFindingMode.Horizontal; session.SessionConfig.EnablePlaneFinding = true; session.OnEnable(); } if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && !spawned) { var session = GameObject.Find("ARCore Device").GetComponent <ARCoreSession>(); session.SessionConfig.PlaneFindingMode = DetectedPlaneFindingMode.Disabled; session.SessionConfig.EnablePlaneFinding = false; session.OnEnable(); spawned = true; // 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; prefab = GameObjectHorizontalPlanePrefab; /*if (hit.Trackable is FeaturePoint) * { * //prefab = GameObjectPointPrefab; * } * else if (hit.Trackable is DetectedPlane) * { * DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; * prefab = GameObjectHorizontalPlanePrefab; * } * else * { * prefab = GameObjectHorizontalPlanePrefab; * }*/ // Instantiate prefab at the hit pose. var gameObject1 = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); gameObject1.SetActive(true); // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). gameObject1.transform.Rotate(0, k_PrefabRotation, 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 game object a child of the anchor. gameObject1.transform.parent = anchor.transform; GameObject dragon = gameObject1.GetComponent <Level>().dragon; dragonController.Dragon = dragon.transform; gameObject1.transform.localEulerAngles = new Vector3(0, 360, 0); //dragonController.Dragon.transform.localEulerAngles = new Vector3(0, 360, 0); dragonController.gameObject.SetActive(true); } } }
/// <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 <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]); } // 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)) { if (currentNumberOfObjects < numberOfObjectsAllowed) { currentNumberOfObjects = currentNumberOfObjects + 1; var catObject = Instantiate(m_ObjectPrefeb, 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 = FirstPersonCamera.transform.position; cameraPositionSameY.y = hit.Pose.position.y; // Have Andy look toward the camera respecting his "up" perspective, which may be from ceiling. catObject.transform.LookAt(cameraPositionSameY, catObject.transform.up); } // Make Andy model a child of the anchor. catObject.transform.parent = anchor.transform; } /* * * if (Input.touchCount == 2||currentNumberOfObjects==numberOfObjectsAllowed) * { * * //store the both touch * * Touch touch1 = Input.GetTouch(0); * Touch touch2 = Input.GetTouch(1); * * //Find the position of the previous fream of each touch * Vector2 touch1PrePos = touch1.position - touch1.deltaPosition; * Vector2 touch2PrePos = touch2.position - touch2.deltaPosition; * * //find the magnitude of the vector * float prevTouchDeltaMag = (touch1PrePos - touch2PrePos).magnitude; * float touchDeltaMag = (touch1.position - touch2.position).magnitude; * //find the difference betwwen the magnitude * * float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; * * // Change the scale based on the change in distance between the touches. * * FirstPersonCamera.fieldOfView += deltaMagnitudeDiff * ZoomSpeed; * FirstPersonCamera.fieldOfView = Mathf.Clamp(FirstPersonCamera.fieldOfView, .1f, 179.9f); * * } */ } //if there are two touch on the screen //To check the zooming option }
public void Update() { // Exit the app when the 'back' button is pressed. if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } if (CrossPlatformInputManager.GetButtonDown("Restart")) { //Application.Quit(); m_hasCreateBattle = false; TouchControls.SetActive(false); if (battleGO != null) { DestroyImmediate(battleGO); } } _QuitOnConnectionErrors(); // Check that motion tracking is tracking. if (Session.Status != SessionStatus.Tracking)//mata mod { 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;//mata mod 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) && !m_hasCreateBattle) { battleGO = 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 = FirstPersonCamera.transform.position; cameraPositionSameY.y = hit.Pose.position.y;//相机在地板上的投影点。 var lookAtPos = battleGO.transform.position - (cameraPositionSameY - battleGO.transform.position); // Have Andy look toward the camera respecting his "up" perspective, which may be from ceiling. //andyObject.transform.LookAt(andyObject.transform.position + Vector3.forward, anchor.transform.up); battleGO.transform.LookAt(lookAtPos, anchor.transform.up); } // Make Andy model a child of the anchor. battleGO.transform.parent = anchor.transform; m_hasCreateBattle = true; TouchControls.SetActive(true); //dualTouchControls = (GameObject)Instantiate(Resources.Load("Standard_Assets/CrossPlatformInput/Prefabs/DualTouchControls")); } }
public void Update() { UpdateApplicationLifecycle(); if (gameObjectTemp != null) { gameObjectTemp.transform.Rotate(0, SliderRotate.value, 0, Space.Self); gameObjectTemp.transform.localScale += SliderScale.value * scale; } // 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; bool foundHit = false; if (InstantPlacementMenu.IsInstantPlacementEnabled()) { foundHit = Frame.RaycastInstantPlacement(touch.position.x, touch.position.y, 1.0f, out hit); } else { TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; foundHit = Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit); } if (foundHit) { // Choose the gameobject to place if (GameObjectIndex == 0) { GameObjectVerticalPlanePrefab = GameObjectRobot; GameObjectHorizontalPlanePrefab = GameObjectRobot; GameObjectPointPrefab = GameObjectRobot; InstantPlacementPrefab = GameObjectRobot; } else if (GameObjectIndex == 1) { GameObjectVerticalPlanePrefab = GameObjectFox; GameObjectHorizontalPlanePrefab = GameObjectFox; GameObjectPointPrefab = GameObjectFox; InstantPlacementPrefab = GameObjectFox; } else if (GameObjectIndex == 2) { GameObjectVerticalPlanePrefab = GameObjectCat; GameObjectHorizontalPlanePrefab = GameObjectCat; GameObjectPointPrefab = GameObjectCat; InstantPlacementPrefab = GameObjectCat; } else if (GameObjectIndex == 3) { GameObjectVerticalPlanePrefab = GameObjectWindow; GameObjectHorizontalPlanePrefab = GameObjectWindow; GameObjectPointPrefab = GameObjectWindow; InstantPlacementPrefab = GameObjectWindow; } // 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 { if (DepthMenu != null) { // Show depth card window if necessary. DepthMenu.ConfigureDepthBeforePlacingFirstAsset(); } // Choose the prefab based on the Trackable that got hit. GameObject prefab; if (hit.Trackable is InstantPlacementPoint) { prefab = InstantPlacementPrefab; } else if (hit.Trackable is FeaturePoint) { prefab = GameObjectPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = GameObjectVerticalPlanePrefab; } else { prefab = GameObjectHorizontalPlanePrefab; } } else { prefab = GameObjectHorizontalPlanePrefab; } // Instantiate prefab at the hit pose. gameObjectTemp = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // Compensate for the hitPose rotation facing away from the raycast if (GameObjectIndex != 3) { gameObjectTemp.transform.Rotate(0, _prefabRotation, 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 game object a child of the anchor. gameObjectTemp.transform.parent = anchor.transform; // Initialize Instant Placement Effect. if (hit.Trackable is InstantPlacementPoint) { gameObjectTemp.GetComponentInChildren <InstantPlacementEffect>().InitializeWithTrackable(hit.Trackable); } } } }
/// <summary> /// The Unity Update() method. /// </summary> public 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 FeaturePoint) { prefab = GameObjectPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = GameObjectVerticalPlanePrefab; } else { prefab = GameObjectHorizontalPlanePrefab; } } else { prefab = GameObjectHorizontalPlanePrefab; } //// Instantiate prefab at the hit pose. //var gameObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); //// Compensate for the hitPose rotation facing away from the raycast (i.e. //// camera). //gameObject.transform.Rotate(0, k_PrefabRotation, 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); // Выровнять якорь по горизонтали Vector3 myEu = anchor.transform.eulerAngles; myEu.x = 0.0f; myEu.z = 0.0f; //// Make game object a child of the anchor. //gameObject.transform.parent = anchor.transform; // Скрыть генератор поверхностей _PlaneGen.SetActive(false); // Открыть объекты сцены _GO_Root.transform.parent = anchor.transform; _GO_Root.transform.localPosition = Vector3.zero; _GO_Root.transform.localEulerAngles = Vector3.zero; _GO_Root.SetActive(true); _Text1.text = "Pos=" + _GO_Root.transform.position.ToString() + " Eu=" + _GO_Root.transform.eulerAngles.ToString(); // Установить поле зрения 45 градусов FirstPersonCamera.fieldOfView = 45; _RightCam.fieldOfView = 45; } } }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { //if (Input.GetMouseButtonDown(0)) //{ // Vector3 pos; // pos.x = Random.Range(-2.0f, 2.0f); // pos.z = Random.Range(-2.0f, 2.0f); // pos.y = 0; // var andyObject = Instantiate(AndyPlanePrefab, pos, Quaternion.identity); // Points.Add(andyObject); // if (Points.Count >= 2) // { // andyObject.GetComponent<LineRenderer>().positionCount = 2; // andyObject.GetComponent<LineRenderer>().SetPosition(0, andyObject.transform.position); // andyObject.GetComponent<LineRenderer>().SetPosition(1, Points[Points.Count - 2].transform.position); // var temp = Instantiate( // Text, // (andyObject.transform.position + Points[Points.Count - 2].transform.position) / 2, Quaternion.identity); // temp.transform.LookAt(andyObject.transform.position); // temp.transform.localEulerAngles = new Vector3(90, temp.transform.localEulerAngles.y + 90, 0); // temp.GetComponent<TextMesh>().text = // (Vector3.Distance( // andyObject.transform.position, // Points[Points.Count - 2].transform.position) * 100).ToString("0.00"); // } //} _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 { // Choose the Andy model for the Trackable that got hit. GameObject prefab; if (hit.Trackable is FeaturePoint) { prefab = AndyPointPrefab; } else { prefab = AndyPlanePrefab; } // Instantiate Andy model at the hit pose. var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // Our part; create ruler. Points.Add(andyObject); if (Points.Count >= 2) { andyObject.GetComponent <LineRenderer>().positionCount = 2; andyObject.GetComponent <LineRenderer>().SetPosition(0, andyObject.transform.position); andyObject.GetComponent <LineRenderer>().SetPosition(1, Points[Points.Count - 2].transform.position); var temp = Instantiate( Text, (andyObject.transform.position + Points[Points.Count - 2].transform.position) / 2, Quaternion.identity); temp.transform.LookAt(andyObject.transform.position); temp.transform.localEulerAngles = new Vector3(90, temp.transform.localEulerAngles.y + 90, 0); temp.GetComponent <TextMesh>().text = (Vector3.Distance( andyObject.transform.position, Points[Points.Count - 2].transform.position) * 100).ToString("0.00"); } // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). andyObject.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. andyObject.transform.parent = anchor.transform; } } }
public 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 FeaturePoint) { prefab = GameObjectPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = GameObjectVerticalPlanePrefab; } else { prefab = GameObjectHorizontalPlanePrefab; } } else { prefab = GameObjectHorizontalPlanePrefab; } // Instantiate prefab at the hit pose. var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); Points.Add(andyObject); if (Points.Count >= 2) { andyObject.GetComponent <LineRenderer>().positionCount = 2; andyObject.GetComponent <LineRenderer>().SetPosition(0, andyObject.transform.position); andyObject.GetComponent <LineRenderer>().SetPosition(1, Points[Points.Count - 2].transform.position); var temp = Instantiate(Text, (andyObject.transform.position + Points[Points.Count - 2].transform.position) / 2, Quaternion.identity); temp.transform.LookAt(andyObject.transform.position); temp.transform.localEulerAngles = new Vector3(90, temp.transform.localEulerAngles.y + 90, 0); temp.GetComponent <TextMesh>().text = (Vector3.Distance(andyObject.transform.position, Points[Points.Count - 2].transform.position) * 100).ToString("0.00"); } // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). andyObject.transform.Rotate(0, k_PrefabRotation, 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 game object a child of the anchor. andyObject.transform.parent = anchor.transform; } } }
/// <summary> /// The Unity Update() method. /// </summary> public 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 Andy model for the Trackable that got hit. GameObject prefab = NewTurbine; ////if (hit.Trackable is FeaturePoint) //{ // prefab = NewTurbine; //} //else //{ // prefab = NewTurbine; //} // Instantiate Andy model at the hit pose. var TurbineObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). //TurbineObject.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. TurbineObject.transform.parent = anchor.transform; } } RotorGroup[0].transform.Rotate(0, 0, -1 * Time.deltaTime * rotationSpeed); }
/// <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; * } * }*/ //change this line for instantiating other things if (alreadyDetect) { return; } //SearchingForPlaneUI.SetActive(showSearchingUI); //Debug.Log ("touch count in controller: " + Input.touchCount); // 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; // Raycast against the location the player touched to search for planes. if (Application.platform != RuntimePlatform.IPhonePlayer) { TrackableHit hit; if (Frame.Raycast(touch.position.x, touch.position.y, TrackableHitFlags.PlaneWithinPolygon, out hit)) { m_LastPlacedAnchor = hit.Trackable.CreateAnchor(hit.Pose); } } else { Pose hitPose; if (m_ARKit.RaycastPlane(FirstPersonCamera, touch.position.x, touch.position.y, out hitPose)) { m_LastPlacedAnchor = m_ARKit.CreateAnchor(hitPose); } } if (m_LastPlacedAnchor != null) { // Instantiate Andy model at the hit pose. if (!alreadyDetect) { var andyObject = Instantiate(AndyAndroidPrefab, m_LastPlacedAnchor.transform.position, m_LastPlacedAnchor.transform.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self); // Make Andy model a child of the anchor. andyObject.transform.parent = m_LastPlacedAnchor.transform; alreadyDetect = true; } else { //instantiate curve with an anchor attached var curveObject = Instantiate(curvePrefab, m_LastPlacedAnchor.transform.position, m_LastPlacedAnchor.transform.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). curveObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self); // Make Andy model a child of the anchor. curveObject.transform.parent = m_LastPlacedAnchor.transform; curveDetected = true; } } }