/// <summary> /// 保存创作 /// </summary> public IEnumerator SaveEdit() { if (mapData == null) { yield break; } var cor1 = Window.instance.startCoroutine(SaveMapMeta()); var cor2 = Window.instance.startCoroutine(Snapshot()); yield return(cor1); yield return(cor2); // 保存到云端 // (图片)capturedImage // (ID)mapData.Meta.Map.ID // (time) DateTime.Now.ToString("yyyy-MM-dd_HHmmss") // (Meta) mapData.Meta // GPS Mark mark = new Mark { coordinate = new cn.bmob.io.BmobGeoPoint { Latitude = TapOnUtils.nowLocation.latitude, Longitude = TapOnUtils.nowLocation.longitude }, snapShot_byte = capturedImage.EncodeToJPG(), MapId = mapData.Meta.Map.ID, MapName = "Map_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss"), meta_byte = File.ReadAllBytes(MapMetaManager.GetPath(mapData.Meta.Map.ID)), }; BmobApi.addMarktoServer(mark); }
private IEnumerator LoadMetaFile(Mark mark) { Debug.Log("LoadMetaFile"); if (MapMetaManager.isLocal(mark.MapId)) { Debug.Log("is Local"); selectedMaps.Add(MapMetaManager.LoadMeta(mark.MapId)); } // 否则,从url获取, 并保存在本地 else { Debug.Log("get from url"); #pragma warning disable CS0618 // 类型或成员已过时 WWW meta = new WWW(mark.metaFile.url); #pragma warning restore CS0618 // 类型或成员已过时 yield return(meta); selectedMaps.Add(JsonUtility.FromJson <MapMeta>(meta.text)); // 保存在本地 foreach (var m in selectedMaps) { if (!MapMetaManager.isLocal(m.Map.ID)) { MapMetaManager.Save(m); } } } }
private IEnumerator LoadTexture(string url, string fileName) { //Debug.Log("LoadTexture"); // 判定texture是否本地存在 #pragma warning disable CS0618 // 类型或成员已过时 WWW www; if (MapMetaManager.isTextureInLocal(fileName)) { www = new WWW("file://" + MapMetaManager.PathForFile(fileName, "picture")); //Debug.Log("prop: get From local"); } else { www = new WWW(url); //Debug.Log("prop: get From url"); } #pragma warning restore CS0618 // 类型或成员已过时 yield return(www); this.tag = "texture"; Transform tf = this.transform.Find("Cube"); if (saveImgTf) { saveImgTf = false; imageTF = this.transform.Find("Cube").localScale; ratio = imageTF.y * 1.0f / imageTF.x; } float ratio_tex = www.texture.height * 1.0f / www.texture.width; //Debug.Log("ratio: " + ratio + " ratio_text: " + ratio_tex); tf.localScale = ratio_tex > ratio ? new Vector3(ratio / ratio_tex * imageTF.x, imageTF.y, imageTF.z) : new Vector3(imageTF.x, ratio_tex / ratio * imageTF.y, imageTF.z); Renderer rd = this.GetComponentInChildren <Renderer>(); rd.material.mainTexture = www.texture; // 存储texture 到本地。 MapMetaManager.SaveTextureToLocal(www.texture, fileName); }
public void Save(string name, Optional <easyar.Image> preview) { IsSaving = true; MapWorker.BuilderMapController.MapHost += (map, isSuccessful, error) => { if (isSuccessful) { var mapMeta = new MapMeta(map, new List <MapMeta.PropInfo>()); MapMetaManager.Save(mapMeta); // Maps 添加一个Map /********************************************/ var mapData = new MapData(); mapData.Meta = mapMeta; Maps.Add(mapData); /********************************************/ GUIPopup.EnqueueMessage("Map Generated", 3); GUIPopup.EnqueueMessage("Notice: map name can be changed on website," + Environment.NewLine + "while the SDK side will not get updated until map cache cleared and a re-download has been triggered.", 5); Saved = true; } else { GUIPopup.EnqueueMessage("Fail to generate Map" + (string.IsNullOrEmpty(error) ? "" : "\n error: " + error), 5); } IsSaving = false; }; try { MapWorker.BuilderMapController.Host(name, preview); } catch (Exception e) { GUIPopup.EnqueueMessage("Fail to host map: " + e.Message, 5); IsSaving = false; } }
public IEnumerator SaveMapMeta() { //if (mapData == null) //{ // return; //} Debug.Log("length: " + mapData.Props.Count); var propInfos = new List <MapMeta.PropInfo>(); foreach (var prop in mapData.Props) { var position = prop.transform.localPosition; var rotation = prop.transform.localRotation; var scale = prop.transform.localScale; MapMeta.PropType typeTemp; string textTemp = null; BmobFile infoTemp = null; Debug.Log("prop tag: " + prop.tag); Debug.Log("prop name: " + prop.name); if ("word" == prop.tag) { typeTemp = MapMeta.PropType.Text; textTemp = prop.GetComponentInChildren <TextMesh>().text; propInfos.Add(new MapMeta.PropInfo() { Name = prop.name, Position = new float[3] { position.x, position.y, position.z }, Rotation = new float[4] { rotation.x, rotation.y, rotation.z, rotation.w }, Scale = new float[3] { scale.x, scale.y, scale.z }, type = typeTemp, text = textTemp, }); } else { byte[] info_byte = null; if ("texture" == prop.tag) { typeTemp = MapMeta.PropType.Texture; Texture rt = prop.GetComponentInChildren <MeshRenderer>().material.mainTexture; if (rt == null) { Debug.LogError("RenderTexture is error"); } else { RenderTexture destTexture = new RenderTexture(rt.width, rt.height, 0); Graphics.Blit(rt, destTexture); RenderTexture.active = destTexture; var imgTemp = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false); imgTemp.ReadPixels(new UnityEngine.Rect(0, 0, rt.width, rt.height), 0, 0); imgTemp.Apply(); RenderTexture.active = null; Destroy(destTexture); info_byte = imgTemp.EncodeToJPG(); if (info_byte == null) { Debug.Log("info_byte is null"); } } //info_byte = prop.GetComponentInChildren<MeshRenderer>().material.mainTexture. coroutines.Add( Window.instance.startCoroutine( TapOnUtils.upLoadFile( "NameCard_" + (tempInfoCount++) + "_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".jpg", "application/x-jpg", info_byte, (wr) => { Restful_FileUpLoadCallBack t = TapOnUtils.fileUpLoadCallBackfromJson(wr.downloadHandler.text); infoTemp = new BmobFile { filename = t.filename, url = t.url }; Debug.Log("NameCard save"); propInfos.Add(new MapMeta.PropInfo() { Name = prop.name, Position = new float[3] { position.x, position.y, position.z }, Rotation = new float[4] { rotation.x, rotation.y, rotation.z, rotation.w }, Scale = new float[3] { scale.x, scale.y, scale.z }, type = typeTemp, infoFileName = infoTemp.filename, infoUrl = infoTemp.url, }); }) )); } else if ("Video(Clone)" == prop.name) { typeTemp = MapMeta.PropType.Video; // info_byte } else if ("Model(Clone)" == prop.name) { typeTemp = MapMeta.PropType.Model; // info_byte } else { typeTemp = MapMeta.PropType.other; } } } foreach (var cor in coroutines) { yield return(cor); } mapData.Meta.Props = propInfos; // 保存到本地 MapMetaManager.Save(mapData.Meta); }