当前位置:网站首页>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");
}
边栏推荐
- Pat class a 1030 travel plan
- [cocos creator] Click the button to switch the interface
- PHP common sorting algorithm
- IP production stream is so close to me
- Go language foundation ------ 14 ------ gotest
- PostGIS space function
- 什么是数据类型?数据类型有什么用?
- WPF:解决MaterialDesign:DialogHost 无法关闭问题
- Introduction of novel RNA based cancer therapies
- Getting started with minicom
猜你喜欢

Getting started with minicom

Go language foundation ------ 14 ------ gotest

Pat class a 1030 travel plan

VMware virtual machine configuration static IP

the installer has encountered an unexpected error installing this package

Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“

一条通往服务器所有端口的隧道

haproxy+keepalived搭建01

Viz artist advanced script video tutorial -- stringmap use and vertex operation

Worldview satellite remote sensing image data / meter resolution remote sensing image
随机推荐
一篇文章让你读懂-曼彻斯特编码
static关键字
什么是数据类型?数据类型有什么用?
Go language foundation ----- 16 ----- goroutine, GPM model
C language learning notes (mind map)
[at] abc 258G - Triangle 三元組可達-暴力
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
Iterm2设置
链式长取值
Go language foundation ----- 10 ----- string related operations (operation function, string conversion)
yarn link 是如何帮助开发者对 NPM 包进行 debug 的?
register关键字
Go language foundation ------17 ----- channel creation, read-write, security shutdown, multiplexing select
Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)
Demonstration of plug-in use of ventuz basic series
Redis批量启停脚本
Ventuz Foundation Series "one step at the door"
My touch screen production "brief history" 1
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
[at] ABC 258g - triple Reach - violence