AssetBundle是实现资源热更新的重要功能,但Unity为其提供的API却十分基(jian)础(lou)。像是自动加载依赖包、重复加载缓存、解决同步/异步加载冲突,等基础功能都必须由使用者自行实现。 因此,本篇博客将会介绍如何实现一个AssetBundle管理器以解决以上问题。 1 成员定义与初始化 作为典型的"Manager"类,我们显然要让其成为一个单例对象,并且由于后续异步加载会用到协程函数,因此还需要继承MonoBehaviour。所以,这里用到了我在Unity单例基类的实现方式中提到的Mono单例基类SingletonMono<>。 // Mono单例基类 public abstract class SingletonMono<T> : MonoBehaviour where T : MonoBehaviour { private static T _instance; public static T Instance { get { if (_instance == null) { // 在场景中查找是否已存在该类型的实例 _instance =...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with enum
Contact enum, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack