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);
        }
Example #2
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);
                    });
                }));
            }
        }