bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { var overScene = CanvasManager.SCENE_UNDER_CANVAS; List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0 && !mapWasShown && planeAppeared && !overScene) { mapWasShown = true; foreach (var hitResult in hitResults) { m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); m_HitTransform.localScale = new Vector3(resultScale, resultScale, resultScale); Vector3 currAngle = m_HitTransform.eulerAngles; m_HitTransform.LookAt(Camera.main.transform); m_HitTransform.eulerAngles = new Vector3(currAngle.x, m_HitTransform.eulerAngles.y + 180f, currAngle.z); Transform map; for (int i = 0; i < m_HitTransform.childCount; i++) { map = m_HitTransform.GetChild(i); if (map.name == "Map") { MAP = map.gameObject; MAP.GetComponent <Animator>().SetInteger("mapAnimTransition", SHOW_MAP_ANIM); spawnScript = MAP.GetComponent <SpawnOnMap> (); m_HitTransform.gameObject.GetComponent <LeanScale>().enabled = true; if (CanvasController.isFirstSession) { ccontroller.show_info_Button(); } } } generate_script.getManager().HidePrefabs(); ccontroller.hide_about_map_text(); ccontroller.show_screenShot_btn(); ccontroller.show_reload_btn(); return(true); } } return(false); }
public List <ARHitTestResult> HitTest(ARPoint point, ARHitTestResultType types) { #if !UNITY_EDITOR int numResults = HitTest(m_NativeARSession, point, types); List <ARHitTestResult> results = new List <ARHitTestResult>(); for (int i = 0; i < numResults; ++i) { var result = GetLastHitTestResult(i); results.Add(GetHitTestResultFromResultData(result)); } return(results); #else return(new List <ARHitTestResult>()); #endif }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return(true); } } return(false); }
// Update is called once per frame void Update() { #if UNITY_EDITOR //we will only use this script on the editor side, though there is nothing that would prevent it from working on device Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)); RaycastHit hit; //we'll try to hit one of the plane collider gameobjects that were generated by the plugin //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent if (Physics.Raycast(ray, out hit, maxRayDistance, collisionLayer)) { //we're going to get the position from the contact point m_HitTransform.position = hit.point; Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); //and the rotation from the transform of the plane collider m_HitTransform.rotation = hit.transform.rotation; } #else var screenPosition = Camera.main.ScreenToViewportPoint(new Vector2(Screen.width / 2, Screen.height / 2)); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, //ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane, //ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane, //ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } #endif }
// Update is called once per frame void Update () { // #if UNITY_EDITOR //we will only use this script on the editor side, though there is nothing that would prevent it from working on device // if (Input.GetMouseButtonDown (0)) { // Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); // RaycastHit hit; // //we'll try to hit one of the plane collider gameobjects that were generated by the plugin // //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent // if (Physics.Raycast (ray, out hit, maxRayDistance, collisionLayer)) { // //we're going to get the position from the contact point // m_HitTransform.position = hit.point; // Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); // //and the rotation from the transform of the plane collider // m_HitTransform.rotation = hit.transform.rotation; // } // } // #else if (Input.touchCount > 0 && m_HitTransform != null) { var touch = Input.GetTouch (0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint (touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType (point, resultType)) { return; } } } } // #endif }
public LayerMask collisionLayer = 1 << 10; //ARKitPlane layer bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.position += new Vector3(0f, bounceHeight, 0f); //m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform); m_HitTransform.rotation = Random.rotation; return(true); } } return(false); }
public void SetPosition() { // Project from the middle of the screen to look for a hit point on the detected surfaces. var screenPosition = Camera.main.ScreenToViewportPoint(new Vector2(Screen.width / 2f, Screen.height / 2f)); //var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } // ARPoint pt = new ARPoint { // x = screenPosition.x, // y = screenPosition.y // }; // // // Try to hit within the bounds of an existing AR plane. // List<ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface ().HitTest ( // pt, // ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent); // // if (hitResults.Count > 0) { // If a hit is found, set the position and reset the rotation. // transform.rotation = Quaternion.Euler (Vector3.zero); // transform.position = UnityARMatrixOps.GetPosition (hitResults[0].worldTransform); // } }
// Update is called once per frame void Update() { //螢幕觸控 if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.name == "HitCube") { gameObject.SetActive(false); } } } if (Input.touchCount > 0 && m_HitTransform != null) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } } } }
// Update is called once per frame void Update() { //#else if (Input.touchCount > 0 && m_HitTransform != null) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { if (cube.isBeingCarried) { cube.DropCube(); } else { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, //ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane, //ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane, //ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } } } } }
public LayerMask collisionLayer = 1 << 10; //ARKitPlane layer bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); // see if any valid places nearby to put kitten if (hitResults.Count > 0) // if there's a valid place to put the kitten { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); // move the kitten to the first valid position where the user dragged to m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); // adjust rotation as necessary m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); //Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return(true); } } return(false); }
bool DoARRaycast(Touch touch, ref ARHitTestResult hitOut) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint() { x = screenPosition.x, y = screenPosition.y }; var hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent); if (hitResults.Count < 1) { return(false); } hitOut = hitResults[0]; return(true); }
// Update is called once per frame void Update() { if (Input.touchCount > 0 && m_HitTransform != null && !alreadyHit) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { // ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { if (!mapLoaded) { Debug.Log("About to load map."); mapLoaded = true; alreadyHit = true; loadUnits(); // generatePlanes.SetActive(false); // generatePlanes.GetComponent<UnityARGeneratePlane> ().enabled = false; // pointCloud.SetActive (false); } return; } } } } }
/* * * * * * * * Private Methods * * * * * * */ bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { parentTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); parentTransform.position += new Vector3(0, 0.1f, 0); parentTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); GetMapMaterialReferences(); SetMapMaterialClipping(); mapPlane = new Plane(m_HitTransform.up, m_HitTransform.position); return(true); } } return(false); }
// Update is called once per frame void Update() { if (Input.touchCount > 0 && m_HitTransform != null) { var touch = Input.GetTouch(0); int id = touch.fingerId; if (EventSystem.current.IsPointerOverGameObject(id)) { //return if ui touched return; } if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } } } }
// Update is called once per frame void Update() { #if UNITY_IOS if (Input.touchCount > 0) { if (!EventSystem.current.IsPointerOverGameObject()) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: ARHitTestResultType.ARHitTestResultTypeExistingPlane, //ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, //ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } } } } #endif }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { GameObject go = new GameObject(); go.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); Vector3 p = go.transform.position; p.y += 0.3f; go.transform.position = p; go.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); // Create new sphere Instantiate(sphere, go.transform); return(true); } } return(false); }
//private bool test = false; //private Vector3 original = new Vector3(0.025f, 0.025f, 0.025f); //private Vector3 changed = new Vector3(0.05f, 0.05f, 0.05f); bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { Debug.Log("Got hit!"); foreach (var hitResult in hitResults) { m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); Debug.Log(string.Format("HitTest::: x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); // Make the portal to always be facing camera on spawn //Vector3 currAngle = transform.eulerAngles; //transform.LookAt(Camera.main.transform); //transform.eulerAngles = new Vector3(currAngle.x, transform.eulerAngles.y, currAngle.z); return(true); } } return(false); }
void UpdatePositionIfARScrewUp(ARPlaneAnchor arPlaneAnchor) { ARPoint point = new ARPoint { x = transform.position.x, y = transform.position.z }; List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { //Debug.Log ("Got hit!"); transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); //transform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform); //Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", transform.position.x, transform.position.y, transform.position.z)); } } }
// Update is called once per frame void Update() { if (Input.touchCount > 0 && m_HitTransform != null && !binPlaced) //if (m_HitTransform != null && !binPlaced) { print("bin placed false after touch"); var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { //if( IsPointerOverUIObject(touch) ){ var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); print(screenPosition); print("screen position"); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } //} } } }
//Method for checking intersections bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Hit a surface!"); //Calculate the direction Vector3 N = Camera.main.transform.position - gameObject.transform.position; //Create a look rotation to always face the camera gameObject.transform.rotation = Quaternion.LookRotation(N); return(true); } } return(false); }
// Update is called once per frame void Update() { if (Input.touchCount > 0 && universe.transform != null && countTap < 1) //countTap < 1 to place the sphere once { //initialise getLocation manager.GetComponent <getLocation>().enabled = true; var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } } countTap++; enabled = false; } }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes, GameObject prefab) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); Vector3 pos = UnityARMatrixOps.GetPosition(hitResult.worldTransform); float posy = 0.5f + pos.y; pos = new Vector3(pos.x, posy, pos.z); Quaternion rot = UnityARMatrixOps.GetRotation(hitResult.worldTransform); Instantiate(prefab, pos, rot); // Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return(true); } } return(false); }
private void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); //Handle movement based on touch phase. switch (touch.phase) { //Record initial touch position case TouchPhase.Began: ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); if (Physics.Raycast(ray, out hit)) { if (hit.collider.name == "Player") { } } break; case TouchPhase.Moved: if (Physics.Raycast(ray, out hit)) { if (hit.collider.name == "Player") { float distance_to_screen = Camera.main.WorldToScreenPoint(hit.transform.position).z; Vector2 screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; hit.transform.position = (Camera.main.ScreenToWorldPoint(new Vector3((float)point.x, (float)point.y, distance_to_screen))); } } break; } } }
// Update is called once per frame void Update() { if (Input.touchCount == 1 && m_HitTransform != null) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; if (screenPosition.y < .1) { return; } // prioritize reults types ARHitTestResultType[] resultTypes = { ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType(point, resultType)) { return; } } } } }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); if (IsHorizontal) { Vector3 currAngle = PortalRoom.transform.eulerAngles; PortalRoom.transform.position = FocusEllipse.FoundEllipse.transform.position; //PortalRoom.transform.LookAt (Camera.main.transform); PortalRoom.transform.eulerAngles = new Vector3(currAngle.x, Camera.main.transform.eulerAngles.y, currAngle.z); PortalRoom.SetActive(true); PortalController.OutsidePortal(); } else { Wall.SetActive(true); ResetWall(); CanvasController.ShowResetButton(); } _isPlaced = true; CanvasController.ScanImage.SetActive(false); Debug.Log("Call hide image"); FocusEllipse.IsScanning = false; FocusEllipse.HideFoundEllipse(); return(true); } } return(false); }
public void AddAnchor(ARPlaneAnchor arPlaneAnchor) { if (_floorDetectionStatus == FloorDetectionStatus.Finding) { if (_debug) { debugMessage.text = "Anchor added"; } Debug.Log("New Anchor added"); // Get point of battle field by using ray from center of display to detected floor and Vector3 center = new Vector3(Screen.width / 2, Screen.height / 2, 0.5f); var screenPosition = Camera.main.ScreenToViewportPoint(center); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlane); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { _basePoint = UnityARMatrixOps.GetPosition(hitResult.worldTransform) + _baseVector; } } // Change floor detection status to detected _floorDetectionStatus = FloorDetectionStatus.Found; Debug.Log("Floor detected"); mainMessage.text = "Detection Complete"; // Invoke StartGame() with delay Invoke("StartGame", 0.5f); } }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { //平面と当たっていた場合 List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); if (isCreated == false) { m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); Gametrans.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); this.gameObject.transform.position = m_HitTransform.position; this.gameObject.transform.rotation = m_HitTransform.rotation; anim = GetComponent <Animator>(); //このスクリプトがアサインされたキャラクターのアニメーターコントローラーを取得 audioSource = GetComponent <AudioSource>(); //AudioSourceを使えるようにする isCreated = true; } //if(Gametrans.position.x > gameObject.transform.position.x && Gametrans.position.z > gameObject.transform.position.z) //{ //transform.position += (Vector3.right * x + Vector3.forward * z) * Time.deltaTime; //} //Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return(true); } } return(false); }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); transposition = m_HitTransform.position; transorientation = m_HitTransform.rotation; spawnlogo(); //Vector3 relativePosition = transposition - GenerateImageAnchor.GenerateImageAnchorInstance.markerPosition; //Debug.Log (string.Format ("Relative Position: x:{0:0.######} y:{1:0.######} z:{2:0.######}", relativePosition.x, relativePosition.y, relativePosition.z)); //Debug.Log (string.Format(("Rotation: x:{0:0.######} y:{1:0.######} z:{2:0.######}"), transorientation.x, transorientation.y, transorientation.z)); return(true); } } return(false); }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log("Got hit!"); Vector3 p = UnityARMatrixOps.GetPosition(hitResult.worldTransform); if (can_create_new_obj) { CreateObj(new Vector3(p.x, p.y - 0.5f, p.z)); } else { //MoveObj (new Vector3 (m_HitTransform.position.x, m_HitTransform.position.y - 0.5f, m_HitTransform.position.z)); } return(true); } } return(false); }
bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes) { List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { //pontura: iosCameraManager.PlaneDetectionOFF(); Game game = m_HitTransform.gameObject.GetComponentInChildren <Game> (); game.Init(); done = true; // Debug.Log ("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform); // Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return(true); } } return(false); }