/** The coroutine for loading the asset bundle from the application data directory. */ IEnumerator LoadAssetBundle() { string path = Path.Combine(Application.persistentDataPath, m_filenameAssetBundle); if (!File.Exists(path)) { m_assetBundleLoadStat = AssetBundleLoadStat.Success; yield break; } string url = "file://" + path; Debug.Log("[INFO] Issuing a file request : " + url); WWW www = new WWW(url); // Wait for completion of the request. while (true) { if (string.IsNullOrEmpty(www.error)) { if (www.isDone) { break; } } else { m_assetBundleLoadStat = AssetBundleLoadStat.Fail; PutErrorMessage("Failed to load the asset bundle : " + www.error); yield break; } yield return(null); } // NOTE: // On iOS, WWW doesn't seem to give us any error message when some error occurs. if (www.assetBundle == null) { PutErrorMessage("Failed to load the asset bundle (no error messages)"); m_assetBundleLoadStat = AssetBundleLoadStat.Fail; yield break; } // Extract all the image data from the asset bundle. UnityEngine.Object[] images = www.assetBundle.LoadAllAssets(typeof(Texture2D)); int i; for (i = 0; i < images.Length; i++) { Texture2D tex = images[i] as Texture2D; Debug.Log("Loaded from the asset bundle : " + tex.name); m_images[tex.name] = tex; } // Unload all the unnecessary (unused) objects. www.assetBundle.Unload(false); m_assetBundleLoadStat = AssetBundleLoadStat.Success; }
void Update() { if (m_initProcStat != InitProcStat.InProgress) { return; } if (m_assetBundleLoadStat == AssetBundleLoadStat.None) { // Start loading the asset bundle. m_assetBundleLoadStat = AssetBundleLoadStat.InProgress; StartCoroutine(LoadAssetBundle()); } else if (m_assetBundleLoadStat == AssetBundleLoadStat.Success) { // We've succeeded in loading the asset bundle. // Load the XML configuration file from the cache directory, and create the TPTabletUIConfig instance. string path = Path.Combine(Application.persistentDataPath, m_filenameXML); byte[] bytes; try { bytes = File.ReadAllBytes(path); }catch (Exception e) { PutErrorMessage("TPTabletUIManager::Update"); PutErrorMessage(e.Message); m_initProcStat = InitProcStat.Fail; return; } m_config = new TPTabletUIConfig(); if (!m_config.Parse(bytes)) // All the GUI data files are loaded during parsing. { m_config = null; m_initProcStat = InitProcStat.Fail; return; } m_initProcStat = InitProcStat.Success; // The initialization procedure has successfully ended. } else if (m_assetBundleLoadStat == AssetBundleLoadStat.Fail) { // We've failed in loadind the asset bundle. m_initProcStat = InitProcStat.Fail; return; } }