[Unity][AssetBundle]加载并复制AB包中的Texture2D图片

在Unity中,不改变Texture2D的Read/Write Enable状态,可以通过加载AssetBundle来复制AB包中的Texture2D图片。为确保图片可用,需要在打包前将图片的Read/Write Enable设为true,然后进行批量打AB包。加载AB包后,可以复制图片并获取其内容。参考资源包括关于AssetBundle和克隆Texture2D的教程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

如果不想通过 改变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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值