internal void GetAsset(string name, Action <string, UnityEngine.Object> callback, LoadPriority priority = LoadPriority.Default) { if (name == null || name == string.Empty) { return; } if (HasLoaded(name)) { if (callback != null) { GetAssetInCache(name, callback, priority); } return; } #if UNITY_EDITOR UnityEngine.Object obj = LoadFromPrefab(name, typeof(UnityEngine.Object)); if (obj != null) { SetAsset(name, obj).Reference = 1; UnityEngine.Object ins = AssetInfo.IsNeedInstance(obj, name) ? GameObject.Instantiate(obj) : obj; if (callback != null) { callback(name, ins); } return; } #endif string bundleName = ResourceMgr.GetBundleName(name); if (bundleName == string.Empty) { DebugUtil.LogError("can not find asset: " + name); return; } cacheMgr.AddCallbackToDic(name, callback); if (!cacheMgr.HasLoadingInfo(bundleName)) { Resource res = this.GetDownloadResource(bundleName); if (res == null) { res = this.CreateResource(bundleName, priority); res.LoadRes(); } if (res.InvalidBundle) { res.InvalidBundle = false; } //逻辑加载时,提高优先级// if (res.Loader.Priority < priority) { this.ResourceMgr.GOELoaderMgr.SetLoaderPriority(res.Loader, priority); } } else { cacheMgr.CheckAssetLoading(bundleName, name, priority); } }
internal void GetAsset(string name, Action <string, UnityEngine.Object> callback, LoadPriority priority = LoadPriority.Default) { if (string.IsNullOrEmpty(name)) { return; } if (HasLoaded(name)) { if (callback != null) { GetAssetInCache(name, callback, priority); } return; } /* #if UNITY_EDITOR * UnityEngine.Object obj = LoadFromPrefab(name, typeof(UnityEngine.Object)); * if (obj != null) * { * SetAsset(name, obj).Reference = 1;z * UnityEngine.Object ins = AssetInfo.IsNeedInstance(obj, name) ? GameObject.Instantiate(obj) : obj; * if (callback != null) * callback(name, ins); * return; * } #endif*/ string bundleName = ResourceMgr.GetBundleName(name); if (bundleName == string.Empty) { DebugUtil.LogError("can not find asset: " + name); callback?.Invoke(name, null); //update: guangze song: 资源没找到时,回调正常调用,防止有的资源(LazyImageLoader)状态还在加载中 return; } cacheMgr.AddCallbackToDic(name, callback); BundleInfoResource cachedBundleInfo = cacheMgr.Cache[bundleName]; if (cachedBundleInfo != null) { cacheMgr.DoEnqueuePending(bundleName, LoadPriority.Default, cachedBundleInfo.AssetBundle); } else { if (!cacheMgr.HasLoadingInfo(bundleName)) { Resource res = this.GetDownloadResource(bundleName); if (res == null) { res = this.CreateResource(bundleName, priority); res.LoadRes(); } if (res.InvalidBundle) { res.InvalidBundle = false; } //逻辑加载时,提高优先级// if (res.Loader.Priority < priority) { this.ResourceMgr.GOELoaderMgr.SetLoaderPriority(res.Loader, priority); } } else { cacheMgr.CheckAssetLoading(bundleName, name, priority); } } }