using UnityEngine; using UnityEngine.UI; using System.IO; public class bundleunpack :…
- User
using UnityEngine; using UnityEngine.UI; using System.IO;
public class bundleunpack : MonoBehaviour { public string bundlePath; // Путь к .bundle файлу public string imageName; // Имя изображения в AssetBundle public GameObject imageHolder; // Ссылка на объект, содержащий компонент Image public string savePath;
codevoid Start() { Debug.Log("program started"); // Загрузка AssetBundle AssetBundle bundle = AssetBundle.LoadFromFile(bundlePath); // Проверка наличия AssetBundle if (bundle != null) { Debug.Log("Bundle loaded"); // Get all asset names in the AssetBundle string[] assetNames = bundle.GetAllAssetNames(); // Iterate over each asset name foreach (string assetName in assetNames) { // Check if the asset is an image Debug.Log("Image Name: " + assetName); } // Загрузка изображения из AssetBundle Sprite image = bundle.LoadAsset<Sprite>(imageName); // Получение компонента Image из объекта-держателя изображения Image targetImage = imageHolder.GetComponent<Image>(); // Установка загруженного изображения в компонент Image targetImage.sprite = image; bundle.Unload(false); // Выгрузка AssetBundle }else{Debug.Log("None of bundle");} }}
Добавь в код foreach, чтобы каждый файл сохранялся на диск по пути savePath
- Assistant
public class bundleunpack : MonoBehaviour { public string bundlePath; // Путь к .bundle файлу public string imageName; // Имя изображения в AssetBundle public GameObject imageHolder; // Ссылка на объект, содержащий компонент Image public string savePath; // Путь для сохранения файлов
code - User
using UnityEngine; using UnityEngine.UI; using System.IO;
public class NewBehaviourScript1 : MonoBehaviour { public string bundlePath; public string imageName; public GameObject imageHolder; public string savePath;
codevoid Start() { Debug.Log("program started"); AssetBundle bundle = AssetBundle.LoadFromFile(bundlePath); if (bundle != null) { Debug.Log("Bundle loaded"); string[] assetNames = bundle.GetAllAssetNames(); foreach (string assetName in assetNames) { Debug.Log("Image Name: " + assetName); # Добавь здесь код с сохранением файла из bundle на диск в папку savePath } }else{Debug.Log("None of bundle");} }}
Добавь здесь код с сохранением файла из bundle на диск в папку savePath
- Assistantcode
using UnityEngine; using UnityEngine.UI; using System.IO; public class NewBehaviourScript1 : MonoBehaviour { public string bundlePath; public string imageName; public GameObject imageHolder; public string savePath; void Start() { AssetBundle bundle = AssetBundle.LoadFromFile(bundlePath); if (bundle != null) { string[] assetNames = bundle.GetAllAssetNames(); foreach (string assetName in assetNames) { if (assetName.EndsWith(".png") || assetName.EndsWith(".jpg") || assetName.EndsWith(".jpeg")) { Debug.Log("Image Name: " + assetName); byte[] imageData = bundle.LoadAsset<TextAsset>(assetName).bytes; string fileName = Path.GetFileName(assetName); string filePath = Path.Combine(savePath, fileName); File.WriteAllBytes(filePath, imageData); } } bundle.Unload(false); } } }