private IEnumerator ReadAssetBundleFileCoroutine(Stream stream, Action<Byte[], ECAssetBundleHeader> onFinish) { if (stream == null) { //失败 if (onFinish != null) onFinish(null, null); yield break; } ECAssetBundleHeader bh = new ECAssetBundleHeader(); bh.Load(stream); Byte[] fileData = new Byte[stream.Length-stream.Position]; stream.Read(fileData, 0, fileData.Length); stream.Dispose(); //stream 已经用完了。由于是异步操作,只能由调用者释放 if (onFinish != null) onFinish(fileData, bh); }
public static void LoadAssetBundleImmediate(String path, Action<AssetBundle, ECAssetBundleHeader, bool> onFinish) { Stream stream = FileLoader.LoadFile(path); if (stream == null) { //Debug.LogError("failed to open asset bundle file: " + path); //在回调里自行处理 } ECAssetBundleHeader bh = new ECAssetBundleHeader(); bh.Load(stream); CreateBundleImmediate(stream, bh, onFinish, path); }
public static void LoadAssetBundleFromSepFile(String path, string depFilePath, Action<AssetBundle, ECAssetBundleHeader, bool> onFinish) { ECAssetBundleHeader bh; using (FileStream fin = File.OpenRead(depFilePath)) { bh = new ECAssetBundleHeader(); bh.Load(fin); } AssetBundle bundle = AssetBundle.CreateFromFile(path); if (onFinish != null) onFinish(bundle, bh, true); }
static bool SaveSepFileToCache(Stream stream, string sepFilePath, string depFilePath, out ECAssetBundleHeader bh) { bh = new ECAssetBundleHeader(); bh.Load(stream); if ((bh.option & ECAssetBundleHeader.BundleOption.SepFile) != 0) { int headerLen = (int)stream.Position; String sepDir = Path.GetDirectoryName(sepFilePath); Directory.CreateDirectory(sepDir); stream.Seek(-headerLen, SeekOrigin.Current); WriteStreamToFile(depFilePath, stream, headerLen); //保存 assetbundle WriteStreamToFile(sepFilePath, stream, (int)(stream.Length - stream.Position)); return true; } return false; }
private static IEnumerator LoadAssetBundleCoroutine(Stream stream, Action<AssetBundle, ECAssetBundleHeader, bool> onFinish, String path) { ECAssetBundleHeader bh = new ECAssetBundleHeader(); bh.Load(stream); CreateBundleImmediate(stream, bh, onFinish, path); yield break; }
public static void LoadAssetBundleImmediate(String path, Action<AssetBundle, ECAssetBundleHeader, bool> onFinish) { Stream stream = LoadFile(path); if (stream == null) { if (onFinish != null) onFinish(null, null, false); return; } ECAssetBundleHeader bh = new ECAssetBundleHeader(); bh.Load(stream); CreateBundleImmediate(stream, bh, onFinish, path); }
public static void LoadAssetBundleFromSepFile(String path, string depFilePath, Action<AssetBundle, ECAssetBundleHeader, bool> onFinish) { ECAssetBundleHeader bh; try { using (FileStream fin = File.OpenRead(depFilePath)) { bh = new ECAssetBundleHeader(); bh.Load(fin); } } catch (IOException e) { Debug.LogWarning("LoadAssetBundleFromSepFile failed to read header from " + depFilePath + ": " + e); if (onFinish != null) onFinish(null, null, false); return; } catch (System.IO.IsolatedStorage.IsolatedStorageException e) { Debug.LogWarning("LoadAssetBundleFromSepFile failed to read header from " + depFilePath + ": " + e); if (onFinish != null) onFinish(null, null, false); return; } AssetBundle bundle = AssetBundle.CreateFromFile(path); if (onFinish != null) onFinish(bundle, bh, true); }