当前位置:网站首页>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");
}
边栏推荐
- go语言-循环语句
- [untitled]
- 【cocos creator】获取资源uuid
- JSON与Object之间转换
- Go language foundation ------ 14 ------ gotest
- The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
- tp3.2和tp5.0的区别
- Are you still watching the weather forecast on TV?
- PHP常用排序算法
- How to clear the console password for s7700 device
猜你喜欢

*p++、*++p、++*p、(*p)++

Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)

VMware virtual machine configuration static IP

PostGIS space function

Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire

Technical dry goods | some thoughts on the future of AI architecture
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.

LwIP learning socket (application)

一个实习生的CnosDB之旅
随机推荐
【cocos creator】获取资源uuid
P2704 [NOI2001] 炮兵阵地(状压dp)
Redis批量启停脚本
PHP常用排序算法
PostGIS space function
PHP微信抢红包的算法
Idea unreference Display Effect
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
一篇文章让你读懂-曼彻斯特编码
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
Iterm2设置
OSPF experiment
Structure of golang
在浏览器输入url后执行什么
Client server model
HDMI2.1与HDMI2.0的区别以及转换PD信号。
[at] abc 258G - Triangle 三元组可达-暴力
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
Viz artist advanced script video tutorial -- stringmap use and vertex operation