public IEnumerator CoGetSpriteFromAtlasAsync(string name, LoadSpriteDelegate onLoadComplete) { FirebaseManager.CheckWaitForReady((object sender, bool success) => { if (success) { FirebaseManager.LogCrashlytics($"{Const.CRASHLYTIC_LOG_PICTURE}_{name}"); } }); //check if atlas exist string atlasAddress = GetAtlasAddressFromPictureName(name); ResourceRequest request = null; SpriteAtlas atlas = null; if (coroutineIsRunning) { Debug.LogWarning("This asynchronous operation is already being yielded from another coroutine."); } while (coroutineIsRunning) { yield return(0); } coroutineIsRunning = true; yield return(StartCoroutine(ResourcesPreloader.CoLoad <SpriteAtlas>(atlasAddress, (sender, cachedOperation) => { atlas = cachedOperation as SpriteAtlas; }))); coroutineIsRunning = false; //ResourceRequest request = Resources.LoadAsync<SpriteAtlas>(atlasAddress); //yield return request; if (atlas == null) { atlasAddress = GetAtlasAddressFromPictureName("OTHER"); //request = Resources.LoadAsync<SpriteAtlas>(atlasAddress); //yield return request; yield return(StartCoroutine(ResourcesPreloader.CoLoad <SpriteAtlas>(atlasAddress, (sender, cachedOperation) => { atlas = cachedOperation as SpriteAtlas; }))); } var req = request; Sprite spr = atlas.GetSprite(name); if (spr == null) { Debug.LogError($"Sprite [{name}] not found in atlas {atlasAddress}"); } onLoadComplete?.Invoke(spr); }
public void GetSpriteFromAtlasAsync(string name, LoadSpriteDelegate onLoadComplete) { StartCoroutine(CoGetSpriteFromAtlasAsync(name, onLoadComplete)); }