public static IEnumerator getMetaFile(BmobFile metaFile, Action <List <GameObject> > after) { MapMeta meta = null; yield return(TapOnUtils.downloadFile( metaFile.url, wr => { meta = JsonUtility.FromJson <MapMeta>(wr.downloadHandler.text); })); List <GameObject> objects = new List <GameObject>(); List <IEnumerator> tasks = new List <IEnumerator>(); foreach (MapMeta.PropInfo propInfo in meta.Props) { if (propInfo.type == MapMeta.PropType.Text) { GameObject instance = GameObject.Instantiate(Globals.instance.templetes[0]); instance.tag = "word"; instance.SetActive(false); TextMesh tm = instance.GetComponentInChildren <TextMesh>(); tm.text = propInfo.text; instance.transform.position = new Vector3(propInfo.Position[0], propInfo.Position[1], propInfo.Position[2]); instance.transform.rotation = new Quaternion(propInfo.Rotation[0], propInfo.Rotation[1], propInfo.Rotation[2], propInfo.Rotation[3]); instance.transform.localScale = new Vector3(propInfo.Scale[0], propInfo.Scale[1], propInfo.Scale[2]); objects.Add(instance); } if (propInfo.type == MapMeta.PropType.Texture) { GameObject instance = GameObject.Instantiate(Globals.instance.templetes[1]); instance.tag = "texture"; instance.SetActive(false); Renderer rd = instance.GetComponentInChildren <Renderer>(); instance.transform.position = new Vector3(propInfo.Position[0], propInfo.Position[1], propInfo.Position[2]); instance.transform.rotation = new Quaternion(propInfo.Rotation[0], propInfo.Rotation[1], propInfo.Rotation[2], propInfo.Rotation[3]); instance.transform.localScale = new Vector3(propInfo.Scale[0], propInfo.Scale[1], propInfo.Scale[2]); objects.Add(instance); IEnumerator downloadTexture = TapOnUtils.downloadFile( propInfo.infoUrl, wr_dt => { Texture2D texture = new Texture2D(10, 10); texture.LoadImage(wr_dt.downloadHandler.data); rd.material.mainTexture = texture; }); tasks.Add(downloadTexture); } } foreach (IEnumerator t in tasks) { yield return(t); } if (after != null) { after(objects); } }
public static object AddVideoProduct(string path, Unity.UIWidgets.widgets.BuildContext context) { return(new ThunkAction <AppState>((dispatcher, getState) => { GameObject instance = GameObject.Instantiate(Globals.instance.templetes[2]); instance.tag = "video"; instance.SetActive(false); instance.GetComponentInChildren <VideoPlayer>().url = "File:////" + path; Prop product = new Prop { type = (int)ProductType.Video, instance = instance }; if (getState().settingState.products.Count < 3) { dispatcher.dispatch(new AddProductAction { product = product }); dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = getState().settingState.products.Count - 1 }); return 0; } dispatcher.dispatch(new ChangeProductIndexAction()); dispatcher.dispatch(new ChangeAppearStateAction { state = false, index = 2 }); if (Window.instance == null) { Debug.Log("null"); } using (Unity.UIWidgets.widgets.WindowProvider.of(context).getScope()) { Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: () => { Debug.Log("xs"); dispatcher.dispatch(new AddProductAction { product = product }); Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: (() => { dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = 2 }); }))); } )); } return 0; })); }
public static object AddTextProduct(string text) { return(new ThunkAction <AppState>((dispatcher, getState) => { GameObject instance = GameObject.Instantiate(Globals.instance.templetes[0]); instance.tag = "word"; instance.SetActive(false); TextMesh tm = instance.GetComponentInChildren <TextMesh>(); tm.text = text; Prop product = new Prop { type = (int)ProductType.Text, text = text, instance = instance }; if (getState().settingState.products.Count < 3) { dispatcher.dispatch(new AddProductAction { product = product }); dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = getState().settingState.products.Count - 1 }); return 0; } dispatcher.dispatch(new ChangeProductIndexAction()); dispatcher.dispatch(new ChangeAppearStateAction { state = false, index = 2 }); Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: () => { dispatcher.dispatch(new AddProductAction { product = product }); Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: (() => { dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = 2 }); }))); } )); return 0; })); }
public static object AddModelProduct(GameObject model, string id) { return(new ThunkAction <AppState>((dispatcher, getState) => { model.tag = "model"; BmobModel m = new BmobModel(); m.objectId = id; Prop product = new Prop { type = (int)ProductType.Model, model = m, instance = model }; if (getState().settingState.products.Count < 3) { dispatcher.dispatch(new AddProductAction { product = product }); dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = getState().settingState.products.Count - 1 }); return 0; } dispatcher.dispatch(new ChangeProductIndexAction()); dispatcher.dispatch(new ChangeAppearStateAction { state = false, index = 2 }); Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: () => { dispatcher.dispatch(new AddProductAction { product = product }); Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: (() => { dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = 2 }); }))); } )); return 0; })); }
public IEnumerator test() { UnityWebRequest wr = new UnityWebRequest("https://api.bmob.cn/2/files/myTest.jpg", "POST"); wr.SetRequestHeader("X-Bmob-Application-Id", "694024c993688a00b5707fba73ab8551"); wr.SetRequestHeader("X-Bmob-REST-API-Key", "60ad19f4362c54aa3da42a41282cb369"); wr.SetRequestHeader("Content-Type", "application/x-jpg"); wr.uploadHandler = new UploadHandlerFile("E:\\easyAR_sample\\TapOn2.0\\Assets\\TapOn\\Resources\\texture\\namecard.jpg"); wr.downloadHandler = new DownloadHandlerBuffer(); yield return(wr.SendWebRequest()); if (wr.isHttpError || wr.isNetworkError) { Debug.LogError(wr.error + "\n" + wr.downloadHandler.text); } else { Debug.Log("bmob return " + wr.downloadHandler.text); Restful_FileUpLoadCallBack t = TapOnUtils.fileUpLoadCallBackfromJson(wr.downloadHandler.text); Debug.Log(t.filename); Debug.Log(t.url); } }
protected override void OnEnable() { base.OnEnable(); StartCoroutine(TapOnUtils.startGPS()); //Debuger.EnableLog = Config.enableDebug; Screen.fullScreen = false; Screen.orientation = ScreenOrientation.Portrait; //Window.onFrameRateCoolDown = CustomFrameRateCoolDown; LoadFonts(); BmobDebug.Register(print); BmobDebug.level = BmobDebug.Level.TRACE; //if (Globals.instance == null) Debug.LogError("Global instance is null!"); //if (Globals.instance.bmob == null) Debug.LogError("Global bmob is null!"); if (Globals.instance.bmob == null) { GameObject t = GameObject.Find("Config"); if (t == null) { Debug.LogError("t is null"); } else { Globals.instance.bmob = t.GetComponent <BmobUnity>(); } } if (Globals.instance.bmob == null) { Debug.LogError("Global bmob is null after!"); } if (!Directory.Exists(Application.persistentDataPath + "//model")) { Directory.CreateDirectory(Application.persistentDataPath + "//model"); } }
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); }
public static object AddImageProduct(Texture2D texture, Unity.UIWidgets.widgets.BuildContext context) { return(new ThunkAction <AppState>((dispatcher, getState) => { GameObject instance = GameObject.Instantiate(Globals.instance.templetes[1]); instance.tag = "texture"; instance.SetActive(false); Renderer rd = instance.GetComponentInChildren <Renderer>(); UnityEngine.Transform tf = instance.transform.Find("Cube"); if (saveImgTf) { saveImgTf = false; imageTF = instance.transform.Find("Cube").localScale; ratio = imageTF.y * 1.0f / imageTF.x; } float ratio_tex = texture.height * 1.0f / 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); rd.material.mainTexture = texture; Prop product = new Prop { type = (int)ProductType.Picture, texture_byte = texture.EncodeToPNG(), instance = instance }; if (getState().settingState.products.Count < 3) { dispatcher.dispatch(new AddProductAction { product = product }); dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = getState().settingState.products.Count - 1 }); return 0; } dispatcher.dispatch(new ChangeProductIndexAction()); dispatcher.dispatch(new ChangeAppearStateAction { state = false, index = 2 }); if (Window.instance == null) { Debug.Log("null"); } using (Unity.UIWidgets.widgets.WindowProvider.of(context).getScope()) { Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: () => { Debug.Log("xs"); dispatcher.dispatch(new AddProductAction { product = product }); Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.3f, after: (() => { dispatcher.dispatch(new ChangeAppearStateAction { state = true, index = 2 }); }))); } )); } return 0; })); }
/*public static IEnumerator getAllProps() * { * * }*/ public static async void addMarktoServer(Mark mark) { CreateCallbackData callback_mark = await Bmob.CreateTaskAsync(Mark.table_name, mark); if (callback_mark == null || callback_mark.objectId == null || callback_mark.objectId.Length == 0) { Debug.LogError("BmobRrror: Mark hasn't upload!"); return; } Globals.instance.uploading = false; ((Unity.UIWidgets.widgets.Element)Globals.instance.nowContext).markNeedsBuild(); using (Unity.UIWidgets.widgets.WindowProvider.of(Globals.instance.nowContext).getScope()) { Window.instance.startCoroutine( TapOnUtils.WaitSomeTime( time: 0.5f, after: () => { Debug.Log("in back home!"); Globals.instance.returnHome(() => { Globals.instance.returnMap(); }); }) ); Window.instance.startCoroutine( TapOnUtils.upLoadFile( "img_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".jpg", "application/x-jpg", mark.snapShot_byte, wr => { Restful_FileUpLoadCallBack t = TapOnUtils.fileUpLoadCallBackfromJson(wr.downloadHandler.text); BmobFile bf = new BmobFile { filename = t.filename, url = t.url, group = t.cdnname }; Mark m = new Mark { snapShot = bf }; Bmob.Update( Mark.table_name, callback_mark.objectId, m, (resp, exception) => { if (exception != null) { Debug.Log("修改失败, 失败原因为: " + exception.Message); return; } Debug.Log("修改成功, @" + resp.updatedAt); }); })); Window.instance.startCoroutine( TapOnUtils.upLoadFile( "Props_" + DateTime.Now.ToString("yyyy-MM-,") + ".json", "application/json", mark.meta_byte, wr => { Restful_FileUpLoadCallBack t = TapOnUtils.fileUpLoadCallBackfromJson(wr.downloadHandler.text); BmobFile bf = new BmobFile { filename = t.filename, url = t.url, group = t.cdnname }; Mark m = new Mark { metaFile = bf }; Bmob.Update( Mark.table_name, callback_mark.objectId, m, (resp, exception) => { if (exception != null) { Debug.Log("修改失败, 失败原因为: " + exception.Message); return; } Debug.Log("修改成功, @" + resp.updatedAt); }); })); } }