当前位置:网站首页>Unity one click AssetBundle
Unity one click AssetBundle
2022-07-03 07:57:00 【qq_ two billion three hundred and eighty-five million seven hun】
ChuangLi_BuildAB class
[MenuItem("Build AssetBundle/Taptap/1-Build AssetBundles")]
public static void BuildABS()
{
BuildAssetBundle();
AssetDatabase.Refresh();
Debug.Log("BuildABS OK");
CopyFilesToABsFile();
}BuildAssetBundles class
protected static void BuildAssetBundle()
{
Platform pf = GetPlatform();
// Delete incremental folder Delete backup folder
ClearIncrements(pf);
ClearTemp(pf);
CheckPath(pf.abPath);
// Change the current asset bundle Make a backup ,
CopyDirectory(pf.abPath, pf.CopyabPath);
// pack assetbundle , And use LZ4 Compress
BuildPipeline.BuildAssetBundles(pf.abPath, BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle, pf.target);
CreateSizeFile(pf.abPath);
// Compare the latest asset bundle And backup assetbundle , And copy to the new incremental folder
CopyChangeFile(pf.abPath, pf.CopyabPath, pf);
// Delete backup folder
ClearTemp(pf);
} protected static Platform GetPlatform()
{
Platform pf = new Platform();
pf.abFilesDic = new Dictionary<string, string>();
pf.CopyabFilesDic = new Dictionary<string, string>();
pf.NeedDownFiles = new List<string>();
pf.ABsFilePath = Application.dataPath + "/StreamingAssets/ABs/";
string tag = "Unkonwn";
#if UNITY_ANDROID
tag = "Android";
pf.target = BuildTarget.Android;
#endif
#if UNITY_IPHONE
tag = "IOS";
pf.target = BuildTarget.iOS;
#endif
#if UNITY_STANDALONE_WIN
tag = "Win";
pf.target = BuildTarget.StandaloneWindows64;
#endif
#if UNITY_WSA
tag = "WSA";
pf.target = BuildTarget.WSAPlayer;
#endif
pf.abPath = Application.dataPath + "/../ABS_" + tag + "/AssetBundles/";
pf.CopyabPath = Application.dataPath + "/../ABS_" + tag + "/OldAssetBundles/";
pf.name = "AssetBundles";
pf.changeFilePath = Application.dataPath + "/../ABS_" + tag + "/" + tag + System.DateTime.Now.ToString("_yyyyMMdd_HHmmss") + "/";
return pf;
}
static void ClearIncrements(Platform pf)
{
if (Directory.Exists(pf.changeFilePath))
{
Directory.Delete(pf.changeFilePath, true);
}
} static void ClearTemp(Platform pf)
{
if (Directory.Exists(pf.CopyabPath))
{
Directory.Delete(pf.CopyabPath, true);
}
} protected static void CheckPath(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}// Change the current asset bundle Make a backup ,
public static void CopyDirectory(string srcPath, string destPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); // Get the directory ( No subdirectories ) Files and subdirectories
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) // Determine whether the folder
{
if (!Directory.Exists(destPath + "\\" + i.Name))
{
Directory.CreateDirectory(destPath + "\\" + i.Name); // If this folder does not exist in the target directory, create a subfolder
}
CopyDirectory(i.FullName, destPath + "\\" + i.Name); // Recursive call to copy subfolders
}
else
{
File.Copy(i.FullName, destPath + "\\" + i.Name, true); // Either folder or copy file ,true Indicates that the file with the same name can be overwritten
}
}
}
catch (System.Exception e)
{
throw;
}
} static void CreateSizeFile(string path)
{
using (FileStream t_file = new FileStream(path + "_FileSize.txt", FileMode.Create, FileAccess.Write))
{
using (StreamWriter t_sw = new StreamWriter(t_file))
{
DirectoryInfo dir = new DirectoryInfo(path);
string perStr = dir.FullName;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Ddir(path, sb, perStr);
t_sw.Write(sb.ToString());
}
}
index = 0;
using (FileStream t_file = new FileStream(path + "ResList.txt", FileMode.Create, FileAccess.Write))
{
using (StreamWriter t_sw = new StreamWriter(t_file))
{
DirectoryInfo dir = new DirectoryInfo(path);
string perStr = dir.FullName;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Ddir2(path, sb, perStr);
Ddir2End(sb);
t_sw.Write(sb.ToString());
}
}
}// Compare the latest asset bundle And backup assetbundle , And copy to the new incremental folder
static void CopyChangeFile(string path, string copiedPath, Platform pf)
{
DirectoryInfo newPath = new DirectoryInfo(path);
DirectoryInfo oldPath = new DirectoryInfo(copiedPath);
List<FileInfo> list = new List<FileInfo>();
GetChangedAbs(path, newPath.FullName, oldPath.FullName, ref list);
DirectoryInfo changePath = new DirectoryInfo(pf.changeFilePath);
if (changePath.Exists)
{
changePath.Delete();
}
changePath.Create();
foreach (var file in list)
{
FileInfo fi = new FileInfo(file.FullName.Replace(newPath.FullName, changePath.FullName));
if (!Directory.Exists(fi.Directory.FullName))
{
fi.Directory.Create();
}
File.Copy(file.FullName, fi.FullName);
}
} static void ClearTemp(Platform pf)
{
if (Directory.Exists(pf.CopyabPath))
{
Directory.Delete(pf.CopyabPath, true);
}
}Copy the new resources to ABs In the folder
/// <summary>
/// Copy the new resources to ABs In the folder
/// </summary>
//[MenuItem("Build AssetBundle/Taptap/2-Copy AssetBundles To StreamingAssets")]
public static void CopyFilesToABsFile()
{
Platform pf = GetPlatform();
CheckPath(pf.ABsFilePath);
DeleteFiles(pf.ABsFilePath);
CheckPath(pf.ABsFilePath);
CopyDirectory(pf.abPath, pf.ABsFilePath);
AssetDatabase.Refresh();
Debug.Log("CopyFilesToABsFile OK");
}
边栏推荐
- 使用 FileChannel 进行文件的复制拷贝
- Screenshot tool snipaste
- Differences between tp3.2 and tp5.0
- Redis查看客户端连接
- [MySQL 12] MySQL 8.0.18 reinitialization
- 在浏览器输入url后执行什么
- Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
- Research shows that breast cancer cells are more likely to enter the blood when patients sleep
- What is a data type? What is the use of data types?
- Zohocrm deluge function application time verification
猜你喜欢

LwIP learning socket (application)

Are you still watching the weather forecast on TV?

How to configure GDAL under idea

Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once

Redis batch startup and shutdown script

一篇文章让你读懂-曼彻斯特编码

Harmonyos third training notes

【cocos creator】点击按钮切换界面

WPF:解决MaterialDesign:DialogHost 无法关闭问题

Getting started with minicom
随机推荐
the installer has encountered an unexpected error installing this package
在浏览器输入url后执行什么
多旅行商问题——公式和求解过程概述
JS common basic case sorting (continuous update)
华为交换机Console密码重置、设备初始化、默认密码
Client server model
Install cross compiler arm none liunx gnueabihf
How to clear the console password for s7700 device
Uniapp learning records
Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
Redis配置文件
jsutlis
Idea dereference display effect
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
freetype库的移植
什么是数据类型?数据类型有什么用?
Go language foundation ----- 16 ----- goroutine, GPM model
一篇文章让你读懂-曼彻斯特编码
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task