(或者说怎么打开动态加载图片的读写权限)
unity的Read/Write Enable无法在运行项目时设置
/// <summary>
/// 以AssetBundle方式进行加载
/// </summary>
private void LoadByAB()
{
WWW w = new WWW("file://" + Application.streamingAssetsPath + "/Test.assetbundle");
mTex = w.assetBundle.LoadAsset<Texture2D>("Test.jpg");
Color[] colors = mTex.GetPixels();
Debug.LogFormat("pixels:{0}", colors.Length);
}
看看能不能帮到你
楼主用www加载图片到内存不就可以了吗?这个不需要权限吧
找了很久最后在Unity社区上找到了原因,因为用的是AssetBundle加载资源,资源包是别人做的
所以原因就是打包资源包的同事没有勾上可读性,所以会报错!!
附上社区地址 https://answers.unity.com/questions/988174/create-modify-texture2d-to-readwrite-enabled-at-ru.html
最后 wjintao 给的方法都是可行的,因为外部加载的图片默认可读。(AssetBundle默认不行是因为unity有自动标记)