如果不想通过 改变Texture2D图片的Read/Write Enable为 非勾选 状态,参考资料1.
加载AB包,之后,由于图片全部在一个AB包中,将AB包卸载就会使得 从AB包加载的图片 失效,为空。
要使得AB包中的Texture,Texture2D图片可用。
先确保 要打包 的图片的Read/Write Enable为 勾选状态。
用代码批量处理 当前项目工程 中的 所有 .png图片 ,设置为Read/Write Enable = true,然后再批量打AB包
using UnityEditor;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Linq;//.OfType
using System.Xml;
public class CreateAssetBundles
{
private static string path_111= "/Assets";//F:\mxdmap\body\Assets
[MenuItem("Assets/Build AssetBundles/SetReadWriteTrue")]
static void SetReadWriteTrue()
{
Debug.LogWarning("------开始");
string fullPath = Application.dataPath;
Debug.Log("fullPath:" + fullPath + "..." + fullPath.Length);
Debug.Log("path_111:" + path_111 + "..." + path_111.Length);
if (Directory.Exists(fullPath))
{
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
Debug.Log(files.Length);
string str = "",str_1 ="";
for (int i = 0; i < files.Length; i++)
{
str = files[i].FullName.Substring(files[i].FullName.Length - 4, 4);
if (str == ".png")
{
//Debug.Log("files[i].FullName:" + files[i].FullName);
s