Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
        {
            //do coordinate conversion from ARKit to Unity
            plane.transform.position   = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
            plane.transform.rotation   = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);
            plane.transform.localScale = new Vector3(arPlaneAnchor.extent.x, 1f, arPlaneAnchor.extent.z);


            /*
             *          MeshFilter mf = plane.GetComponentInChildren<MeshFilter> ();
             *
             *          if (mf != null) {
             *  //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
             *  mf.gameObject.transform.localScale = new Vector3(arPlaneAnchor.extent.x * 0.1f ,arPlaneAnchor.extent.y * 0.1f ,arPlaneAnchor.extent.z * 0.1f );
             *
             *  //convert our center position to unity coords
             *  mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x,arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
             *          }
             *
             */

            return(plane);
        }
Esempio n. 3
0
        bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
        {
            List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

            if (hitResults.Count > 0)
            {
                foreach (var hitResult in hitResults)
                {
                    if (!string.IsNullOrEmpty(this.m_AnchorId))
                    {
                        UnityARSessionNativeInterface.GetARSessionNativeInterface().RemoveUserAnchor(this.m_AnchorId);
                    }
                    m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    m_HitTransform.rotation = Quaternion.identity;                    // UnityARMatrixOps.GetRotation (hitResult.worldTransform);
                    FaceToward.SetFacing(m_HitTransform, Camera.main.transform.position);
                    m_PlaneTapped.Invoke();
                    m_AnchorId = UnityARSessionNativeInterface.GetARSessionNativeInterface().AddUserAnchorFromGameObject(m_HitTransform.gameObject).identifierStr;
                    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)
        {
            if (exists)
            {
                return(false);
            }
            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));
                    exists = true;
                    GetComponent <AudioSource>().PlayOneShot(placingSound);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
        {
            List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

            if (hitResults.Count > 0 && !worldSpawn)
            {
                foreach (var hitResult in hitResults)
                {
                    worldSpawn = true;

                    //Debug.Log ("Got hit!");
                    m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);

                    PlanetsSpawn();

                    //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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);

                    // Face the camera (assume it's level and rotate around y-axis only)
                    m_HitTransform.LookAt(Camera.main.transform.position);
                    m_HitTransform.eulerAngles = new Vector3(0, m_HitTransform.eulerAngles.y, 0);


                    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);
        }
Esempio n. 9
0
        public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
        {
            // TANKS CODE
            if (ARKitGameManager.instance.gameMode != ARKitGameManager.GameMode.Calibration)
            {
                return(plane);
            }
            /////

            //do coordinate conversion from ARKit to Unity
            plane.transform.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
            plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);

            ARKitPlaneMeshRender apmr = plane.GetComponent <ARKitPlaneMeshRender> ();

            if (apmr != null)
            {
                apmr.UpdateMesh(arPlaneAnchor);
            }


            MeshFilter mf = plane.GetComponentInChildren <MeshFilter> ();

            if (mf != null)
            {
                if (apmr == null)
                {
                    //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
                    mf.gameObject.transform.localScale = new Vector3(arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);

                    //convert our center position to unity coords
                    mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
                }
            }

            return(plane);
        }
Esempio n. 10
0
        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 (placed != "placed")
                    {
                        placed = "unplaced";
                    }
//					m_HitTransform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform);
//
////					m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);
//					transform.LookAt(Camera.main.transform.position);
//					transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

                    if (clickNum == 0)
                    {
                        m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
//						clickNum += 1;
                    }
                    else if (clickNum == 1)
                    {
                        m_HitTransform2.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                        placed = "placed";
//						clickNum += 1;
                    }

                    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);
        }
