private void _CheckStreamingAssetAsync(string path, IAssetDescription description, Action <bool> callback) { var fullPath = PathUtility.ComposeAppUrl(path); new WWWLoadTask(fullPath, 1f).Start().Continue(task => { if (null != task.Result) { var w = task.Result as WWW; callback(null != w.error || !description.Equals(w.bytes)); } else { callback(true); } return(null); }); }
private void _LoadSelfFromWWWAsync() { var fullPath = ""; switch (this.loadType) { case AssetPackLoadType.STREAMINGASSETS: fullPath = PathUtility.ComposeAppUrl(this.path); break; case AssetPackLoadType.PERSISTENTDATAPATH: fullPath = PathUtility.ComposeDataUrl(this.path); break; case AssetPackLoadType.REMOTE: fullPath = this.path; break; } Logger <IAssetManager> .L("Load asset pack through WWW: " + fullPath); new WWWLoadTask(fullPath).Start().Continue(task => { var w = task.Result as WWW; if (null == w.error) { this.origin = w; this.state = AssetPackState.LOADED; } else { this.state = AssetPackState.FAILED; } _OnAssetPackLoaded(); return(null); }); }
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); }); }