在Unity中加载LZMA压缩文件时滞后

时间:2017-09-21 17:06:39

标签: c# multithreading performance unity3d lzma

我在Unity 3D中编写了简单的地形加载。使用此工具压缩地形:https://bitbucket.org/Agent_007/lzma-unity/overview。 我正在使用这个脚本,我写道:

void loadAfterFirst() {
        byte[] terrainBytes = File.ReadAllBytes(Path.Combine(streamingAssetsPathVar, "terrain/" + Chunk + ".terrain"));
        BinaryFormatter bf = new BinaryFormatter();
        //FileStream stream = new FileStream(Path.Combine(Application.streamingAssetsPath, "terrain/" + Chunk + ".terrain"), FileMode.Open);
        LoadingSavingClass myClass = bf.Deserialize(new MemoryStream(LZMAtools.DecompressLZMAByteArrayToByteArray(terrainBytes))) as LoadingSavingClass;

        terrain = myClass.terrain;
}

但是当我加载它时,在测试时启动此功能,整个游戏冻结,我必须等到它加载。我把这个功能放到新的线程中并没有帮助。如果你想看看我如何写线程,它看起来像这样:

Thread t = new Thread(new ThreadStart(loadAfterFirst));
t.Start();    // Starts new thread

0 个答案:

没有答案
相关问题