private IEnumerator UpdateMatch() { WWW www = new WWW("https://api.guildwars2.com/v2/wvw/matches?world=" + Config.Instance.worldId); yield return(www); if (www.error != null) { Debug.Log("WWW Error: " + www.error); yield break; } mMatch = JsonConvert.DeserializeObject <Gw2Match>(www.text); fullyLoaded = true; }
private IEnumerator MainLoop() { Debug.Log("Initializing wvw data..."); string url = "https://api.guildwars2.com/v2/worlds?ids=all"; yield return(StartCoroutine(RestCache.Get(mWorldPath, url))); mWorlds = JsonConvert.DeserializeObject <List <Gw2World> >(RestCache.mJsonData); mWorlds.Sort((x, y) => x.name.CompareTo(y.name)); Debug.Log("Servers: " + mWorlds.Count); RefreshDropDown(); url = "https://api.guildwars2.com/v2/wvw/objectives?ids=all"; yield return(StartCoroutine(RestCache.Get(mObjectivesPath, url))); mObjectivesList = JsonConvert.DeserializeObject <List <Gw2Objective> >(RestCache.mJsonData); mObjectiveMap = new Dictionary <string, Gw2Objective>(); Debug.Log("Objectives: " + mObjectivesList.Count); foreach (var objective in mObjectivesList) { mObjectiveMap[objective.id] = objective; } url = "https://api.guildwars2.com/v2/maps?ids=38,95,96,1099"; yield return(StartCoroutine(RestCache.Get(mMapsPath, url))); var maps = JsonConvert.DeserializeObject <List <Gw2Map> >(RestCache.mJsonData); foreach (var map in maps) { mMapTable[map.id] = map; } Debug.Log("Maps: " + mMapTable.Count); url = "https://api.guildwars2.com/v2/wvw/matches?world=" + Config.Instance.worldId; yield return(StartCoroutine(RestCache.Get(mMatchesPath, url))); mMatch = JsonConvert.DeserializeObject <Gw2Match>(RestCache.mJsonData); fullyLoaded = !RestCache.mCached; if (RestCache.mCached) { StartCoroutine(UpdateMatch()); } int limiter = 0; while (isInWvwMap && isActiveAndEnabled) { if (++limiter > 5) { StartCoroutine(UpdateMatch()); limiter = 0; } Gw2MatchMap mapItem = mMatch.maps.Find(x => x.id == mMapId); if (mapItem != null) { RefreshMap(mapItem); } yield return(new WaitForSeconds(1.0f)); } mainLoop = null; }