当前位置:网站首页>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
- Are you still watching the weather forecast on TV?
- What is definition? What is a statement? What is the difference between them?
- vcs import src < ros2. Repos failed
- the installer has encountered an unexpected error installing this package
- The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
- Demonstration of plug-in use of ventuz basic series
- Research shows that breast cancer cells are more likely to enter the blood when patients sleep
- [MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18
- Huawei switch: configure Telnet, SSH and web access
猜你喜欢

oracle 插入单引号

什么是数据类型?数据类型有什么用?
![[cocos creator] Click the button to switch the interface](/img/b8/f0fd54a2a197cbfd788990e2806b52.png)
[cocos creator] Click the button to switch the interface

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
![[MySQL 12] MySQL 8.0.18 reinitialization](/img/e1/9874df18bbc8d80c3c5c5fe39aefc9.png)
[MySQL 12] MySQL 8.0.18 reinitialization

Pat class a 1032 sharing

Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico

haproxy+keepalived搭建01

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico

What is a data type? What is the use of data types?
随机推荐
JSON与Object之间转换
PHP common sorting algorithm
2020-12-12
P1896 [SCOI2005] 互不侵犯(状压dp)
Install cross compiler arm none liunx gnueabihf
Differences between tp3.2 and tp5.0
EtherCAT state machine transition (ESM)
regular expression
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
Client server model
Redis查看客户端连接
Zohocrm deluge function application time verification
MaxCompute字符串分割函数-SPLIT_PART
What to do after the browser enters the URL
STM32F103 SPI (pit Diary)
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
C2-关于VCF文件合并的几种方法
Register keyword
The general trend of data news releases the power of visual reporting ----- essays after reading