下面的代码是非Include in Build模式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
public class loadpre : MonoBehaviour {
public string prefabBundle = "preab_late";
public string saBundle = "atlasab_late";
IEnumerator Start ()
{
var loadOp = new WWW("file://" + Application.streamingAssetsPath + "/" + prefabBundle);
yield return loadOp;
var prepre = loadOp.assetBundle.LoadAsset<GameObject>("prop_parachute");
GameObject.Instantiate(prepre);
}
void OnEnable()
{
SpriteAtlasManager.atlasRequested += RequestLateBindingAtlas;
}
void OnDisable()
{
SpriteAtlasManager.atlasRequested -= RequestLateBindingAtlas;
}
void RequestLateBindingAtlas(string tag, System.Action<SpriteAtlas> action)
{
StartCoroutine(LoadFromAssetBundle(tag, action));
}
IEnumerator LoadFromAssetBundle(string tag, System.Action<SpriteAtlas> action)
{
var loadOp = new WWW("file://" + Application.streamingAssetsPath + "/" + saBundle);
yield return loadOp;
var sa = loadOp.assetBundle.LoadAsset<SpriteAtlas>(tag);
action(sa);
}
}
本文介绍了一个Unity游戏开发中使用AssetBundle加载预置物和精灵图集的非IncludeinBuild模式示例。通过IEnumerator协程Start()加载指定路径的资源包,并实例化游戏对象。OnEnable()和OnDisable()方法用于注册和注销SpriteAtlasManager的atlasRequested事件,以实现资源的按需加载。
1897

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



