private void _CollectUpgradeAssetAsync(byte loadType, string updateServerPath, IAssetDescription description, Action <Asset> callback) { if (STREAMINGASSETS == loadType || !File.Exists(PathUtility.ComposeDataPath(description.Path))) { _CheckStreamingAssetAsync(description.Path, description, result => { callback(result ? new Asset(description) { ServerPath = updateServerPath, File = description.Path, Size = description.Size, } : null); }); } else { _CheckPerisitentDataAssetAsync(description.Path, description, result => { callback(result ? new Asset(description) { ServerPath = updateServerPath, File = description.Path, Size = description.Size, } : null); }); } }
private void _LoadSelfFromBundleAsync() { var fullPath = ""; switch (this.loadType) { case AssetPackLoadType.STREAMINGASSETS: fullPath = PathUtility.ComposeAppPath(this.path); break; case AssetPackLoadType.PERSISTENTDATAPATH: fullPath = PathUtility.ComposeDataPath(this.path); if (!File.Exists(fullPath)) { fullPath = PathUtility.ComposeAppPath(this.path); this.loadType = AssetPackLoadType.STREAMINGASSETS; } break; } Logger <IAssetManager> .L("Load asset pack through assets bundle: " + fullPath); new AssetBundleLoadTask(fullPath).Start().Continue(task => { var request = task.Result as AssetBundleCreateRequest; this.origin = request.assetBundle; this.state = (null != this.origin ? AssetPackState.LOADED : AssetPackState.FAILED); _OnAssetPackLoaded(); return(null); }); }
private AssetPack _GetAssetPack(string path, bool checkDependency, AssetType assetType) { AssetPack pack = null; lock (this.packs) { var loadType = this.info._LoadType; var packInfo = _FindAssetPackInfo(path); if (null == packInfo) { var assetInfo = _FindAssetInfo(path); if (null != assetInfo) { path = assetInfo.PackPath; // Override path with pack path packInfo = _FindAssetPackInfo(path); if (null == packInfo) { Logger <IAssetManager> .E("!IMPOSSIBLE!"); } } else { packInfo = new AssetPackInfo { Type = AssetPackType.FLAT, }; if (File.Exists(PathUtility.ComposeDataPath(path))) // Check if it exists but not managed by AssetManager { loadType = AssetPackLoadType.PERSISTENTDATAPATH; } else if (AssetType.SCENE == assetType) // Unity scene type { loadType = AssetPackLoadType.INTERNALSCENE; } else { loadType = AssetPackLoadType.RESOURCES; if (AssetType.SPRITEATLAS == assetType) // Resources sprite atlas { packInfo.Type = AssetPackType.BUNDLE; } } this.info.Packs.Add(path, packInfo); } } if (!this.packs.TryGetValue(path, out pack)) { pack = new AssetPack(this, path, packInfo.Type, (path.StartsWith("http") ? AssetPackLoadType.REMOTE : loadType), checkDependency); _RetainAssetPack(pack); } } return(pack); }
private void _CheckPerisitentDataAssetAsync(string path, IAssetDescription description, Action <bool> callback) { var fullPath = PathUtility.ComposeDataPath(path); new FileReadTask(fullPath).Start().Continue(task => { var bytes = task.Result as byte[]; callback(!description.Equals(bytes)); return(null); }); }
private object _LoadSelfFromBundle() { var fullPath = ""; switch (this.loadType) { case AssetPackLoadType.STREAMINGASSETS: fullPath = PathUtility.ComposeAppPath(this.path); break; case AssetPackLoadType.PERSISTENTDATAPATH: fullPath = PathUtility.ComposeDataPath(this.path); if (!File.Exists(fullPath)) { fullPath = PathUtility.ComposeAppPath(this.path); this.loadType = AssetPackLoadType.STREAMINGASSETS; } break; } Logger <IAssetManager> .L("Load asset pack through assets bundle: " + fullPath); return(AssetBundle.LoadFromFile(fullPath)); }
public void UpdateAsync(Action callback) { new FileReadTask(PathUtility.ComposeDataPath(Id)) .Start() .Continue(task => { if (null != task.Result) { using (var stream = new MemoryStream(task.Result as byte[])) { this.info = AssetManagerInfo.Deserialize(stream); this.info._LoadType = AssetPackLoadType.PERSISTENTDATAPATH; stream.Close(); } } return(new WWWLoadTask(PathUtility.ComposeAppUrl(Id))); }) .Continue(task => { if (null != task.Result) { var w = task.Result as WWW; if (null == w.error) { using (var stream = new MemoryStream(w.bytes)) { var info = AssetManagerInfo.Deserialize(stream); info._LoadType = AssetPackLoadType.STREAMINGASSETS; var innerVersion = new Version(info.Version); var outerVersion = new Version(this.info.Version); if (innerVersion.Compare(outerVersion) > 0) { this.info = info; } } } } return(null); }) .Continue(task => { var reloadPacks = new List <AssetPack>(); foreach (var pair in this.packs) { var pack = pair.Value; if (AssetPackLoadType.RESOURCES != pack.LoadType && AssetPackLoadType.REMOTE != pack.LoadType) // DO NOT reload asset in Resources { pack._Reset(false); // Reset first reloadPacks.Add(pack); } } if (reloadPacks.Count > 0) { var count = reloadPacks.Count; for (var i = 0; i < reloadPacks.Count; ++i) { var pack = reloadPacks[i]; pack.LoadType = this.info._LoadType; // Sync load type after _Reset pack.LoadAsync((assetPack, _) => { if (0 == (--count) && null != callback) { callback(); } }); } } else if (null != callback) { callback(); } return(null); }); }
// IAssetListUpdater public void Check(string updateServerPath, string configureFile, IAssetConfigureParser parser, Action <AssetUpdateType, IAssetDownloader> callback) { this.updateServerPath = updateServerPath; this.configureFile = configureFile; this.callback = callback; if (!Directory.Exists(PathUtility.DataFolder)) { Directory.CreateDirectory(PathUtility.DataFolder); } byte loadType = PERSISTENTDATAPATH; new HttpDownloadTask(this.updateServerPath + configureFile + "?") // Add time out (5s) for request .Start() .Continue(task => { if (null != task.Result) // Check null first since IL2CPP will throw exception if converting null to any type { this.configureData = task.Result as byte[]; return(new AssetConfigureParseTask(parser, this.configureData)); } return(null); }) .Continue(task => { remoteConfigure = _CastToAssetConfigure(task.Result); var filePath = PathUtility.ComposeDataPath(configureFile); return(new FileReadTask(filePath)); }) .Continue(task => { return(null != task.Result ? new AssetConfigureParseTask(parser, task.Result as byte[]) : null); }) .Continue(task => { this.localConfigure = _CastToAssetConfigure(task.Result); var fileUrl = PathUtility.ComposeAppUrl(configureFile); return(new WWWLoadTask(fileUrl, 5.0f)); }) .Continue(task => { if (null != task.Result) // Check null first since IL2CPP will throw exception if converting null to any type { var w = task.Result as WWW; if (null == w.error) { return(new AssetConfigureParseTask(parser, w.bytes)); } } return(null); }) .Continue(task => { var assetConfigure = _CastToAssetConfigure(task.Result); if (null != assetConfigure) { if (null == this.localConfigure) { this.localConfigure = assetConfigure; loadType = STREAMINGASSETS; } else { var innerVersion = new GameBox.Framework.Version(assetConfigure.Version); var outerVersion = new GameBox.Framework.Version(this.localConfigure.Version); if (innerVersion.Compare(outerVersion) > 0) { this.localConfigure = assetConfigure; loadType = STREAMINGASSETS; } } } if (null == this.remoteConfigure) { _NotifyCallback(this.updateType = AssetUpdateType.INVALID, null); } else if (null == this.localConfigure) { _NotifyCallback(this.updateType = AssetUpdateType.HOTUPDATE, _SetupHotUpdateDownloaderWithoutCheck(this.updateServerPath, remoteConfigure)); } else { var localVersion = new GameBox.Framework.Version(this.localConfigure.Version); var remoteVersion = new GameBox.Framework.Version(this.remoteConfigure.Version); if (remoteVersion.Major != localVersion.Major) { // Major version upgrade indicates full app upgrade _NotifyCallback(this.updateType = AssetUpdateType.FULLUPDATE, null); } else if (0 != remoteVersion.Compare(localVersion)) { // Major version is same but minor version is upgrade indicates hot assets upgrade _SetupHotUpdateDownloaderAsync(this.updateServerPath, loadType, this.remoteConfigure, downloader => { _NotifyCallback(this.updateType = (null != downloader ? AssetUpdateType.HOTUPDATE : AssetUpdateType.UPDATED), downloader); }); } else { _NotifyCallback(this.updateType = AssetUpdateType.UPDATED, null); } } return(null); }); }