Unity Addressables 笔记

1. 环境配置

  • 安装 :Package Manager → 搜 Addressables → 安装

  • 初始化 :Window → Asset Management → Addressables → Groups → 点击 Create Addressables Settings

  • 标记资源 :选中 Prefab/图片/场景 → Inspector 顶部勾选 Addressable

2. 加载示例

方式一:AssetReference(推荐)

cpp 复制代码
using UnityEngine;
using UnityEngine.AddressableAssets;

public class LoadByReference : MonoBehaviour
{
    public AssetReference reference; // 拖拽 Addressable 资源

    async void Start()
    {
        var prefab = await reference.LoadAssetAsync<GameObject>().Task;
        Instantiate(prefab);
    }
    
    void OnDestroy() => reference.ReleaseAsset();
}

方式二:通过地址字符串

cpp 复制代码
using UnityEngine;
using UnityEngine.AddressableAssets;

public class LoadByAddress : MonoBehaviour
{
    public string address = "MyPrefab"; // 填资源的 Address

    async void Start()
    {
        var prefab = await Addressables.LoadAssetAsync<GameObject>(address).Task;
        Instantiate(prefab);
    }
}

释放 :Addressables.Release(handle)

相关推荐
寂寞的船18 小时前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
寂寞的船1 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
探求虚无3 天前
用 AI 在 Unity 里做一款 RTS:最难的不是生成代码,而是证明它真的能玩
人工智能·unity·游戏引擎
17岁的勇气4 天前
Unity Shader unity文档学习笔记(二十二):shader变体
笔记·学习·unity
寂寞的船5 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene
Martina_03215 天前
AI生成3D场景的霓虹灯一开就糊成光团?用6步检查Emissive、Bloom与曝光
人工智能·3d·ai·自然语言处理·游戏引擎·材质·贴图
寂寞的船7 天前
【Unity知识速递】第8期 IL2CPP 托管堆内存碎片与原生堆交互机制深度解析
unity·游戏引擎·交互
寂寞的船7 天前
【Unity知识速递】第5期 Unity 6.2 深度解析:AI Assistant 登场,World Space UI 与 Sentis 全面升级
人工智能·ui·unity
寂寞的船8 天前
【Unity知识速递】第4期 MCP for Unity:用 AI 自然语言控制编辑器
人工智能·unity·编辑器
淡海水8 天前
09-04-内存-Unity原生对象生命周期
unity·c#·游戏引擎·gc