我如何获取和渲染 sprite 形式的 dataPath?
how i can get and render sprite form dataPath?
Sprite SpriteModding(字符串路径)
{
byte[] bytes = File.ReadAllBytes(Application.dataPath + "/Resources/fgsoftwarestudio.png");
Texture2D texture = new Texture2D(512, 512, TextureFormat.RGB24, false);
texture.filterMode = FilterMode.Trilinear;
texture.LoadImage(bytes);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, 512, 512), new Vector2(0.5f, 0.0f), 1.0f);
sprite_bg.GetComponent<SpriteRenderer>().sprite = sprite;
return null;
}
`
]1]1
我打开游戏,精灵不渲染
如果您从资源文件夹加载文件,请尝试 Resources.Load
此处了解更多信息:Information about Resources folder
Sprite SpriteModding(字符串路径)
{
byte[] bytes = File.ReadAllBytes(Application.dataPath + "/Resources/fgsoftwarestudio.png");
Texture2D texture = new Texture2D(512, 512, TextureFormat.RGB24, false);
texture.filterMode = FilterMode.Trilinear;
texture.LoadImage(bytes);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, 512, 512), new Vector2(0.5f, 0.0f), 1.0f);
sprite_bg.GetComponent<SpriteRenderer>().sprite = sprite;
return null;
}
` ]1]1
我打开游戏,精灵不渲染
如果您从资源文件夹加载文件,请尝试 Resources.Load
此处了解更多信息:Information about Resources folder