public IEnumerator checkAndDownloadEggSprite(int index, CoroutineResponse response) { response.reset(); while (_eggDownloadingIndex == index) { yield return(null); // this image is currently being downloaded } if (_eggSprites.ContainsKey(index)) { response.setSuccess(true); yield break; } _eggDownloadingIndex = index; WWW www = new WWW(eggSpriteAtIndex(index)); yield return(www); if (string.IsNullOrEmpty(www.error)) { _eggSprites[index] = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0.5f, 0.5f)); response.setSuccess(true); } else { Debug.Log("egg error: " + www.error + "index: " + index.ToString()); MessageController.single.displayError(null, "Failed to load egg image.\n" + SpatialClient2.CHECK_YOUR_INTERNET_CONNECTION); response.setSuccess(false); } _eggDownloadingIndex = NO_DOWNLOAD; }
public IEnumerator addDestoryCityReward(int amount, CoroutineResponse winCoroutineEnded) { // START OF EMRE'S CODE yield return(SpatialClient2.single.updateLastRampageWithMultiplier(amount, currentMarkerId)); //mainMenuCamera.GetComponent<MainMenuScript>().addCheckedLocation(); winCoroutineEnded.setSuccess(true); // END OF EMRE'S CODE }
public IEnumerator initialize(int handSpriteIndex, int headSpriteIndex, int bodySpriteIndex, CoroutineResponse response) { response.reset(); CoroutineResponse handResponse = new CoroutineResponse(); CoroutineResponse bodyResponse = new CoroutineResponse(); CoroutineResponse headResponse = new CoroutineResponse(); StartCoroutine(checkAndDownloadBodySprite(bodySpriteIndex, bodyResponse)); StartCoroutine(checkAndDownloadHandSprite(handSpriteIndex, handResponse)); StartCoroutine(checkAndDownloadHeadSprite(headSpriteIndex, headResponse)); while (handResponse.Success == null || bodyResponse.Success == null || headResponse.Success == null) { yield return(null); } response.setSuccess(true); }
// assigns true to result.value if location service is ready, otherwise assigns false IEnumerator checkLocationService(CoroutineResponse result) { // make sure result's success value is null before beginning result.reset(); // base code from https://docs.unity3d.com/ScriptReference/LocationService.Start.html // Wait until service initializes int maxWait = LOCATION_INITIALIZED_QUERY_TIMEOUT * LOCATION_INITIALIZED_QUERIES_PER_SECOND; float timeBetweenQueries = 1.0f / LOCATION_INITIALIZED_QUERIES_PER_SECOND; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { yield return(new WaitForSeconds(timeBetweenQueries)); maxWait--; } if (maxWait > 0) { // false if location service disabled, null if timed out, true otherwise result.setSuccess(!(Input.location.status == LocationServiceStatus.Failed)); } }