1

只是为了消除对代码所做的任何混淆,它需要一个“对象”类(浮点数和数字类),写入文件(使用二进制格式),并使用 IPFS.Net 实现将文件写入网络。创建文件没问题,但是当保存文件时,代码在 Unity 中无限期挂起。代码如下:

public static class IPFS_IO
{
    public static void AddObject(Object obs)
    {
        string path = Application.persistentDataPath + "/data.bytes";
        if (File.Exists(path))
        {
            File.Delete(path);
        }

        FileStream stream = File.Create(path);
        BinaryFormatter formatter = new BinaryFormatter();
        formatter.Serialize(stream, obs);
        stream.Close();

        Task<Ipfs.IFileSystemNode> taskA = AddObjectSaveHash(path);
        taskA.Wait();

        //string hashpath = Application.persistentDataPath + "/hash.txt";

        //StreamWriter writer = new StreamWriter(hashpath);
        //writer.Write(hash);
        //writer.Close();
    }

    async static Task<Ipfs.IFileSystemNode> AddObjectSaveHash(string path)
    {
        Batteries.Init();

        using (var ie = new IpfsEngine("".ToCharArray()))
        {
            return await ie.FileSystem.AddFileAsync(path)
                           .ConfigureAwait(false);
        }
    }

这是一个常见的死锁,还是输入网络的数据过多?牢记:

a) 这是在 Unity 游戏引擎中使用的 C# 实现

b)我正在使用 Richard Schneiders 实现(github:https ://github.com/richardschneider/net-ipfs-engine )

感谢你们发现的任何帮助或问题。

4

0 回答 0