public Sprite LoadSourceSprite(string relativePath)
{
//Debug.Log("relativePath=" + relativePath);
//把资源加载到内存中
Object Preb = Resources.Load(relativePath, typeof(Sprite));
Sprite tmpsprite = null;
try
{
tmpsprite = Instantiate(Preb) as Sprite;
}
catch ( System.Exception ex )
{
}
//用加载得到的资源对象,实例化游戏对象,实现游戏物体的动态加载
return tmpsprite;
//return Resources.Load(relativePath, typeof(Sprite)) as Sprite;
}
Unity 从Resources中动态加载Sprite图片
最新推荐文章于 2026-05-17 21:41:21 发布
本文介绍了一个Unity中资源动态加载的方法,通过使用Resources.Load方法结合Instantiate函数,实现了将指定路径下的Sprite资源加载到内存并实例化的过程。此方法适用于游戏开发中需要动态加载资源的场景。
3040

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



