IEnumerator OnLoadAssetAsync(string filename, string assetBundleName, string assetName, System.Type type, Action <string, object, object[]> callback, params object[] callbackArgs) { AssetBundleLoadAssetOperation operation = manifestAssetBundleManager.LoadAssetAsync(assetBundleName, assetName, type); yield return(operation); UnityEngine.Object obj = null; if (AssetManagerSetting.IsCacheAssetBundleAsset) { obj = operation.GetAsset <UnityEngine.Object>(); if (obj == null) { Debug.LogErrorFormat("AssetManager_AssetBundle OnLoadAssetAsync obj=null, operation={0}", operation); } CreateLoadedAssetBundleCache(assetBundleName, assetName, type, obj); } if (callback != null) { if (obj == null) { obj = operation.GetAsset <UnityEngine.Object>(); } if (obj == null) { Debug.LogErrorFormat("AssetManager_AssetBundle OnLoadAssetAsync obj=null, operation={0}", operation); } callback(filename, obj, callbackArgs); } }
/** 加载资源 */ public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { LogFormat(LogType.Info, "LoadAssetAsync assetBundleName={0}, assetName={1}, type={2}", assetBundleName, assetName, type); AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (AssetManagerSetting.EditorSimulateAssetBundle) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogErrorFormat("LoadAssetAsync用AssetDatabase模拟加载没有找到该文件 assetBundleName={0}, assetName={1}", assetBundleName, assetName); return(null); } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadAssetAtPath(assetPaths[0], type); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { assetBundleName = RemapVariantName(assetBundleName); LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperationFull(this, assetBundleName, assetName, type); m_InProgressOperations.Add(operation); } return(operation); }
public AssetBundleLoadAssetOperation LoadOperation(string filename, Type type) { AssetBundleLoadAssetOperation operation = null; string filenameLower = filename.ToLower(); if (AssetOperationDict.ContainsKey(filenameLower)) { operation = AssetOperationDict[filenameLower]; operation.referencedCount++; AssetInfo fileInfo; if (assetInfoDict.TryGetValue(filenameLower, out fileInfo)) { AddToModule(fileInfo); } return(operation); } if (AssetManagerSetting.IsConfigFile(filename)) { operation = new AssetBundleLoadAssetOperationSimulation(LoadConfig(filename)); } else { AssetInfo fileInfo; if (!assetInfoDict.TryGetValue(filenameLower, out fileInfo)) { operation = new AssetBundleLoadAssetOperationSimulation(Resources.Load(filename, type)); } else { AddToModule(fileInfo); if (fileInfo.objType != null && (type == null || type == tmpObjType)) { type = fileInfo.objType; } if (fileInfo.loadType == AssetLoadType.AssetBundle) { #if UNITY_EDITOR if (AssetManagerSetting.EditorSimulateAssetBundle) { UnityEngine.Object target = UnityEditor.AssetDatabase.LoadAssetAtPath(fileInfo.path, type); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { operation = manifestAssetBundleManager.LoadAssetAsync(fileInfo.assetBundleName, fileInfo.assetName, type); } } else { operation = new AssetBundleLoadAssetOperationSimulation(Resources.Load(fileInfo.path, type)); } } } operation.referencedCount++; operation.key = filenameLower; AssetOperationDict.Add(filenameLower, operation); AssetOperationList.Add(operation); return(operation); }