protected override void Init(string url, params object[] args) { base.Init(url); _loaderMode = (KAssetBundleLoaderMode)args[0]; // 如果是默认模式,则要判断ResourceModule.InAppPathType的默认为依据 if (_loaderMode == KAssetBundleLoaderMode.Default) { _inAppPathType = KResourceModule.DefaultInAppPathType; switch (_inAppPathType) { case KResourceInAppPathType.StreamingAssetsPath: _loaderMode = KAssetBundleLoaderMode.StreamingAssetsWww; break; case KResourceInAppPathType.ResourcesAssetsPath: _loaderMode = KAssetBundleLoaderMode.ResourcesLoad; break; case KResourceInAppPathType.PersistentAssetsPath: _loaderMode = KAssetBundleLoaderMode.PersitentDataPathSync; break; default: Logger.LogError("Error DefaultInAppPathType: {0}", _inAppPathType); break; } } // 不同的AssetBundle加载方式,对应不同的路径 switch (_loaderMode) { case KAssetBundleLoaderMode.ResourcesLoad: case KAssetBundleLoaderMode.ResourcesLoadAsync: _inAppPathType = KResourceInAppPathType.ResourcesAssetsPath; break; case KAssetBundleLoaderMode.StreamingAssetsWww: _inAppPathType = KResourceInAppPathType.StreamingAssetsPath; break; case KAssetBundleLoaderMode.PersitentDataPathSync: _inAppPathType = KResourceInAppPathType.PersistentAssetsPath; break; default: Logger.LogError("[KAssetBundleLoader:Init]Unknow loader mode: {0}", _loaderMode); break; } if (NewAssetBundleLoaderEvent != null) { NewAssetBundleLoaderEvent(url); } RelativeResourceUrl = url; KResourceModule.LogRequest("AssetBundle", RelativeResourceUrl); KResourceModule.Instance.StartCoroutine(LoadAssetBundle(url)); }
protected override void Init(string url, params object[] args) { base.Init(url, args); _inAppPathType = (KResourceInAppPathType)args[0]; _loaderMode = (KAssetBundleLoaderMode)args[1]; KResourceModule.Instance.StartCoroutine(CoLoad(url, _inAppPathType, _loaderMode)); }
public static KStaticAssetLoader LoadUIAtlas(string resourcePath, Action<UIAtlas> callback, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { //System.Func<bool> doCheckCache = () => //{ // UIAtlas cacheAtlas; // 这里有个问题的,如果正在加载中,还没放进Cache列表...还是会多次执行, 但不要紧, CWWWLoader已经避免了重复加载, 这里确保快速回调,不延迟1帧 // if (CachedUIAtlas.TryGetValue(resourcePath, out cacheAtlas)) // { // if (callback != null) // callback(cacheAtlas); // return true; // } // return false; //}; //if (doCheckCache()) // return; bool exist = KStaticAssetLoader.GetRefCount<KStaticAssetLoader>(resourcePath) > 0; return KStaticAssetLoader.Load(resourcePath, (isOk, obj) => { //if (doCheckCache()) // return; GameObject gameObj = obj as GameObject; // Load UIAtlas Object Prefab gameObj.transform.parent = DependenciesContainer.transform; gameObj.name = resourcePath; UIAtlas atlas = gameObj.GetComponent<UIAtlas>(); Debuger.Assert(atlas); if (!exist) { // Wait Load Material var colDep = gameObj.GetComponent<KAssetDep>(); Debuger.Assert(colDep && colDep.GetType() == typeof (KUIAtlasDep)); // CResourceDependencyType.UI_ATLAS); // 依赖材质Material, 加载后是Material colDep.AddFinishCallback((assetDep, _obj) => { // 塞Material进去UIAtlas if (atlas.spriteMaterial == null) // 不为空意味已经加载过了! { Material _mat = _obj as Material; atlas.spriteMaterial = _mat; // 注意,这一行性能消耗非常的大! } else Log.LogWarning("Atlas依赖的材质多次加载了(未缓存)!!!!!!!!!!!!!"); if (callback != null) callback(atlas); }); } else { if (callback != null) callback(atlas); } }, loaderMode); }
public static KStaticAssetLoader Load(string url, KAssetFileLoader.CAssetFileBridgeDelegate callback = null, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { CLoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as UnityEngine.Object); } return AutoNew<KStaticAssetLoader>(url, newCallback, false, loaderMode); }
public static KAssetFileLoader Load(string path, CAssetFileBridgeDelegate assetFileLoadedCallback = null, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { CLoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as UnityEngine.Object); } return AutoNew<KAssetFileLoader>(path, realcallback, false, loaderMode); }
public static KAssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { CLoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew<KAssetBundleLoader>(url, newCallback, false, loaderMode); return newLoader; }
public static KAssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { CLoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <KAssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
private IEnumerator CoLoad(string url, KResourceInAppPathType type, KAssetBundleLoaderMode loaderMode) { if (KResourceModule.GetResourceFullPath(url, out FullUrl, _inAppPathType)) { } else { if (Debug.isDebugBuild) { Logger.LogError("[KBytesLoader]Error Path: {0}", url); } OnFinish(null); } if (_inAppPathType == KResourceInAppPathType.PersistentAssetsPath) { Progress = .5f; Bytes = File.ReadAllBytes(FullUrl); } else if (_inAppPathType == KResourceInAppPathType.StreamingAssetsPath) { _wwwLoader = KWWWLoader.Load(FullUrl); while (!_wwwLoader.IsCompleted) { Progress = _wwwLoader.Progress / 2f; // 最多50%, 要算上Parser的嘛 yield return(null); } if (!_wwwLoader.IsSuccess) { //if (AssetBundlerLoaderErrorEvent != null) //{ // AssetBundlerLoaderErrorEvent(this); //} Logger.LogError("[KBytesLoader]Error Load WWW: {0}", url); OnFinish(null); yield break; } Bytes = _wwwLoader.Www.bytes; } else if (_inAppPathType == KResourceInAppPathType.ResourcesAssetsPath) // 使用Resources文件夹模式 { var pathExt = Path.GetExtension(FullUrl); // Resources.Load无需扩展名 var pathWithoutExt = FullUrl.Substring(0, FullUrl.Length - pathExt.Length); if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoad) { var textAsset = Resources.Load <TextAsset>(pathWithoutExt); if (textAsset == null) { Logger.LogError("[KBytesLoader]Cannot Resources.Load from : {0}", pathWithoutExt); OnFinish(null); yield break; } Bytes = textAsset.bytes; Resources.UnloadAsset(textAsset); } else if (_loaderMode == KAssetBundleLoaderMode.ResourcesLoadAsync) { var loadReq = Resources.LoadAsync <TextAsset>(pathWithoutExt); while (!loadReq.isDone) { Progress = loadReq.progress / 2f; // 最多50%, 要算上Parser的嘛 } var loadAsset = loadReq.asset; var loadTextAsset = loadAsset as TextAsset; if (loadTextAsset == null) { Logger.LogError("[KBytesLoader]Error Resources.LoadAsync: {0}", url); OnFinish(null); yield break; } Bytes = loadTextAsset.bytes; Resources.UnloadAsset(loadTextAsset); } else { Logger.LogError("[KBytesLoader]Unvalid LoaderMode on Resources Load Mode: {0}", _loaderMode); OnFinish(null); yield break; } } else { Logger.LogError("[KBytesLoader]Error InAppPathType: {0}", KResourceModule.DefaultInAppPathType); OnFinish(null); yield break; } OnFinish(Bytes); }
public static KBytesLoader Load(string path, KResourceInAppPathType inAppPathType, KAssetBundleLoaderMode loaderMode) { var newLoader = AutoNew <KBytesLoader>(path, null, false, inAppPathType, loaderMode); return(newLoader); }
public static KStaticAssetLoader LoadUIAtlas(string resourcePath, Action <UIAtlas> callback, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { //System.Func<bool> doCheckCache = () => //{ // UIAtlas cacheAtlas; // 这里有个问题的,如果正在加载中,还没放进Cache列表...还是会多次执行, 但不要紧, CWWWLoader已经避免了重复加载, 这里确保快速回调,不延迟1帧 // if (CachedUIAtlas.TryGetValue(resourcePath, out cacheAtlas)) // { // if (callback != null) // callback(cacheAtlas); // return true; // } // return false; //}; //if (doCheckCache()) // return; bool exist = KStaticAssetLoader.GetRefCount <KStaticAssetLoader>(resourcePath) > 0; return(KStaticAssetLoader.Load(resourcePath, (isOk, obj) => { //if (doCheckCache()) // return; GameObject gameObj = obj as GameObject; // Load UIAtlas Object Prefab gameObj.transform.parent = DependenciesContainer.transform; gameObj.name = resourcePath; UIAtlas atlas = gameObj.GetComponent <UIAtlas>(); Logger.Assert(atlas); if (!exist) { // Wait Load Material var colDep = gameObj.GetComponent <KAssetDep>(); Logger.Assert(colDep && colDep.GetType() == typeof(KUIAtlasDep)); // CResourceDependencyType.UI_ATLAS); // 依赖材质Material, 加载后是Material colDep.AddFinishCallback((assetDep, _obj) => { // 塞Material进去UIAtlas if (atlas.spriteMaterial == null) // 不为空意味已经加载过了! { Material _mat = _obj as Material; atlas.spriteMaterial = _mat; // 注意,这一行性能消耗非常的大! } else { Logger.LogWarning("Atlas依赖的材质多次加载了(未缓存)!!!!!!!!!!!!!"); } if (callback != null) { callback(atlas); } }); } else { if (callback != null) { callback(atlas); } } }, loaderMode)); }
private IEnumerator _Init(string path, string assetName, KAssetBundleLoaderMode loaderMode) { IsLoadAssetBundle = KEngine.AppEngine.GetConfig("IsLoadAssetBundle").ToInt32() != 0; AssetInBundleName = assetName; UnityEngine.Object getAsset = null; if (!IsLoadAssetBundle) { string extension = System.IO.Path.GetExtension(path); path = path.Substring(0, path.Length - extension.Length); // remove extensions getAsset = Resources.Load<UnityEngine.Object>(path); if (getAsset == null) { Logger.LogError("Asset is NULL(from Resources Folder): {0}", path); } OnFinish(getAsset); } else { _bundleLoader = KAssetBundleLoader.Load(path, null, loaderMode); while (!_bundleLoader.IsCompleted) { if (IsReadyDisposed) // 中途释放 { _bundleLoader.Release(); OnFinish(null); yield break; } yield return null; } if (!_bundleLoader.IsSuccess) { Logger.LogError("[KAssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path); _bundleLoader.Release(); OnFinish(null); yield break; } var assetBundle = _bundleLoader.Bundle; System.DateTime beginTime = System.DateTime.Now; if (AssetInBundleName == null) { // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化 //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset //while (!request.isDone) //{ // yield return null; //} try { Logger.Assert(getAsset = assetBundle.mainAsset); } catch { Logger.LogError("[OnAssetBundleLoaded:mainAsset]{0}", path); } } else { // TODO: 未测试过这几行!~~ AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof (Object)); while (!request.isDone) { yield return null; } getAsset = request.asset; } KResourceModule.LogLoadTime("AssetFileBridge", path, beginTime); if (getAsset == null) { Logger.LogError("Asset is NULL: {0}", path); } _bundleLoader.Release(); // 释放Bundle(WebStream) } if (Application.isEditor) { if (getAsset != null) KResoourceLoadedAssetDebugger.Create(getAsset.GetType().Name, Url, getAsset as UnityEngine.Object); } if (getAsset != null) { // 更名~ 注明来源asset bundle 带有类型 getAsset.name = string.Format("{0}~{1}", getAsset, Url); } OnFinish(getAsset); }
public static KStaticAssetLoader Load(string url, KAssetFileLoader.CAssetFileBridgeDelegate callback = null, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { CLoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as UnityEngine.Object); } return(AutoNew <KStaticAssetLoader>(url, newCallback, false, loaderMode)); }
protected override void Init(string url, params object[] args) { base.Init(url); _loaderMode = (KAssetBundleLoaderMode) args[0]; // 如果是默认模式,则要判断ResourceModule.InAppPathType的默认为依据 if (_loaderMode == KAssetBundleLoaderMode.Default) { _inAppPathType = KResourceModule.DefaultInAppPathType; switch (_inAppPathType) { case KResourceInAppPathType.StreamingAssetsPath: _loaderMode = KAssetBundleLoaderMode.StreamingAssetsWww; break; case KResourceInAppPathType.ResourcesAssetsPath: _loaderMode = KAssetBundleLoaderMode.ResourcesLoad; break; default: Logger.LogError("Error DefaultInAppPathType: {0}", _inAppPathType); break; } } // 不同的AssetBundle加载方式,对应不同的路径 switch (_loaderMode) { case KAssetBundleLoaderMode.ResourcesLoad: case KAssetBundleLoaderMode.ResourcesLoadAsync: _inAppPathType = KResourceInAppPathType.ResourcesAssetsPath; break; case KAssetBundleLoaderMode.StreamingAssetsWww: _inAppPathType = KResourceInAppPathType.StreamingAssetsPath; break; default: Logger.LogError("[KAssetBundleLoader:Init]Unknow loader mode: {0}", _loaderMode); break; } if (NewAssetBundleLoaderEvent != null) NewAssetBundleLoaderEvent(url); RelativeResourceUrl = url; if (KResourceModule.GetResourceFullPath(url, out FullUrl, _inAppPathType)) { KResourceModule.LogRequest("AssetBundle", FullUrl); KResourceModule.Instance.StartCoroutine(LoadAssetBundle(url)); } else { if (Debug.isDebugBuild) Logger.LogError("[KAssetBundleLoader]Error Path: {0}", url); OnFinish(null); } }
private IEnumerator _Init(string path, string assetName, KAssetBundleLoaderMode loaderMode) { IsLoadAssetBundle = KEngine.AppEngine.GetConfig("IsLoadAssetBundle").ToInt32() != 0; AssetInBundleName = assetName; UnityEngine.Object getAsset = null; if (!IsLoadAssetBundle) { string extension = System.IO.Path.GetExtension(path); path = path.Substring(0, path.Length - extension.Length); // remove extensions getAsset = Resources.Load <UnityEngine.Object>(path); if (getAsset == null) { Logger.LogError("Asset is NULL(from Resources Folder): {0}", path); } OnFinish(getAsset); } else { _bundleLoader = KAssetBundleLoader.Load(path, null, loaderMode); while (!_bundleLoader.IsCompleted) { if (IsReadyDisposed) // 中途释放 { _bundleLoader.Release(); OnFinish(null); yield break; } yield return(null); } if (!_bundleLoader.IsSuccess) { Logger.LogError("[KAssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path); _bundleLoader.Release(); OnFinish(null); yield break; } var assetBundle = _bundleLoader.Bundle; System.DateTime beginTime = System.DateTime.Now; if (AssetInBundleName == null) { // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化 //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset //while (!request.isDone) //{ // yield return null; //} try { Logger.Assert(getAsset = assetBundle.mainAsset); } catch { Logger.LogError("[OnAssetBundleLoaded:mainAsset]{0}", path); } } else { // TODO: 未测试过这几行!~~ AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object)); while (!request.isDone) { yield return(null); } getAsset = request.asset; } KResourceModule.LogLoadTime("AssetFileBridge", path, beginTime); if (getAsset == null) { Logger.LogError("Asset is NULL: {0}", path); } _bundleLoader.Release(); // 释放Bundle(WebStream) } if (Application.isEditor) { if (getAsset != null) { KResoourceLoadedAssetDebugger.Create(getAsset.GetType().Name, Url, getAsset as UnityEngine.Object); } } if (getAsset != null) { // 更名~ 注明来源asset bundle 带有类型 getAsset.name = string.Format("{0}~{1}", getAsset, Url); } OnFinish(getAsset); }
public static KAssetFileLoader Load(string path, CAssetFileBridgeDelegate assetFileLoadedCallback = null, KAssetBundleLoaderMode loaderMode = KAssetBundleLoaderMode.Default) { CLoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as UnityEngine.Object); } return(AutoNew <KAssetFileLoader>(path, realcallback, false, loaderMode)); }
protected override void Init(string url, params object[] args) { base.Init(url); _loaderMode = (KAssetBundleLoaderMode)args[0]; // 如果是默认模式,则要判断ResourceModule.InAppPathType的默认为依据 if (_loaderMode == KAssetBundleLoaderMode.Default) { _inAppPathType = KResourceModule.DefaultInAppPathType; switch (_inAppPathType) { case KResourceInAppPathType.StreamingAssetsPath: _loaderMode = KAssetBundleLoaderMode.StreamingAssetsWww; break; case KResourceInAppPathType.ResourcesAssetsPath: _loaderMode = KAssetBundleLoaderMode.ResourcesLoad; break; default: Logger.LogError("Error DefaultInAppPathType: {0}", _inAppPathType); break; } } // 不同的AssetBundle加载方式,对应不同的路径 switch (_loaderMode) { case KAssetBundleLoaderMode.ResourcesLoad: case KAssetBundleLoaderMode.ResourcesLoadAsync: _inAppPathType = KResourceInAppPathType.ResourcesAssetsPath; break; case KAssetBundleLoaderMode.StreamingAssetsWww: _inAppPathType = KResourceInAppPathType.StreamingAssetsPath; break; default: Logger.LogError("[KAssetBundleLoader:Init]Unknow loader mode: {0}", _loaderMode); break; } if (NewAssetBundleLoaderEvent != null) { NewAssetBundleLoaderEvent(url); } RelativeResourceUrl = url; if (KResourceModule.GetResourceFullPath(url, out FullUrl, _inAppPathType)) { KResourceModule.LogRequest("AssetBundle", FullUrl); KResourceModule.Instance.StartCoroutine(LoadAssetBundle(url)); } else { if (Debug.isDebugBuild) { Logger.LogError("[KAssetBundleLoader]Error Path: {0}", url); } OnFinish(null); } }