53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using BITKit;
|
|
using UnityEditor;
|
|
using Sirenix.OdinInspector;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
namespace BITKit.IO
|
|
{
|
|
public class AssetBundleHelper : SerializedMonoBehaviour
|
|
{
|
|
[Sirenix.OdinInspector.FilePath]
|
|
public string path;
|
|
public string header = "Header";
|
|
public List<string> strings = new();
|
|
[ContextMenu(nameof(Write))]
|
|
public void Write()
|
|
{
|
|
Dictionary<string, string> dictionary = new();
|
|
foreach (var _str in strings)
|
|
{
|
|
dictionary.Add(_str, Guid.NewGuid().ToString());
|
|
}
|
|
var value = strings.Select(x => new BITAsset()
|
|
{
|
|
Name = x,
|
|
Buffer = Encoding.UTF8.GetBytes(x)
|
|
}).ToList();
|
|
value.Add(new()
|
|
{
|
|
Name = nameof(header),
|
|
Buffer = Encoding.UTF8.GetBytes(header),
|
|
});
|
|
value.Add(new()
|
|
{
|
|
Name = nameof(dictionary),
|
|
Buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dictionary)),
|
|
});
|
|
BITAssets.Build(path, value.ToArray());
|
|
}
|
|
[ContextMenu(nameof(Read))]
|
|
public async void Read()
|
|
{
|
|
Debug.Log(await BITAssets.ReadTextAsync(path, nameof(header)));
|
|
}
|
|
}
|
|
}
|
|
|