Unity 从Resources中动态加载Sprite图片

 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开发)