private IEnumerator BuildWorld(WWW req)
    {
        yield return(req);

        WorldData.World world = JsonConvert.DeserializeObject <WorldData.World>(req.text);
        GenerateWorld(world);
    }
    private void GenerateWorld(WorldData.World world)
    {
        WorldData.Layer   l;
        WorldData.Layer   objectLayer;
        Portal            portal;
        GameObject        layer;
        GameObject        portalObj;
        MeshFilter        meshFilter;
        PolygonCollider2D polygonCollider;
        MeshRenderer      meshRenderer;
        Mesh           mesh;
        List <Vector2> line;
        List <Vector3> vertices;
        List <int>     triangles;
        List <Vector2> uvs;
        List <string>  sprite_ids = new List <string>();
        SpriteData     data;
        FileStream     fileStream;

        for (int j = 0; j < world.layers.Count; j++)
        {
            l         = world.layers[j];
            layer     = (GameObject)Instantiate(_layer);
            mesh      = new Mesh();
            vertices  = new List <Vector3>();
            uvs       = new List <Vector2>();
            triangles = new List <int>();
            line      = WorldData.Layer.GetCurvedLine(l.x, l.y);
            foreach (Vector2 point in line)
            {
                vertices.Add(new Vector3(point.x, point.y, 0.0f));
            }
            triangles = WorldData.Layer.GenerateTriangles(line);
            foreach (Vector2 vec in vertices)
            {
                uvs.Add(new Vector2(vec.x / l.size, vec.y / 100));
            }

            foreach (WorldData.Sprite sprite in l.sprites)
            {
                if (File.Exists(cachePath + "/Sprites/" + sprite.id + ".bin"))
                {
                    if (!sprites.ContainsKey(sprite.id))
                    {
                        fileStream = new FileStream(cachePath + "/Sprites/" + sprite.id + ".bin", FileMode.Open);
                        data       = (SpriteData)formatter.Deserialize(fileStream);
                        AddSprite(sprite.id, data);
                    }
                }
                else if (!sprite_ids.Contains(sprite.id))
                {
                    sprite_ids.Add(sprite.id);
                }
            }

            //init mesh
            mesh.vertices  = vertices.ToArray();
            mesh.triangles = triangles.ToArray();
            mesh.uv        = uvs.ToArray();
            mesh.RecalculateBounds();
            meshFilter      = layer.GetComponent <MeshFilter>();
            meshFilter.mesh = mesh;
            if (j == 4)
            {
                polygonCollider = layer.GetComponent <PolygonCollider2D>();
                List <Vector2> vert2 = new List <Vector2>();
                foreach (Vector3 vert in vertices)
                {
                    vert2.Add(new Vector2(vert.x, vert.y - 1.0f));
                }
                polygonCollider.points = vert2.ToArray();
            }
            meshRenderer = layer.GetComponent <MeshRenderer>();
            meshRenderer.material.SetColor("_Color", new Color(l.color[0] / 255.0f, l.color[1] / 255.0f, l.color[2] / 255.0f));
            layer.name  = "Layer" + j;
            layer.layer = LayerMask.NameToLayer(layer.name.ToLower());
            layer.transform.position = new Vector3(-(16.0f / 9.0f) * 5.0f, 0.0f, world.layers.Count - j);
            objectLayer = layer.GetComponent <WorldData.Layer>();
            objectLayer.Copy(l);
        }

        layer = GameObject.Find("Layer4");
        player.GetComponent <Rigidbody2D>().isKinematic = false;

        foreach (Portal p in world.layers[4].portals)
        {
            portalObj       = (GameObject)Instantiate(_portal);
            portal          = portalObj.GetComponent <Portal>();
            portal.x        = p.x;
            portal.y        = p.y;
            portal.name     = p.name;
            portal.link     = p.link;
            portal.title    = title;
            portalObj.layer = layer.layer;
            portalObj.transform.position = new Vector3(world.layers[4].Ratio * (p.x / 10.0f - 5.0f), (100 - p.y) / 10.0f - 5.0f, 0.0f);
            portalObj.transform.parent   = layer.transform;
        }
        this.world = world;
        Movement movement = player.GetComponent <Movement>();

        movement.SetPlayerPosition();
        if (sprite_ids.Count > 0)
        {
            string ids = JsonConvert.SerializeObject(sprite_ids);
            request.Request("SpriteBuilder/_GetSpriteSources", ids, AddSprites);
        }
        else
        {
            if (start_portal != "")
            {
                request.Request("Worlds/_GetPortal?id=" + start_portal, SetInitialPosition);
            }
            AddSpriteObjectsToWorld(new Dictionary <string, Tuple <string, bool, string> >());
        }
    }