/// <summary> /// Recreates a scene based on parsed JSON data (SerializableScene). /// </summary> /// <param name="scene">The scene data we parsed from JSON</param> /// <param name="sceneId">The unique ID of the scene, used for downloading custom objects</param> public void ParseSerializableScene(SerializableScene scene, string sceneId) { HideObjectsInViewMode(scene.allowSceneEdit); CameraModeChanger.Instance.ActiveCamera.transform.position = new Vector3(scene.camera.position.x, scene.camera.position.y, scene.camera.position.z); CameraModeChanger.Instance.ActiveCamera.transform.rotation = new Quaternion(scene.camera.rotation.x, scene.camera.rotation.y, scene.camera.rotation.z, scene.camera.rotation.w); //Apply sunlight settings sunSettings.SetDateTimeFromString(scene.sunTimeStamp); //Fixed layer settings buildingsLayer.Active = scene.fixedLayers.buildings.active; treesLayer.Active = scene.fixedLayers.trees.active; groundLayer.Active = scene.fixedLayers.ground.active; buildingsLayer.EnableOptions(scene.allowSceneEdit); treesLayer.EnableOptions(scene.allowSceneEdit); groundLayer.EnableOptions(scene.allowSceneEdit); //Create annotations for (int i = 0; i < scene.annotations.Length; i++) { //Create the 2D annotation var annotationData = scene.annotations[i]; Annotation annotation = Instantiate(annotationPrefab, annotationsContainer); annotation.WorldPointerFollower.WorldPosition = new Vector3(annotationData.position.x, annotationData.position.y, annotationData.position.z); annotation.BodyText = annotationData.bodyText; annotation.AllowEdit = scene.allowSceneEdit; annotation.waitingForClick = false; //Create a custom annotation layer CustomLayer newCustomAnnotationLayer = interfaceLayers.AddNewCustomObjectLayer(annotation.gameObject, LayerType.ANNOTATION, false); newCustomAnnotationLayer.RenameLayer(annotationData.bodyText); annotation.interfaceLayer = newCustomAnnotationLayer; newCustomAnnotationLayer.ViewingOnly(!scene.allowSceneEdit); newCustomAnnotationLayer.Active = annotationData.active; } //Create all custom layers with meshes for (int i = 0; i < scene.customLayers.Length; i++) { SerializableScene.CustomLayer customLayer = scene.customLayers[i]; GameObject customObject = new GameObject(); customObject.name = customLayer.layerName; if (scene.allowSceneEdit) { customObject.AddComponent <Interactable>(); } ApplyLayerMaterialsToObject(customLayer, customObject); CustomLayer newCustomLayer = interfaceLayers.AddNewCustomObjectLayer(customObject, LayerType.OBJMODEL, false); newCustomLayer.ViewingOnly(!scene.allowSceneEdit); newCustomLayer.EnableOptions(scene.allowSceneEdit); newCustomLayer.Active = customLayer.active; newCustomLayer.GetUniqueNestedMaterials(); newCustomLayer.UpdateLayerPrimaryColor(); StartCoroutine(GetCustomMeshObject(customObject, sceneId, customLayer.token, customLayer.position, customLayer.rotation, customLayer.scale)); } //Create all custom camera points for (int i = 0; i < scene.cameraPoints.Length; i++) { SerializableScene.CameraPoint cameraPoint = scene.cameraPoints[i]; GameObject cameraObject = Instantiate(cameraPrefab); cameraObject.name = cameraPoint.name; cameraObject.transform.SetParent(camerasContainer, false); cameraObject.GetComponent <WorldPointFollower>().WorldPosition = cameraPoint.position; cameraObject.GetComponent <FirstPersonLocation>().savedRotation = cameraPoint.rotation; cameraObject.GetComponent <FirstPersonLocation>().waitingForClick = false; CustomLayer newCustomLayer = interfaceLayers.AddNewCustomObjectLayer(cameraObject, LayerType.CAMERA); newCustomLayer.Active = true; } //Set material properties for fixed layers SetFixedLayerProperties(buildingsLayer, scene.fixedLayers.buildings); SetFixedLayerProperties(treesLayer, scene.fixedLayers.trees); SetFixedLayerProperties(groundLayer, scene.fixedLayers.ground); }