private void UpdateForDisplayImmediatelyGroundOnly()
    {
        long      activeSurfaceId = xr.GetActiveSurfaceId();
        XRSurface activeSurface   = xr.GetSurface(activeSurfaceId);

        bool activeSurfaceIsValidGround = activeSurface != XRSurface.NO_SURFACE &&
                                          activeSurface.type == XRSurface.Type.HORIZONTAL_PLANE;

        if (!activeSurfaceIsValidGround)
        {
            return;
        }

        Vector3 centerVertex = GetVertexCenter(activeSurface.mesh);

        if (surfaceFound)
        {
            if (centerVertex.y < groundHeightGuess)
            {
                groundHeightGuess = centerVertex.y;
                SetHeight(groundHeightGuess);
            }
        }
        else
        {
            if (centerVertex.y < Camera.main.transform.position.y - MIN_GROUND_DISTANCE_FROM_PHONE)
            {
                groundHeightGuess = centerVertex.y;
                SetHeight(groundHeightGuess);
                onSurfaceAttach.Invoke();
                surfaceFound = true;
            }
        }
    }
    void Update()
    {
        if (xr_.DisabledInEditor())
        {
            return;
        }

        long surfaceId = xr_.GetActiveSurfaceId();
        var  surface   = xr_.GetSurface(surfaceId);

        if (surface != XRSurface.NO_SURFACE && !idToMesh_.ContainsKey(surfaceId))
        {
            MeshThing meshThing = new MeshThing();
            meshThing.holder = new GameObject();
            meshThing.holder.transform.parent = gameObject.transform;
            meshThing.filter              = meshThing.holder.AddComponent <MeshFilter>();
            meshThing.collider            = meshThing.holder.AddComponent <MeshCollider>();
            meshThing.renderer            = meshThing.holder.AddComponent <MeshRenderer>();
            meshThing.filter.mesh         = surface.mesh;
            meshThing.collider.sharedMesh = surface.mesh;
            if (surface.type == XRSurface.Type.VERTICAL_PLANE)
            {
                meshThing.renderer.material = verticalSurfaceMaterial_;
            }
            else
            {
                meshThing.renderer.material = horizontalSurfaceMaterial_;
            }
            idToMesh_[surfaceId] = meshThing;

            // Save all surfaces that we have seen
            idToSurface_[surfaceId] = surface;
        }

        // Update Status Text
        if (statusText_ != null)
        {
            int totalSurfaceCount    = idToSurface_.Count;
            int verticalSurfaceCount = 0;
            foreach (var s in idToSurface_.Values)
            {
                if (s.type == XRSurface.Type.VERTICAL_PLANE)
                {
                    verticalSurfaceCount++;
                }
            }
            statusText_.text = string.Format("Surface {0} Vertical /{1} Total",
                                             verticalSurfaceCount, totalSurfaceCount);
        }
    }
Exemple #3
0
    void Update()
    {
        // If there are no meshes, reset the id to default and don't change
        // anything.
        Mesh mesh = xr.GetActiveSurfaceMesh();

        if (mesh == null)
        {
            surfaceId = Int64.MinValue;
            return;
        }

        UpdateMesh(xr.GetActiveSurfaceId(), mesh);
    }
Exemple #4
0
    void Move()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

        // The GameObject with an XRSurfaceController attached should be on layer "Surface"
        if (Physics.Raycast(ray, out hit, 50.0f, LayerMask.GetMask("Surface")))
        {
            transform.position = new Vector3(hit.point.x,
                                             transform.position.y,
                                             hit.point.z);

            activeSurfaceId = xr.GetActiveSurfaceId();
            Vector3 newCenter = transform.position;
            GetComponent <XRSurfaceController>().centerMap[activeSurfaceId] = newCenter;
        }
    }