public static GetResourceFullPath ( string url, bool withFileProtocol, string &fullPath, bool isLog = true ) : GetResourceFullPathType | ||
url | string | |
withFileProtocol | bool | |
fullPath | string | |
isLog | bool | |
return | GetResourceFullPathType |
/// <summary> /// Convenient method to load file sync auto. /// </summary> /// <param name="url"></param> /// <returns></returns> public static byte[] LoadSync(string url) { string fullUrl; var getResPathType = KResourceModule.GetResourceFullPath(url, false, out fullUrl); if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid) { if (Debug.isDebugBuild) { Log.Error("[HotBytesLoader]Error Path: {0}", url); } return(null); } byte[] bytes; if (getResPathType == KResourceModule.GetResourceFullPathType.InApp) { if (Application.isEditor) // Editor mode : 读取Product配置目录 { var loadSyncPath = Path.Combine(KResourceModule.ProductPathWithoutFileProtocol, url); bytes = KResourceModule.ReadAllBytes(loadSyncPath); } else // product mode: read streamingAssetsPath { bytes = KResourceModule.LoadSyncFromStreamingAssets(url); } } else { bytes = KResourceModule.ReadAllBytes(fullUrl); } return(bytes); }
private IEnumerator CoLoad(string url) { var getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl); if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid) { if (Debug.isDebugBuild) { Log.Error("[HotBytesLoader]Error Path: {0}", url); } OnFinish(null); yield break; } if (_loaderMode == LoaderMode.Sync) { // 存在应用内的,StreamingAssets内的,同步读取;否则去PersitentDataPath if (getResPathType == KResourceModule.GetResourceFullPathType.InApp) { if (Application.isEditor) // Editor mode : 读取Product配置目录 { var loadSyncPath = Path.Combine(KResourceModule.ProductPathWithoutFileProtocol, url); Bytes = KResourceModule.ReadAllBytes(loadSyncPath); } else // product mode: read streamingAssetsPath { Bytes = KResourceModule.LoadSyncFromStreamingAssets(url); } } else { Bytes = KResourceModule.ReadAllBytes(_fullUrl); } } else { _wwwLoader = KWWWLoader.Load(_fullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress; yield return(null); } if (!_wwwLoader.IsSuccess) { //if (AssetBundlerLoaderErrorEvent != null) //{ // AssetBundlerLoaderErrorEvent(this); //} Log.Error("[HotBytesLoader]Error Load WWW: {0}", url); OnFinish(null); yield break; } Bytes = _wwwLoader.Www.bytes; } OnFinish(Bytes); }
private IEnumerator CoLoad(string url) { if (_loaderMode == LoaderMode.Sync) { Bytes = KResourceModule.LoadAssetsSync(url); } else { string _fullUrl; var getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl); if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid) { Log.Error("[HotBytesLoader]Error Path: {0}", url); OnFinish(null); yield break; } _wwwLoader = KWWWLoader.Load(_fullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress; yield return(null); } if (!_wwwLoader.IsSuccess) { //if (AssetBundlerLoaderErrorEvent != null) //{ // AssetBundlerLoaderErrorEvent(this); //} Log.Error("[HotBytesLoader]Error Load WWW: {0}", url); OnFinish(null); yield break; } #if UNITY_2018_1_OR_NEWER //TODO 换成WebRequst //Bytes = _wwwLoader.Www.downloadHandler.data; Bytes = _wwwLoader.Www.bytes; #else Bytes = _wwwLoader.Www.bytes; #endif } OnFinish(Bytes); }
private IEnumerator CoLoad(string url) { if (_loaderMode == LoaderMode.Sync) { Bytes = LoadSync(url); } else { var getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl); if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid) { if (Debug.isDebugBuild) { Log.Error("[HotBytesLoader]Error Path: {0}", url); } OnFinish(null); yield break; } _wwwLoader = KWWWLoader.Load(_fullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress; yield return(null); } if (!_wwwLoader.IsSuccess) { //if (AssetBundlerLoaderErrorEvent != null) //{ // AssetBundlerLoaderErrorEvent(this); //} Log.Error("[HotBytesLoader]Error Load WWW: {0}", url); OnFinish(null); yield break; } Bytes = _wwwLoader.Www.bytes; } OnFinish(Bytes); }
private IEnumerator LoadAssetBundle(string relativeUrl) { #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 Manifest中管理了依赖 var abPath = relativeUrl.ToLower(); var deps = _assetBundleManifest.GetAllDependencies(abPath); _depLoaders = new AssetBundleLoader[deps.Length]; for (var d = 0; d < deps.Length; d++) { var dep = deps[d]; _depLoaders[d] = AssetBundleLoader.Load(dep, null, _loaderMode); if (_depLoaders[d].dependFrom == string.Empty) { _depLoaders[d].dependFrom = relativeUrl; } } for (var l = 0; l < _depLoaders.Length; l++) { var loader = _depLoaders[l]; while (!loader.IsCompleted) { yield return(null); } } #endif #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 AssetBundle自动转小写 relativeUrl = relativeUrl.ToLower(); #endif if (AppConfig.IsLogAbLoadCost) { beginTime = Time.realtimeSinceStartup; } string _fullUrl; var pathType = KResourceModule.GetResourceFullPath(KResourceModule.BundlesPathRelative + relativeUrl, false, out _fullUrl); if (pathType == KResourceModule.GetResourceFullPathType.Invalid) { OnFinish(null); yield break; } if (Application.platform == RuntimePlatform.Android && pathType == KResourceModule.GetResourceFullPathType.InApp) { _fullUrl = "jar:file://" + _fullUrl; } AssetBundle assetBundle = null; if (_loaderMode == LoaderMode.Sync) { assetBundle = AssetBundle.LoadFromFile(_fullUrl); } else { var request = AssetBundle.LoadFromFileAsync(_fullUrl); while (!request.isDone) { if (IsReadyDisposed) // 中途释放 { OnFinish(null); yield break; } Progress = request.progress; yield return(null); } assetBundle = request.assetBundle; } if (assetBundle == null) { Log.Error("assetBundle is NULL: {0}", RelativeResourceUrl); } if (AppConfig.IsLogAbLoadCost) { Log.Info("[Finish] Load AssetBundle {0}, CostTime {1}s {2}", relativeUrl, Time.realtimeSinceStartup - beginTime, dependFrom); } if (AppConfig.IsSaveCostToFile && !relativeUrl.StartsWith("ui/")) { LogFileRecorder.WriteLoadAbLog(relativeUrl, Time.realtimeSinceStartup - beginTime); } OnFinish(assetBundle); }