Unity 更换纹理贴图

// 加载贴图        
AssetsManager.Instance.LoadAsset(texturePath).AddCallback(LoadComplete, LoadError);
        
        //加载完毕
        void LoadComplete(AssetsAsyncOperation _operation)
        {
            if (texturePath != "")
            {
                Texture t = _operation.GetAsset();
                
                foreach (var item in targetEntityList)
                {
                    var render = item.GameObject.GetComponentInChildren();
                    if (render != null)
                    {
                        var material = render.materials[0];
                        if (material != null)
                        {
                            material.mainTexture = t;
                        }
                    }
                }
            }
        }

        //加载错误
        void LoadError(AssetsAsyncOperation _operation)
        {
            this.Log($"加载贴图失败:{texturePath}");
        }

你可能感兴趣的:(Unity 更换纹理贴图)