unity打不开项目显示为只读文件

unity打不开项目显示为只读文件,第1张

unity打不开项目显示为只读文件的解决方法:

1、Android端代燃唤碧码可以在Eclipse中开发(AndroidStudio没有试,应该也可以)。

2、Android和Unity3D端,两边都需要加入一些代码从而可以皮举使之关联链凯交互。

3、将Android端代码编译成jar文件以插件形式放入到Unity端中。

方法一 直接传结构体与保持文件名字

  public void WriteJson(object ob, string jsonName)

    {

        string json = LitJson.JsonMapper.ToJson(ob)

        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json)

        string filePath = Application.dataPath + "/Resources/" + jsonName + ".json"

        using (System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))

        {

            stream.Write(bytes, 0, bytes.Length)

        }

        UnityEditor.AssetDatabase.Refresh()//属性掘薯困Asset,生成完成后立刻可以看到文件

    }

方法二 jsonwriter 半编译写法

  void CreateJson()

    {

        string path = Application.dataPath + "/Resources/Jsons/" + objBase.transform.name + ".json"

        FileInfo fileInfo = new FileInfo(path)

        StreamWriter sw = fileInfo.CreateText()

        StringBuilder sb = new StringBuilder()

        JsonWriter jsonwriter = new JsonWriter(sb)

        jsonwriter.WriteObjectStart()//1

        for (int i = 0i <numbers.Counti++)

        {

            jsonwriter.WritePropertyName("Number" + (i + 1))

            jsonwriter.WriteObjectStart()//1-1

            type = new List<Transform>()

            foreach (Transform child in numbers[i].transform)

                type.Add(child)

            jsonwriter.WritePropertyName("TypeCount")jsonwriter.Write(type.Count)

         手举   for (int j = 0j <type.Countj++)

            {

                jsonwriter.WritePropertyName("Type"判念 + (j + 1))

                jsonwriter.WriteObjectStart()//1-1-1

                pos = new List<Transform>()

                foreach (Transform child in type[j].transform)

                    pos.Add(child)

                jsonwriter.WritePropertyName("Size")jsonwriter.Write(pos[0].transform.localScale.x.ToString())

                jsonwriter.WritePropertyName("Pos")

                jsonwriter.WriteArrayStart()

                for (int k = 0k <pos.Countk++)

                {

                    jsonwriter.Write("(" + pos[k].transform.localPosition.x + "," + pos[k].transform.localPosition.y + ")")

                }

                jsonwriter.WriteArrayEnd()

                jsonwriter.WriteObjectEnd()//1-1-1

            }

            jsonwriter.WriteObjectEnd()//1-1

        }

        jsonwriter.WriteObjectEnd()//1

        sw.WriteLine(sb.ToString())

        sw.Close()

        AssetDatabase.Refresh()

    }

Json 里面的数据是double 类型,使用float 会出问题

double.Parse  float .Parse    不一样


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12244326.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存