void AnchorStoreReady(WorldAnchorStore store) { // save instance anchorStore = store; // load room meshesn roomMeshes = MeshSaverOld.Load(fileName) as List <Mesh>; roomObjects = new List <GameObject>(); foreach (Mesh surface in roomMeshes) { GameObject obj = Instantiate(surfaceObject) as GameObject; obj.GetComponent <MeshFilter>().mesh = surface; obj.GetComponent <MeshCollider>().sharedMesh = surface; obj.transform.parent = this.transform; roomObjects.Add(obj); if (!anchorStore.Load(surface.name, obj)) { Debug.Log("WorldAnchor load failed..."); } } if (managerObject != null) { managerObject.SendMessage("RoomLoaded"); } }
public void SaveRoom() { // if the anchor store is not ready then we cannot save the room mesh if (anchorStore == null) { return; } // delete old relevant anchors string[] anchorIds = anchorStore.GetAllIds(); for (int i = 0; i < anchorIds.Length; i++) { if (anchorIds[i].Contains(anchorStoreName)) { anchorStore.Delete(anchorIds[i]); } } // get all mesh filters used for spatial mapping meshes roomMeshFilters = SpatialMappingManager.Instance.GetMeshFilters() as List <MeshFilter>; // create new list of room meshes for serialization List <Mesh> roomMeshes = new List <Mesh>(); // cycle through all room mesh filters foreach (MeshFilter filter in roomMeshFilters) { // increase count of meshes in room meshCount++; // make mesh name = anchor name + mesh count string meshName = anchorStoreName + meshCount.ToString(); filter.mesh.name = meshName; // add mesh to room meshes for serialization roomMeshes.Add(filter.mesh); // save world anchor WorldAnchor attachingAnchor = filter.gameObject.GetComponent <WorldAnchor>(); if (attachingAnchor == null) { attachingAnchor = filter.gameObject.AddComponent <WorldAnchor>(); } else { DestroyImmediate(attachingAnchor); attachingAnchor = filter.gameObject.AddComponent <WorldAnchor>(); } if (attachingAnchor.isLocated) { if (!anchorStore.Save(meshName, attachingAnchor)) { Debug.Log("" + meshName + ": Anchor save failed..."); } else { Debug.Log("" + meshName + ": Anchor SAVED..."); } } else { attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged; } } // serialize and save meshes MeshSaverOld.Save(fileName, roomMeshes); }