Unity 更换纹理贴图
// 加载贴图
AssetsManager.Instance.LoadAsset(texturePath).AddCallback(LoadComplete, LoadError);
//加载完毕
void LoadComplete(AssetsAsyncOperation _operation)
{
if (texturePath != "")
{
Texture t = _operation.GetAsset<Texture>();
foreach (var item in targetEntityList)
{
var render = item.GameObject.GetComponentInChildren<Renderer>();
if (render != null)
{
var material = render.materials[0];
if (material != null)
{
material.mainTexture = t;
}
}
}
}
}
//加载错误
void LoadError(AssetsAsyncOperation _operation)
{
this.Log($"加载贴图失败:{texturePath}");
}
本文标题:Unity 更换纹理贴图
本文链接:https://www.haomeiwen.com/subject/dsjyjctx.html
网友评论