public static string WriteSchemeJson(string name, object obj)
    {
        string jsonData = null;
        // 文件具体路径
        string Direct = getMyPersistentPath("Scheme");
        // 文件的具体路径 在文件夹下面
        string path = Direct + "/" + name;

        jsonData = MyJsonTool.ToJson(obj);
        DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(path));

        if (!directoryInfo.Exists)
        {
            Debug.Log("文件不存在");
            directoryInfo.Create();
        }
        else
        {
            FileInfo info = new FileInfo(path);
            if (info.Exists)
            {
                File.Delete(path);
            }
        }
        using (StreamWriter stream = new StreamWriter(path, true, System.Text.Encoding.UTF8))
        {
            stream.WriteLine(jsonData);
        }
        return(jsonData);
    }
    //private static SchemeManifest schemeManifest { get { return SchemeManifest.instance; } }
    // 读取JSON 数据
    public static string ReadSchemeJson(string name, object obj)
    {
        // json 数据
        string jsonData = null;
        // 文件具体路径   Dir 文件夹
        string Direct = getMyPersistentPath("Scheme");
        // 文件的具体路径 在文件夹下面
        string path = Direct + "/" + name;

        // 判断文件夹是否存在
        if (!File.Exists(path))
        {
            DirectoryInfo dir = new DirectoryInfo(Direct);
            dir.Create();
            FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            fs.Close();
            //对象 -> json   序列化
            jsonData = MyJsonTool.ToJson(obj);
            return(jsonData);
        }
        // 从绝对路径读取JSON
        using (StreamReader stream = new StreamReader(path, System.Text.Encoding.UTF8))
        {
            jsonData = stream.ReadToEnd();
        }
        return(jsonData);
    }