Esempio n. 11
0
        bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
        {
            List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

            if (hitResults.Count > 0)
            {
                ScanningDots.SetActive(false);

                if (!cflBulb.activeInHierarchy)
                {
                    //works as long as theres only one condition?
                    buildingFact.SetActive(true);
                    buildingFact_trans.SetActive(true);
                }

                BlueFocusSquare.SetActive(false);

                FocusedSquare.SetActive(false);
                Destroy(FocusedSquare);
                Destroy(BlueFocusSquare);
                Destroy(TapToText);


                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);
                }
            }

            WholeLamp.transform.DetachChildren();
            lampNewCollider.GetComponent <Collider>().enabled = 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!");


                    // spawn Portal
                    GameObject newPortal = Instantiate(portalPrefab);
                    newPortal.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    newPortal.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);

                    portalAnim = newPortal.GetComponent <Animator>();

                    // spawn Fractal
                    GameObject newFractal = Instantiate(fractalPrefab);
                    newFractal.transform.position = newPortal.transform.position;
                    newFractal.transform.rotation = newPortal.transform.rotation;

                    fractalAnim = newFractal.GetComponent <Animator>();

                    /*
                     * 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);
        }
        bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
        {
            if (_isPlaneisPlaced)
            {
                return(false);
            }

            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);
                    _gameContent.SetActive(true);
                    _isPlaneisPlaced = true;
                    _ARCameraManager.TurnOffPlaneDetection();
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 14
0
        void MovePlane(Touch touch)
        {
            ARHitTestResult arHit = new ARHitTestResult();

            if (DoARRaycast(touch, ref arHit))
            {
                var hitPosition = UnityARMatrixOps.GetPosition(arHit.worldTransform);

                if (m_ARHit.anchorIdentifier != arHit.anchorIdentifier)
                {
                    // This means we've hit a different plane, so move to it immediately
                    transform.position = hitPosition;
                }
                else
                {
                    // Calculate the difference
                    var lastPosition = UnityARMatrixOps.GetPosition(m_ARHit.worldTransform);
                    var delta        = hitPosition - lastPosition;
                    transform.position += delta;
                }

                m_ARHit = arHit;
            }
        }
Esempio n. 15
0
        public void bringToCenter()
        {
            Vector3 screenPosition = Camera.main.ScreenToViewportPoint(new Vector3(Screen.width / 2, Screen.height / 2, 1));

            point.x    = screenPosition.x;
            point.y    = screenPosition.y;
            hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeFeaturePoint);
            if (hitResults.Count > 0)
            {
                cubeParent.transform.position = new Vector3(UnityARMatrixOps.GetPosition(hitResults[0].worldTransform).x, UnityARMatrixOps.GetPosition(hitResults[0].worldTransform).y, 1);
            }
        }
Esempio n. 16
0
        bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultType)
        {
            List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultType);

            if (hitResults.Count > 0)
            {
                foreach (var hitResult in hitResults)
                {
                    Debug.Log("Got Hit!");
                    //This was used in the original UnityARHitTestExample,
                    //but we want to have multiple objects placed based on toggles
                    // so we will change it

                    //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));

                    var position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    var rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                    switch (objectMode)
                    {
                    case ObjectMode.INV:

                        if (m_ARKitProjectUI.GetGameObjectPressed() == null)
                        {
                            GameObject invisibleWall = (GameObject)Instantiate(invisibleWall_prefab);
                            m_invisibleWallPlacement = invisibleWall.GetComponent <ObjectPlacement>();
                            m_invisibleWallPlacement.placeObject(position, rotation);
                        }
                        break;

                    case ObjectMode.DEL:
                        GameObject gameObjectDel = m_ARKitProjectUI.GetGameObjectPressed();
                        if (gameObjectDel != null)
                        {
                            Destroy(gameObjectDel);
                        }
                        break;

                    case ObjectMode.OB1:

                        if (object1_duplicate == true)
                        {
                            if (m_ARKitProjectUI.GetGameObjectPressed() == null)
                            {
                                GameObject object1 = (GameObject)Instantiate(object1_prefab);
                                m_object1Placement = object1.GetComponent <ObjectPlacement>();
                                m_object1Placement.placeObject(position, rotation);
                            }
                        }
                        else
                        {
                            GameObject object1 = GameObject.FindWithTag("object1");
                            if (object1 == null)
                            {
                                object1            = (GameObject)Instantiate(object1_prefab);
                                object1.tag        = "object1";
                                m_object1Placement = object1.GetComponent <ObjectPlacement>();
                                m_object1Placement.placeObject(position, rotation);
                            }
                            else
                            {
                                m_object1Placement = object1.GetComponent <ObjectPlacement>();
                                m_object1Placement.placeObject(position, rotation);
                            }
                        }


                        break;

                    case ObjectMode.OB2:

                        if (object2_duplicate == true)
                        {
                            if (m_ARKitProjectUI.GetGameObjectPressed() == null)
                            {
                                GameObject object2 = (GameObject)Instantiate(object2_prefab);
                                m_object2Placement = object2.GetComponent <ObjectPlacement>();
                                m_object2Placement.placeObject(position, rotation);
                            }
                        }
                        else
                        {
                            GameObject object2 = GameObject.FindWithTag("object2");
                            if (object2 == null)
                            {
                                object2            = (GameObject)Instantiate(object2_prefab);
                                object2.tag        = "object2";
                                m_object2Placement = object2.GetComponent <ObjectPlacement>();
                                m_object2Placement.placeObject(position, rotation);
                            }
                            else
                            {
                                m_object2Placement = object2.GetComponent <ObjectPlacement>();
                                m_object2Placement.placeObject(position, rotation);
                            }
                        }

                        break;
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 17
0
        bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultType)
        {
            List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultType);

            if (hitResults.Count > 0)
            {
                foreach (var hitResult in hitResults)
                {
                    Debug.Log("Got Hit!");

                    var position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    var rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                    switch (objectMode)
                    {
                    case ObjectMode.INV:

                        if (m_ARKitProjectUI.GetGameObjectPressed() == null)
                        {
                            GameObject invisibleWall = (GameObject)Instantiate(invisibleWall_prefab);
                            m_invisibleWallPlacement = invisibleWall.GetComponent <ObjectPlacement>();
                            m_invisibleWallPlacement.placeObject(position, rotation);
                        }
                        break;

                    case ObjectMode.DEL:
                        GameObject gameObjectDel = m_ARKitProjectUI.GetGameObjectPressed();
                        if (gameObjectDel != null)
                        {
                            Destroy(gameObjectDel);
                        }
                        break;

                    case ObjectMode.OB1:

                        if (object1_duplicate == true)
                        {
                            if (m_ARKitProjectUI.GetGameObjectPressed() == null)
                            {
                                GameObject object1 = (GameObject)Instantiate(object1_prefab);
                                m_object1Placement = object1.GetComponent <ObjectPlacement>();
                                m_object1Placement.placeObject(position, rotation);
                            }
                        }
                        else
                        {
                            GameObject object1 = GameObject.FindWithTag("object1");
                            if (object1 == null)
                            {
                                object1            = (GameObject)Instantiate(object1_prefab);
                                object1.tag        = "object1";
                                m_object1Placement = object1.GetComponent <ObjectPlacement>();
                                m_object1Placement.placeObject(position, rotation);
                            }
                            else
                            {
                                m_object1Placement = object1.GetComponent <ObjectPlacement>();
                                m_object1Placement.placeObject(position, rotation);
                            }
                        }


                        break;

                    case ObjectMode.OB2:

                        if (object2_duplicate == true)
                        {
                            if (m_ARKitProjectUI.GetGameObjectPressed() == null)
                            {
                                GameObject object2 = (GameObject)Instantiate(object2_prefab);
                                m_object2Placement = object2.GetComponent <ObjectPlacement>();
                                m_object2Placement.placeObject(position, rotation);
                            }
                        }
                        else
                        {
                            GameObject object2 = GameObject.FindWithTag("object2");
                            if (object2 == null)
                            {
                                object2            = (GameObject)Instantiate(object2_prefab);
                                object2.tag        = "object2";
                                m_object2Placement = object2.GetComponent <ObjectPlacement>();
                                m_object2Placement.placeObject(position, rotation);
                            }
                            else
                            {
                                m_object2Placement = object2.GetComponent <ObjectPlacement>();
                                m_object2Placement.placeObject(position, rotation);
                            }
                        }

                        break;
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 18
0
        // 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
                    };

                    List <ARHitTestResult> hitresults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeFeaturePoint);

                    if (hitresults.Count > 0)
                    {
                        foreach (var hitResult in hitresults)
                        {
                            Vector3 position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                        }
                    }
//                    // 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
        }
        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);

                    if (prefabToSpawn != null)
                    {
                        Debug.Log("Spawn object related to: " + m_Name);
                        Instantiate(prefabToSpawn, UnityARMatrixOps.GetPosition(hitResult.worldTransform), 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);
        }
Esempio n. 20
0
        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)
                {
                    GetComponent <MainManager>().ReceivedTouch(UnityARMatrixOps.GetPosition(hitResult.worldTransform), UnityARMatrixOps.GetRotation(hitResult.worldTransform));
                    //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);
        }