/// <summary> /// Loads required assets for the game. /// </summary> public static void Initialize(MonoBehaviour coroutineOwner, string[] modBundlePaths, OnInitializeCallback onInitCB) { // Load art file try { // Prepare Legacy manager _LegacyAssets = new ResourceManager("."); // Get art file Stream artPartStream = _LegacyAssets.GetResourceStream("op2_art.prt"); _ArtFile = ArtFile.Read(artPartStream); } catch (System.Exception ex) { Debug.LogException(ex); // Inform caller of failure onInitCB?.Invoke(false); return; } // Load asset bundle coroutineOwner.StartCoroutine(LoadAssetsRoutine(modBundlePaths, onInitCB)); }
private static IEnumerator LoadAssetsRoutine(string[] modBundlePaths, OnInitializeCallback onInitCB) { // Load mod bundles foreach (string bundlePath in modBundlePaths) { AssetBundleCreateRequest bundleRequest = AssetBundle.LoadFromFileAsync(Path.Combine(Application.streamingAssetsPath, bundlePath)); yield return(bundleRequest); if (bundleRequest.assetBundle != null) { _ModBundles.Add(bundleRequest.assetBundle); } } // Prepare legacy art loader try { _LegacyArt = new OP2BmpLoader("OP2_ART.BMP", _ArtFile); } catch (System.Exception ex) { Debug.LogWarning(ex); } yield return(null); float startTime = Time.realtimeSinceStartup; float curTime = startTime; // Load textures for (int i = 0; i < _ArtFile.imageMetas.Count; ++i) { Texture2D texture = GetAssetFromModBundle <Texture2D>("Bitmap" + i); if (texture != null) { _TextureLookup[i] = texture; _SpriteLookup[i] = Sprite.Create(texture, new UnityEngine.Rect(0, 0, texture.width, texture.height), Vector2.zero, 1); } else if (_LegacyArt != null) { // Load legacy texture try { OP2BitmapFile bitmap = _LegacyArt.GetImage(i); texture = GetTextureFromBMP(bitmap); _TextureLookup[i] = texture; _SpriteLookup[i] = Sprite.Create(texture, new UnityEngine.Rect(0, 0, texture.width, texture.height), Vector2.zero, 1); } catch (System.Exception ex) { Debug.LogException(ex); Debug.LogError("BmpIndex: " + i); } } else { // Could not find texture! Debug.LogError("Could not find texture for index: " + i); // Inform caller of failure onInitCB?.Invoke(false); yield break; } // Every X seconds, take a break to render the screen if (curTime + 0.25f < Time.realtimeSinceStartup) { yield return(null); curTime = Time.realtimeSinceStartup; } } Debug.Log("Texture Load Time: " + (Time.realtimeSinceStartup - startTime).ToString("N2") + " seconds"); yield return(LoadSoundsRoutine("sound.vol")); yield return(LoadSoundsRoutine("voices.vol")); Debug.Log("Total Load Time: " + (Time.realtimeSinceStartup - startTime).ToString("N2") + " seconds"); // Inform caller of success onInitCB?.Invoke(true); }