Esempio n. 3
0
 public void AddSchemeCache(OriginalProjectData data, string json = null)
 {
     if (string.IsNullOrEmpty(json))
     {
         json = MyJsonTool.ToJson(data);
     }
     if (data.isUnUpload == true)
     {
         cacheLocalSchemeManager.AddSchemeCache(data.tempId, json);
         //Debug.Log("data.isUnUpload == true");
     }
     else
     {
         cacheServerSchemeManager.AddSchemeCache(data.id, json);
         //Debug.Log("data.isUnUpload == false");
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 生成报价、加载报价后缓存、
 /// </summary>
 /// <param name="data"></param>
 /// <param name="json"></param>
 public void AddOfferCache(PriceData data, string json = null)
 {
     if (string.IsNullOrEmpty(json))
     {
         json = MyJsonTool.ToJson(data);
     }
     if (data.isUnUpload == true)
     {
         cacheLocalOfferManager.AddOfferCache(data.tempId, json);
         //Debug.Log("AddOfferCache data.isUnUpload == true");
     }
     else
     {
         cacheServerOfferManager.AddOfferCache(data.serverId, json);
         //Debug.Log("AddOfferCache data.isUnUpload == false");
     }
 }
    public void Start()
    {
        Object obj = Resources.Load("design");
        string msg = obj.ToString();

        Debug.Log(msg);
        //JsonProjectData data = new JsonProjectData();
        //data.meta = new JsonProjectData.JsonMeta();
        //data.data.Add(new JsonProjectData.JsonCameraData());
        //data.data.Add(new JsonProjectData.JsonContentData());
        //data.data.Add(new JsonProjectData.JsonCoWallData());
        //data.data.Add(new JsonProjectData.JsonDoorData());
        //data.data.Add(new JsonProjectData.JsonFloorplan());
        //data.data.Add(new JsonProjectData.JsonMaterialData());
        //data.data.Add(new JsonProjectData.JsonModelData());
        //data.data.Add(new JsonProjectData.JsonMoldingData());
        //data.data.Add(new JsonProjectData.JsonPointData());
        //data.data.Add(new JsonProjectData.JsonRoom());
        //data.data.Add(new JsonProjectData.JsonUnderlayData());
        //data.data.Add(new JsonProjectData.JsonWallData());
        //data.products.Add(new JsonProjectData.JsonProductData());
        //string msg = MyJsonTool.ToJson(data);

        JsonProjectData data = MyJsonTool.ReadProjectJson(msg);
        //string str = MyJsonTool.ToJson(data);
        //Debug.Log(data);
        //Debug.Log(str);
        string outpath = Application.dataPath + "/msg.txt";

        using (StreamWriter writer = new StreamWriter(outpath, true, System.Text.Encoding.UTF8))
        {
            writer.WriteLine(msg);
        }

        string msg2     = MyJsonTool.ToJson(data);
        string outpath2 = Application.dataPath + "/msg2.txt";

        using (StreamWriter writer = new StreamWriter(outpath2, true, System.Text.Encoding.UTF8))
        {
            writer.WriteLine(msg2);
        }
    }
    public static void sendToIOS(MsgToIOS msg, string ListionType = "", Action <MyEvent> handle = null)
    {
        if (string.IsNullOrEmpty(ListionType) == false)
        {
            myEventDispatcher.addEventListener(ListionType, handle);
        }

        string json = MyJsonTool.ToJson(msg);

        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            //if (msg.code == "101002" || msg.code == "101003")
            //{
            //    Mode2DPrefabs.Instance.mainCamera.enabled = false;
            //}
            Debug.Log("sendToIOS:" + json);
            sendToIOS(json);
        }
        else
        {
            Debug.Log("sendToIOS + " + json);
        }
    }
    //private void SaveOffer()
    //{
    //    TestPrice price = new TestPrice();
    //    price.prices = undoHelper.currentData.schemeManifest.prices;
    //    string json = MyJsonTool.ToJson(price);
    //    WriteToLocal(Application.dataPath + "/offer.json", json);
    //}

    private IEnumerator Func(object[] arg1)
    {
        yield return(new WaitForEndOfFrame());

        OriginalProjectData data = new OriginalProjectData();

        //Camera camera3D = prefabs.mainCamera;
        //if (inputMachine.currentInputIs2D)
        //{
        //    view3D.RefreshView();
        //    prefabs.helpCamera.gameObject.SetActive(true);
        //    camera3D = prefabs.helpCamera;
        //}
        TouchCaptureScreen.Instance.AoutCaptureScreenImage();

        yield return(new WaitForSeconds(0.01f));

        yield return(new WaitForEndOfFrame());

        yield return(new WaitForSeconds(0.01f));

        yield return(new WaitForEndOfFrame());

        Texture2D texture = TouchCaptureScreen.Instance.texture; //CaptureScreen.Instance.CaptureCamera(camera3D);

        //mainpage.image.texture = texture;

        string textureEncoding = "";

        if (texture != null)
        {
            byte[] bytes = texture.EncodeToJPG();
            GameObject.DestroyImmediate(texture, true);
            texture = null;
            Resources.UnloadUnusedAssets();
            if (inputMachine.currentInputIs2D)
            {
                //prefabs.helpCamera.gameObject.SetActive(false);
            }
            textureEncoding = System.Convert.ToBase64String(bytes,
                                                            0,
                                                            bytes.Length,
                                                            Base64FormattingOptions.None
                                                            );

            Debug.LogWarning("截屏成功");
        }
        else
        {
            Debug.LogWarning("截屏失败");
        }
        //if (Application.platform == RuntimePlatform.WindowsEditor)
        //{
        //    Debug.Log(textureEncoding);
        //    WriteToLocal(Application.dataPath + "/OriginalProjectJson/textureEncoding/texture.txt", textureEncoding);
        //}
        schemeManifest.meta = data.meta = "data:image/jpeg;base64," + textureEncoding;
        originalInputData.BeforetSerializeFieldDo();
        data.data = originalInputData;
        //SchemeManifest schemeManifest = schemePageControl.schemeManifest;
        data.name        = schemeManifest.name;
        data.description = schemeManifest.description;
        data.isNew       = schemeManifest.isNew;
        data.id          = schemeManifest.id;
        data.tempId      = schemeManifest.tempId;
        data.priceIdList = schemeManifest.prices;
        data.version     = schemeManifest.version;

        string json = MyJsonTool.ToJson(data);

        jsonCacheManager.AddSchemeCache(data, json);

        MsgToIOS msg = new MsgToIOS();

        msg.code = "101004";
        MsgToIOS.InfoToIOS info = new MsgToIOS.InfoToIOS();
        info.projectData = data;
        info.type        = data.isNew == true ? 0 : 1;
        msg.info         = info;
        if (info.type == 0)
        {
            UnityIOSMsg.sendToIOS(msg, IOSEvent.SetSchemeId, CreatScheme);
        }
        else
        {
            UnityIOSMsg.sendToIOS(msg);
            controller.dispatchEvent(new MyEvent(MySaveSchemeToShare.SaveSchemeToShare));
        }

        setState(MainPageFreeState.Name);
        undoHelper.ResetSaveId();
    }