美文网首页
Unity 更换纹理贴图

Unity 更换纹理贴图

作者: 3c9a4f007e1b | 来源:发表于2019-08-12 10:03 被阅读0次
// 加载贴图        
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