//通过AssetBundle的方式加载 private IEnumerator _AsyncLoadAsset(AssetEntity _entity) { #if UNITY_EDITOR && !TEST_AB string AssetName = PathUtil.I.GetStreamingAssesPath() + GetRelativePath(_entity.assetName, _entity.assetType); Object _object = UnityEditor.AssetDatabase.LoadAssetAtPath <Object>(AssetName); _entity.SetAsset(_object); m_kLoaded.Enqueue(_entity); #else AssetBundle assetBundle = null; AssetBundleCreateRequest _assetBundleCreateRequest; string _path = GetRelativePath(_entity.assetName, _entity.assetType).ToLower(); string[] dependences = bundleManifest.GetAllDependencies(_path); if (dependences != null && dependences.Length > 0) { //Debug.LogFormat("assets", "{0}依赖文件个数:{1}", _entity.assetName, dependences.Length); string dependenceAssetName = string.Empty; for (int i = 0; i < dependences.Length; ++i) { dependenceAssetName = PathUtil.I.GetStreamingAssesPath() + dependences[i]; yield return(_AsyncLoadDependencieAsset(dependenceAssetName)); } } string AssetName = PathUtil.I.GetStreamingAssesPath() + _path; _assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(AssetName); yield return(_assetBundleCreateRequest); assetBundle = _assetBundleCreateRequest.assetBundle; AssetBundleRequest bundleRequest = assetBundle.LoadAllAssetsAsync(); yield return(bundleRequest); _entity.SetAsset(bundleRequest.asset); m_kLoaded.Enqueue(_entity); assetBundle.Unload(false); #endif yield return(null); }
static int SetAsset(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); AssetEntity obj = (AssetEntity)ToLua.CheckObject <AssetEntity>(L, 1); UnityEngine.Object arg0 = (UnityEngine.Object)ToLua.CheckObject <UnityEngine.Object>(L, 2); obj.SetAsset(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }