Unity實時讀取天氣預報等資訊在UGUI顯示 附帶Demo匯入unity直接可用
Unity實時讀取天氣預報等資訊在UGUI顯示 附帶Demo匯入unity直接可用
部分程式碼:
IEnumerator Post(string url, Dictionary<string, string> post)
{
//表單
WWWForm form = new WWWForm();
//從集合中取出所有引數,設定表單引數(AddField())
foreach (KeyValuePair<string, string> 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<string, string> get)
{
string parameters;
bool first;
if (get.Count > 0)
{
first = true;
parameters = "?";
//從集合中取出所有引數,設定表單引數(AddField()).
foreach (KeyValuePair<string, string> 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;
}
}
效果展示:
當然這裡用的是XML格式展示出來的,你們可以寫一個類,然後工整的輸出,效果會很好。
Demo連線:https://download.csdn.net/download/qwbin/10650413
辛辛苦苦寫的還是要收取的C幣的。但是親測可用。在UGUI上顯示資訊。還有二維碼。