Exemple #1
0
    private void Update()
    {
        if (objects != null && !generate)
        {
            Debug.Log("Stream received");
            GameObject parent = gameObject;
            foreach (Object ob in objects)
            {
                GameObject newob = ob.GameObject();
                newob.transform.parent        = parent.transform;
                gameObject.transform.position = new Vector3(ob.positionx, ob.positiony, ob.positionz);
                newob.GetComponent <MeshRenderer>().material = new Material(Shader.Find("Diffuse"));
            }
            generate = true;
        }

        if (nexthash != "" && !Shifted)
        {
            string        hash      = PlayerPrefs.GetString("StartHash");
            GameObject    newobject = new GameObject();
            IpfsGenerated gen       = newobject.AddComponent <IpfsGenerated>();

            Thread readthread = new Thread(() => IpfsIO.ReadObject(nexthash, gen));
            readthread.Start();

            Shifted = true;
        }
    }
Exemple #2
0
    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);
        }
    }
    //If not write, read.

    // Use this for initialization
    void Start()
    {
        if (Write)
        {
            Task t = Extensions.Iterate(WriteInSequence());
        }
        else
        {
            string        hash      = PlayerPrefs.GetString("StartHash");
            GameObject    newobject = new GameObject();
            IpfsGenerated gen       = newobject.AddComponent <IpfsGenerated>();

            Thread readthread = new Thread(() => IpfsIO.ReadObject(hash, gen));
            readthread.Start();
        }
    }