コード例 #1
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)
                {
                    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);
        }
コード例 #2
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)
                {
                    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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        void InitializeARKit(MessageEventArgs mea)
        {
            Debug.Log("init ARKit");
                        #if !UNITY_EDITOR
            Application.targetFrameRate = 60;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTackingSessionConfiguration config = new ARKitWorldTackingSessionConfiguration();
            config.planeDetection        = UnityARPlaneDetection.Horizontal;
            config.alignment             = UnityARAlignment.UnityARAlignmentGravity;
            config.getPointCloudData     = true;
            config.enableLightEstimation = true;
            m_session.RunWithConfig(config);

            UnityARSessionNativeInterface.ARFrameUpdatedEvent  += ARFrameUpdated;
            UnityARSessionNativeInterface.ARAnchorAddedEvent   += ARAnchorAdded;
            UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
                        #endif
        }
コード例 #5
0
        public void OnPreRender()
        {
            if (shouldRender)
            {
                ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();
                if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero)
                {
                    return;
                }

                if (!bCommandBufferInitialized)
                {
                    InitializeCommandBuffer();
                }

                Resolution currentResolution = Screen.currentResolution;

                // Texture Y
                if (_videoTextureY == null)
                {
                    _videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                     TextureFormat.R8, false, false, (System.IntPtr)handles.textureY);
                    _videoTextureY.filterMode = FilterMode.Bilinear;
                    _videoTextureY.wrapMode   = TextureWrapMode.Repeat;
                    m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
                }

                // Texture CbCr
                if (_videoTextureCbCr == null)
                {
                    _videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                        TextureFormat.RG16, false, false, (System.IntPtr)handles.textureCbCr);
                    _videoTextureCbCr.filterMode = FilterMode.Bilinear;
                    _videoTextureCbCr.wrapMode   = TextureWrapMode.Repeat;
                    m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
                }

                _videoTextureY.UpdateExternalTexture(handles.textureY);
                _videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr);

                m_ClearMaterial.SetMatrix("_DisplayTransform", _displayTransform);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        // The main camera is surrounded by a SphereCollider with IsTrigger set to On
        void OnTriggerEnter(Collider portal)
        {
            Portal logic = portal.GetComponentInParent <Portal> ();

            transform.position = logic.PortalCameras[1].transform.position - GetComponentInChildren <Camera>().transform.localPosition;


            if (logic.name == "VRDoor")
            {
                doorToReality.transform.position = new Vector3(-0.97f, 200.968f, 0.33f);
                doorToReality.transform.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(doorToReality.transform.position - mainCamera.transform.position, Vector3.up));
                doorToReality.GetComponentInParent <Portal> ().Source.transform.localPosition = doorToReality.transform.position;
                hittest.SetActive(false);
                logic.gameObject.SetActive(false);
            }

            if (logic.name == "VRDoor2")
            {
                doorToReality.transform.position = new Vector3(8.83f, 904.77f, 4.0f);
                doorToReality.transform.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(doorToReality.transform.position - mainCamera.transform.position, Vector3.up));
                doorToReality.GetComponentInParent <Portal> ().Source.transform.localPosition = doorToReality.transform.position;

                portalcamera2.SetActive(false);
                hittest.SetActive(false);

                logic.gameObject.SetActive(false);
            }

            if (logic.name == "RealWorldDoor")
            {
                hittest.SetActive(true);
                ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(UnityARAlignment.UnityARAlignmentGravity, UnityARPlaneDetection.Horizontal);
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking);
            }


            if (OnPortalTransition != null)
            {
                // Emit a static OnPortalTransition event every time the camera enters a portal. The DoorManager listens for this event.
                OnPortalTransition();
            }
        }
コード例 #8
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(100, 100, 200, 50), "Stop"))
            {
                UnityARSessionNativeInterface.GetARSessionNativeInterface().Pause();
            }

            if (GUI.Button(new Rect(300, 100, 200, 50), "Start"))
            {
                ARKitWorldTrackingSessionConfiguration sessionConfig = new ARKitWorldTrackingSessionConfiguration(alignmentOptions [currentAlignmentIndex], planeOptions[currentPlaneIndex]);
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, runOptions[currentOptionIndex]);
            }


            if (GUI.Button(new Rect(100, 300, 200, 100), "Start Non-WT Session"))
            {
                ARKitSessionConfiguration sessionConfig = new ARKitSessionConfiguration(alignmentOptions [currentAlignmentIndex], true, true);
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfig(sessionConfig);
            }


            string runOptionStr = (currentOptionIndex == 0 ? "Full" : (currentOptionIndex == 1 ? "Tracking" : (currentOptionIndex == 2 ? "Anchors" : "None")));

            if (GUI.Button(new Rect(100, 200, 150, 50), "RunOption:" + runOptionStr))
            {
                currentOptionIndex = (currentOptionIndex + 1) % 4;
            }

            string alignmentOptionStr = (currentAlignmentIndex == 0 ? "Camera" : (currentAlignmentIndex == 1 ? "Gravity" :  "GravityAndHeading"));

            if (GUI.Button(new Rect(300, 200, 150, 50), "AlignOption:" + alignmentOptionStr))
            {
                currentAlignmentIndex = (currentAlignmentIndex + 1) % 3;
            }

            string planeOptionStr = currentPlaneIndex == 0 ? "Horizontal":  "None";

            if (GUI.Button(new Rect(500, 200, 150, 50), "PlaneOption:" + planeOptionStr))
            {
                currentPlaneIndex = (currentPlaneIndex + 1) % 2;
            }
        }
