private static void ParseResLoadParam(ResLoadParam param, ref AssetLocation location, ref bool async) { if (param != null) { async = param.async; location = param.location; } }
/// <summary> /// 通过资源信息创建对象 /// 强制异步 /// </summary> public static void GetObjAsyncByResInfo(this IResLoader resLoader, Action <string, string, GameObject> callback, ResLoadParam defaultParam = null) { string abPath = string.Empty; string assetName = string.Empty; if (resLoader != null) { ParseAsyncResInfo(resLoader, ref abPath, ref assetName, defaultParam); resLoader.AssetBundleLoader?.GetAssetAsync(abPath, assetName, (GameObject assetObj) => callback?.Invoke(abPath, assetName, assetObj)); } }
/// <summary> /// 解析基于异步的资源信息 /// </summary> private static void ParseAsyncResInfo(IResLoader resLoader, ref string abPath, ref string assetName, ResLoadParam defaultParam = null) { bool async = true; AssetLocation location = AssetLocation.StreamingAssets; ParseResLoadParam(defaultParam, ref location, ref async); ParseResInfoAttribute(resLoader, ref abPath, ref assetName, ref async, ref location); GenerateDefaultResInfo(resLoader, ref abPath, ref assetName); GenerateAbPath(location, ref abPath, true); }
/// <summary> /// 通过资源信息创建对象 /// </summary> public static void GetObjByResInfo(this IResLoader resLoader, Action <string, string, GameObject> callback, ResLoadParam defaultParam = null) { GameObject obj = null; bool async = false; string abPath = string.Empty; string assetName = string.Empty; if (resLoader != null) { ParseResInfo(resLoader, ref abPath, ref assetName, ref async, defaultParam); if (async) { resLoader.AssetBundleLoader?.GetAssetAsync(abPath, assetName, (GameObject assetObj) => callback?.Invoke(abPath, assetName, assetObj)); } else { obj = resLoader.AssetBundleLoader?.GetAsset <GameObject>(abPath, assetName); } } if (!async) { callback?.Invoke(abPath, assetName, obj); } }