/// <summary> /// Resources 异步加载资源 (注意加载路径中不能带有扩展名否则加载失败) /// </summary> /// <param name="assetFullUri"></param> /// <param name="loadCallback"></param> /// <param name="procressCallback"></param> public static void ResourcesLoadAssetAsync(string assetFullUri, System.Action <ILoadAssetRecord> loadCallback, System.Action <string, float> procressCallback) { LoadResourcesAssetRecord resourcesAssetRecord = LoadResourcesAssetFromCache(assetFullUri); if (resourcesAssetRecord != null && resourcesAssetRecord.IsRecordEnable) { loadCallback?.Invoke(resourcesAssetRecord); return; } ResourceRequest request = Resources.LoadAsync(assetFullUri.GetPathWithOutExtension()); AsyncManager.StartAsyncOperation(request, () => { resourcesAssetRecord = LoadResourcesAssetRecord.GetLoadResourcesAssetRecord(assetFullUri, request.asset); RecordResourcesLoadAsset(assetFullUri, resourcesAssetRecord); loadCallback?.Invoke(resourcesAssetRecord); }, (procress) => { procressCallback?.Invoke(assetFullUri, procress); }); }
/// <summary> /// Resources 同步加载资源 (注意加载路径中不能带有扩展名否则加载失败) /// </summary> /// <param name="assetFullUri"></param> /// <returns></returns> public static ILoadAssetRecord ResourcesLoadAssetSync(string assetFullUri) { LoadResourcesAssetRecord resourcesAssetRecord = LoadResourcesAssetFromCache(assetFullUri); if (resourcesAssetRecord != null && resourcesAssetRecord.IsRecordEnable) { return(resourcesAssetRecord); } Object asset = Resources.Load <UnityEngine.Object>(assetFullUri.GetPathWithOutExtension()); if (asset == null) { #if UNITY_EDITOR Debug.LogInfor($"ResourcesLoadAssetSync Fail,assetFullUri={assetFullUri} not exit"); #endif return(null); } resourcesAssetRecord = LoadResourcesAssetRecord.GetLoadResourcesAssetRecord(assetFullUri, asset); RecordResourcesLoadAsset(assetFullUri, resourcesAssetRecord); return(resourcesAssetRecord); }