【发布时间】:2015-08-10 10:42:36
【问题描述】:
我在游戏中刷新/重新加载带有高分列表的弹出窗口时遇到问题。在 unity 5 模拟器中一切正常,但在 Windows Phone 设备上不行。
问题:当我玩完游戏后,它会将分数上传到云端。然后当我进入高分菜单(游戏在这里下载高分)时,Windows Phone 上没有最新的高分列表(在统一模拟器中,一切正常)。有趣的是,当我关闭游戏并再次运行它并进入高分菜单时,高分列表是最新的。游戏分数上传正确,我在服务器站点上检查过。
有没有办法解决这个问题?
编辑: 我正在使用 dreamlo.com 来存储分数。 通过这种方式,我可以向 Dreamloo 上传/下载乐谱:
using UnityEngine;
using System.Collections;
public class Highscores : MonoBehaviour {
const string privateCode = "myprivatecode (random characters)";
const string publicCode = "mypubliccode(random characters)";
const string webURL = "http://dreamlo.com/lb/";
DisplayHighscores highscoresDisplay;
public Highscore[] highscoresList;
static Highscores instance;
void Awake(){
highscoresDisplay = GetComponent<DisplayHighscores> ();
instance = this;
}
public static void AddNewHighscore(string username, int score){
instance.StartCoroutine(instance.UploadNewHighscore(username,score));
}
IEnumerator UploadNewHighscore(string username, int score)
{
WWW www = new WWW (webURL + privateCode + "/add/" + WWW.EscapeURL (username) + "/" + score);
yield return www;
if (string.IsNullOrEmpty (www.error)){
print ("Uploaded Successful");
DownloadHighscores();
}
else {
print ("Error uploading: " + www.error);
}
}
public void DownloadHighscores(){
StartCoroutine ("DownloadHighscoreFromDatabase");
}
IEnumerator DownloadHighscoreFromDatabase()
{
WWW www = new WWW (webURL + publicCode + "/pipe/");
yield return www;
if (string.IsNullOrEmpty (www.error)) {
FormatHighscores (www.text);
highscoresDisplay.OnHighscoresDownloaded(highscoresList);
}
else {
print ("Error downloading: " + www.error);
}
}
void FormatHighscores(string textStream){
string[] entries = textStream.Split(new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries);
highscoresList = new Highscore[entries.Length];
for (int i = 0; i <entries.Length; i ++) {
string[] entryInfo = entries[i].Split (new char[] {'|'});
string username = entryInfo[0];
int score = int.Parse(entryInfo[1]);
highscoresList[i] = new Highscore(username, score);
print(highscoresList[i].username + ": " + highscoresList[i].score);
}
}
}
public struct Highscore{
public string username;
public int score;
public Highscore(string _username, int _score){
username = _username;
score = _score;
}
}
高分显示该课程:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class DisplayHighscores : MonoBehaviour {
public Text[] highscoreText;
Highscores highscoreManager;
void Start () {
for (int i = 0; i<highscoreText.Length; i++) {
highscoreText[i].text = i+1 + ". Fetching...";
}
highscoreManager = GetComponent<Highscores>();
StartCoroutine ("RefreshHighscores");
}
public void OnHighscoresDownloaded(Highscore[] highscoreList){
for (int i = 0; i < highscoreText.Length; i++) {
highscoreText[i].text = i+1 + ". ";
if(highscoreList.Length > i){
highscoreText[i].text += highscoreList[i].username + " - " + highscoreList[i].score;
}
}
}
IEnumerator RefreshHighscores(){
while (true) {
highscoreManager.DownloadHighscores();
yield return new WaitForSeconds(30);
}
}
}
【问题讨论】:
-
添加更多关于错误或您认为可能导致问题的代码的信息。
标签: c# windows-phone-8 unity3d reload updating