/// <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); }