public async Task <string> Write(IpfsGenesis gen, string addhash) { Debug.Log("Hi. Today, the hash I'm referencing is:" + addhash); GameObject ob = gameObject; if (ob.transform.childCount > 0) { List <Object> objects = new List <Object>(); List <MeshFilter> filter = GetChildRecursive(ob); foreach (Transform child in ob.transform) { filter.AddRange(GetChildRecursive(child.gameObject)); } foreach (MeshFilter f in filter) { objects.Add(new Object(f.mesh, f.gameObject)); } string hash = await IpfsIO.AddObject(objects, gen, addhash); return(hash); } else { Mesh mesh = GetComponent <MeshFilter>().mesh; Object onlyobject = new Object(mesh, gameObject); Object[] objectarray = new Object[1] { onlyobject }; string hash = await IpfsIO.AddObject(objectarray.ToList(), gen, addhash); return(hash); } }
public static async Task <string> AddObject(List <Object> obs, IpfsGenesis gen, string addhash) { string hashpath = Application.persistentDataPath + "/hash.txt"; string hashdatapath = Application.persistentDataPath + "/data.txt"; if (File.Exists(hashdatapath)) { File.Delete(hashdatapath); } StreamWriter txtobjectwriter = new StreamWriter(hashdatapath); txtobjectwriter.WriteLine("Hash:" + addhash); foreach (Object ob in obs) { MemoryStream memoryStream = new MemoryStream(); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, ob); string str = System.Convert.ToBase64String(memoryStream.ToArray()); txtobjectwriter.WriteLine(str); } txtobjectwriter.Close(); Ipfs.Cid taskA = await AddObjectSaveHash(hashdatapath); string hash = taskA.Hash.ToString(); Debug.Log(hash); StreamWriter txtwriter = new StreamWriter(hashpath); txtwriter.Write(hash); txtwriter.Close(); return(hash); }