![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiAnYldHL0FWby9mZvwFN4ETMfdHLkVGepZ2XtxSZ6l2clJ3LcV2Zh1Wa9M3clN2byBXLzN3btgHL9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsQTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cGcq5iM0ITM0UzM4QDNjFGNwIjNzYzX4IDO0MTMyAzLcFTMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.jpg)
01.生成AB包
02.使用资源文件
//加载AB包
AssetBundle asset= AssetBundle.LoadFromFile(Application.streamingAssetsPath+ "/model");
//加载资源
Instantiate(asset.LoadAsset<GameObject>("Cube"));
public Image image;
IEnumerator Load(string abName,string iconName)
{
AssetBundleCreateRequest request=AssetBundle.LoadFromFileAsync(Application.streamingAssetsPath + "/" + abName);
yield return request;
AssetBundleRequest sprite=request.assetBundle.LoadAssetAsync<Sprite>(iconName);
yield return sprite;
image.sprite = sprite.asset as Sprite;
}
03.资源依赖
AssetBundle asset= AssetBundle.LoadFromFile(Application.streamingAssetsPath+ "/model");
AssetBundle assetMain=AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/PC");
AssetBundleManifest abMainfest=assetMain.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] str=abMainfest.GetAllDependencies("model");
for (int i = 0; i < str.Length; i++)
{
AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + str[i]);
}