示例#1
0
    private void Observer_OnSurfaceChanged(UnityEngine.XR.WSA.SurfaceId surfaceId, UnityEngine.XR.WSA.SurfaceChange changeType, Bounds bounds, System.DateTime updateTime)
    {
        GameObject surface;

        switch (changeType)
        {
        case UnityEngine.XR.WSA.SurfaceChange.Updated:
        case UnityEngine.XR.WSA.SurfaceChange.Added:
            if (!surfaces.TryGetValue(surfaceId.handle, out surface))
            {
                // If we are adding a new surface, construct a GameObject
                // to represent its state and attach some Mesh-related
                // components to it.
                surface = new GameObject(string.Format("Surface-{0}", surfaceId));
                surface.AddComponent <MeshFilter>();
                surface.AddComponent <MeshRenderer>().sharedMaterial = DrawMaterial;
                surface.AddComponent <MeshCollider>();
                surface.AddComponent <UnityEngine.XR.WSA.WorldAnchor>();
                // Set the layer that this SpatialMapping surface is a part of
                surface.layer = PhysicsLayer;
                // Add the surface to our dictionary of known surfaces so
                // we can interact with it later.
                surfaces[surfaceId.handle] = surface;
            }

            UnityEngine.XR.WSA.SurfaceData smsd = new UnityEngine.XR.WSA.SurfaceData(
                surfaceId,
                surface.GetComponent <MeshFilter>(),
                surface.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(),
                surface.GetComponent <MeshCollider>(),
                TrianglesPerCubicMeter,
                true);
            surfaceDataQueue.Enqueue(smsd);
            break;

        case UnityEngine.XR.WSA.SurfaceChange.Removed:
            if (surfaces.TryGetValue(surfaceId.handle, out surface))
            {
                surfaces.Remove(surfaceId.handle);
                Destroy(surface);
            }
            break;
        }
    }
        /// <summary>
        /// Calls for rebaking of non-conforming surfaces upon updating of Density
        /// </summary>
        private void CallForRebake(float newDensity)
        {
            for (int i = 0; i < SurfaceObjects.Count; i++) //
            {
                UnityEngine.XR.WSA.SurfaceId ID = new UnityEngine.XR.WSA.SurfaceId();
                ID.handle = SurfaceObjects[i].ID;

                // check if non-conforming and not already staged for rebaking
                if (ExtraData[i].Density != newDensity && !surfaceWorkQueue.Contains(ID))
                {
                    surfaceWorkQueue.Enqueue(ID);

                    /*
                     * // debug
                     * Debug.Log(string.Format("Mesh {0}: Density does not conform. Was {1}, should be {2}. Added to surfaceWorkQuene.",
                     *  ID.handle, ExtraData[i].Density, newDensity));
                     */
                }
            }
            needRebake = false;
        }