Unity 更换纹理贴图

2019-08-12  本文已影响0人  3c9a4f007e1b
// 加载贴图        
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}");
        }
上一篇 下一篇

猜你喜欢

热点阅读