Unity实时读取天气预报等信息在UGUI显示 附带Demo导入unity直接可用

Unity实时读取天气预报等信息在UGUI显示  附带Demo导入unity直接可用

部分代码:

 IEnumerator Post(string url, Dictionary post)
    {
        //表单
        WWWForm form = new WWWForm();
        //从集合中取出所有参数,设置表单参数(AddField())
        foreach (KeyValuePair post_arg in post)
        {
            form.AddField(post_arg.Key, post_arg.Value);
        }
        //表单传值,就是post
        WWW www = new WWW(url, form);
        yield return www;
        if (www.error != null)
        {
            Message = "PostError: " + www.error;
        }
        else
        {
            Message = www.text;
        }
    }
    IEnumerator GetMPic(string PicURL)
    {
        WWW www = new WWW(PicURL);
        yield return www;
        if (www.error != null)
        {
        }
        else
        {
            Mpic = www.texture;
            Sprite wode = Sprite.Create(Mpic, new Rect(0, 0, Mpic.width, Mpic.height), new Vector2(0, 0));
            myT.sprite = wode;
        }
    }
     IEnumerator Get(string url, Dictionary get)
    {
        string parameters;
        bool first;
        if (get.Count > 0)
        {
            first = true;
            parameters = "?";
            //从集合中取出所有参数,设置表单参数(AddField()).
            foreach (KeyValuePair get_arg in get)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    parameters += "%";
                }
                parameters += get_arg.Key + "=" + get_arg.Value;
            }
        }
        else
        {
            parameters = "";
        }
        TestShoe = "GetURL: " + parameters;
        WWW www = new WWW(url + parameters);
        yield return www;

        if (www.error != null)
        {
            Message = "GetError: " + www.error;
        }
        else
        {
            Message = www.text;
        }
    }

效果展示:

Unity实时读取天气预报等信息在UGUI显示 附带Demo导入unity直接可用_第1张图片

当然这里用的是XML格式展示出来的,你们可以写一个类,然后工整的输出,效果会很好。

Demo连接:https://download.csdn.net/download/qwbin/10650413

辛辛苦苦写的还是要收取的C币的。但是亲测可用。在UGUI上显示信息。还有二维码。

github  https://github.com/TaylorGeGe/Unity3DWeather

你可能感兴趣的:(Unity实时读取天气预报等信息在UGUI显示 附带Demo导入unity直接可用)