//=====================================================
// - 文件名:AssetBundleManager
// - 作 者:刘佳
// - 时 间:
/*
*
*/
//======================================================
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class AssetBundleManager
{
//加载路径 多个客户端需要代码设置
public static string path = Application.streamingAssetsPath + "/assetbundle";
private AssetBundleManager()
{
bundleDict = new Dictionary<string, AssetBundle>();
}
private static AssetBundleManager instance;
static AssetBundle abMain;
static AssetBundleManifest abMainfest;
public static AssetBundleManager Instance
{
get
{
if (instance == null)instance = new AssetBundleManager();
return instance;
}
}
//初始化主包 以便后面加载依赖
public void InitMainAB(string assetBundleName)
{
//1.加载主包
abMain = AssetBundle.LoadFromFile(path + "/" + assetBundleName);
// 2.加载主包中的固定文件
// (固定写法,死死记住即可)
abMainfest = abMain.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
}
//加载ab资源
public T LoadAsset<T>(string key, string assetName) where T : UnityEngine.Object
{
#if UNITY_EDITOR
if (UnityEditor.EditorPrefs.GetBool("Editor"))
{
string[] paths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(key, assetName);
if (paths.Length == 0)
Unity AssetBundle加载依赖包
最新推荐文章于 2025-10-18 15:01:29 发布
文章介绍了如何在Unity中创建一个AssetBundleManager类来管理AssetBundle,包括加载主包、加载依赖、异步加载资源、卸载资源等操作。同时,示例展示了如何使用这个管理器加载游戏对象。

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