コード例 #9
0
        /* * * * * *
        *
        * 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);
        }
コード例 #10
0
        /// <summary>
        /// This should only be called once from MapsyncLb.cs
        /// </summary>
        public UnityMapsyncLibNativeInterface(string mapId, string userId, string developerKey, bool isMappingMode)
        {
            UnityARSessionNativeInterface arkit = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            IntPtr arSession = arkit.GetSession();

            if (arSession == IntPtr.Zero)
            {
                Debug.Log("ARKit session is not initialized");
                return;
            }

            _CreateMapsyncSession(arSession, mapId, userId, developerKey, isMappingMode);

            string unityCallbackGameObject          = "MapSession";
            string unityAssetLoadedCallbackFunction = "AssetReloaded";
            string unityStatusUpdatedCallback       = "StatusUpdated";
            string unityStorePlacementCallback      = "PlacementStored";

            _RegisterUnityCallbacks(unityCallbackGameObject, unityAssetLoadedCallbackFunction, unityStatusUpdatedCallback, unityStorePlacementCallback);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        //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);
        }
コード例 #13
0
        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));
                }
            }
        }
コード例 #14
0
ファイル: PlaceBlock.cs プロジェクト: reecedantin/ZombieRun
        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);
        }
コード例 #15
0
        void InitializeARKit(serializableARKitInit sai)
        {
                        #if !UNITY_EDITOR
            //get the config and runoption from editor and use them to initialize arkit on device
            Application.targetFrameRate = 60;
            m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            ARKitWorldTrackingSessionConfiguration config = sai.config;
            UnityARSessionRunOption runOptions            = sai.runOption;

            //potentially improves framerate?
            //https://bitbucket.org/Unity-Technologies/unity-arkit-plugin/issues/78/remote-very-low-fps-and-repeated

            UnityARSessionNativeInterface session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            config.planeDetection = UnityARPlaneDetection.Horizontal;
            var videoFormat = UnityARVideoFormat.SupportedVideoFormats()[UnityARVideoFormat.SupportedVideoFormats().Count - 1];
            config.videoFormat          = videoFormat.videoFormatPtr;
            Application.targetFrameRate = videoFormat.framesPerSecond;

            m_session.RunWithConfigAndOptions(config, runOptions);

            UnityARSessionNativeInterface.ARFrameUpdatedEvent  += ARFrameUpdated;
            UnityARSessionNativeInterface.ARAnchorAddedEvent   += ARAnchorAdded;
            UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
                        #endif
            // #if !UNITY_EDITOR
            // //get the config and runoption from editor and use them to initialize arkit on device
            // Application.targetFrameRate = 60;
            // m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            // ARKitWorldTrackingSessionConfiguration config = sai.config;
            // UnityARSessionRunOption runOptions = sai.runOption;
            // m_session.RunWithConfigAndOptions(config, runOptions);

            // UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
            // UnityARSessionNativeInterface.ARAnchorAddedEvent += ARAnchorAdded;
            // UnityARSessionNativeInterface.ARAnchorUpdatedEvent += ARAnchorUpdated;
            // UnityARSessionNativeInterface.ARAnchorRemovedEvent += ARAnchorRemoved;
            // #endif
        }
コード例 #16
0
        //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);
        }
コード例 #17
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 (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);
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
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);
                    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);
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
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);
        }
コード例 #23
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);
        }
コード例 #24
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);
        }
コード例 #25
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);
        }
コード例 #26
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);
        }
コード例 #27
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!");


                    // 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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
 void OnDestroy()
 {
     UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= GameObjectAnchorUpdated;
     UnityARSessionNativeInterface.ARUserAnchorRemovedEvent -= AnchorRemoved;
     UnityARSessionNativeInterface.GetARSessionNativeInterface().RemoveUserAnchor(this.m_AnchorId);
 }
コード例 #30
0
 void Awake()
 {
     UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent += GameObjectAnchorUpdated;
     UnityARSessionNativeInterface.ARUserAnchorRemovedEvent += AnchorRemoved;
     this.m_AnchorId = UnityARSessionNativeInterface.GetARSessionNativeInterface().AddUserAnchorFromGameObject(this.gameObject).identifierStr;
 }