mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
1:一键打包ab包:新增快捷键,暂定f8。自动生成dll,打包资源,自动将项目的StreamingAssets复制到打包后的StreamingAssets文件夹下
2:UpdateSetting (1)新增webgl设置,选择访问远程还是StreamingAssets (2)构建资源设置:是否自动复制资源包到打包地址;打包地址如:../../Builds/Unity_Data/StreamingAssets,支持绝对路径和相对路径
This commit is contained in:
@@ -57,14 +57,89 @@ namespace TEngine
|
||||
Debug.LogWarning($"Start BuildPackage BuildTarget:{target} outputPath:{outputRoot}");
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/Build/一键打包AssetBundle")]
|
||||
[MenuItem("TEngine/Build/一键打包AssetBundle _F8")]
|
||||
public static void BuildCurrentPlatformAB()
|
||||
{
|
||||
{
|
||||
BuildDLLCommand.BuildAndCopyDlls();
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
BuildInternal(target, Application.dataPath + "/../Builds/", packageVersion: GetBuildPackageVersion());
|
||||
AssetDatabase.Refresh();
|
||||
//复制到打包后的StreamingAssets
|
||||
CopyStreamingAssetsFiles();
|
||||
}
|
||||
/// <summary>
|
||||
/// 复制StreamingAssets文件去打包目录
|
||||
/// </summary>
|
||||
public static void CopyStreamingAssetsFiles()
|
||||
{
|
||||
if (!Settings.UpdateSetting.IsAutoAssetCopeToBuildAddress())
|
||||
{
|
||||
Debug.Log("UpdateSetting.IsAutoAssetCopeToBuildAddress关闭,并不会生产到打包目录中");
|
||||
return;
|
||||
}
|
||||
// 获取StreamingAssets路径
|
||||
string streamingAssetsPath = Application.streamingAssetsPath;
|
||||
|
||||
// 目标路径,可以是任何你想要的目录
|
||||
string targetPath = Settings.UpdateSetting.GetBuildAddress();
|
||||
|
||||
// 判断目标路径是相对路径还是绝对路径
|
||||
if (!System.IO.Path.IsPathRooted(targetPath))
|
||||
{
|
||||
// 如果是相对路径,结合 StreamingAssets 的路径进行合并
|
||||
targetPath = System.IO.Path.Combine(streamingAssetsPath, targetPath);
|
||||
}
|
||||
|
||||
// 如果目标目录不存在,创建它
|
||||
if (!System.IO.Directory.Exists(targetPath))
|
||||
{
|
||||
Debug.LogError("打包目录不存在,检查UpdateSetting BuildAddress:"+targetPath);
|
||||
return;
|
||||
}
|
||||
// 删除目标路径下的所有文件
|
||||
string[] Deletefiles = System.IO.Directory.GetFiles(targetPath);
|
||||
foreach (var file in Deletefiles)
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
Debug.Log($"删除文件: {file}");
|
||||
}
|
||||
|
||||
// 删除目标路径下的所有子目录
|
||||
string[] directories = System.IO.Directory.GetDirectories(targetPath);
|
||||
foreach (var directory in directories)
|
||||
{
|
||||
System.IO.Directory.Delete(directory, true); // true 表示递归删除子目录及其中内容
|
||||
Debug.Log($"删除目录: {directory}");
|
||||
}
|
||||
|
||||
// 获取StreamingAssets中的所有文件,排除.meta文件
|
||||
string[] files = System.IO.Directory.GetFiles(streamingAssetsPath, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
// 遍历并复制文件到目标目录
|
||||
foreach (var file in files)
|
||||
{
|
||||
// 排除.meta文件
|
||||
if (file.EndsWith(".meta"))
|
||||
continue;
|
||||
|
||||
// 获取相对路径,用于在目标目录中创建相同的文件结构
|
||||
string relativePath = file.Substring(streamingAssetsPath.Length + 1);
|
||||
string destinationFilePath = System.IO.Path.Combine(targetPath, relativePath);
|
||||
|
||||
// 确保目标文件夹存在
|
||||
string destinationDir = System.IO.Path.GetDirectoryName(destinationFilePath);
|
||||
if (!System.IO.Directory.Exists(destinationDir))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(destinationDir);
|
||||
}
|
||||
|
||||
// 复制文件
|
||||
System.IO.File.Copy(file, destinationFilePath, true); // true 表示覆盖已存在的文件
|
||||
|
||||
|
||||
}
|
||||
Debug.Log($"复制文件完成:{targetPath}");
|
||||
}
|
||||
private static BuildTarget GetBuildTarget(string platform)
|
||||
{
|
||||
BuildTarget target = BuildTarget.NoTarget;
|
||||
|
@@ -36,7 +36,17 @@ namespace TEngine
|
||||
/// </summary>
|
||||
NoNotice = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WebGL平台下,
|
||||
/// StreamingAssets:跳过远程下载资源直接访问StreamingAssets
|
||||
/// Remote:访问远程资源
|
||||
/// </summary>
|
||||
public enum LoadResWayWebGL
|
||||
{
|
||||
Remote,
|
||||
StreamingAssets,
|
||||
}
|
||||
|
||||
[CreateAssetMenu(menuName = "TEngine/UpdateSetting", fileName = "UpdateSetting")]
|
||||
public class UpdateSetting : ScriptableObject
|
||||
{
|
||||
@@ -96,6 +106,48 @@ namespace TEngine
|
||||
[SerializeField]
|
||||
private string FallbackResDownLoadPath = "http://127.0.0.1:8082";
|
||||
|
||||
/// <summary>
|
||||
/// WebGL平台加载本地资源/加载远程资源。
|
||||
/// </summary>
|
||||
[Header("WebGL设置")]
|
||||
[SerializeField]
|
||||
private LoadResWayWebGL LoadResWayWebGL = LoadResWayWebGL.Remote;
|
||||
/// <summary>
|
||||
/// 是否自动你讲打包资源复制到打包后的StreamingAssets地址
|
||||
/// </summary>
|
||||
[Header("构建资源设置")]
|
||||
[SerializeField]
|
||||
private bool isAutoAssetCopeToBuildAddress = false;
|
||||
/// <summary>
|
||||
/// 打包程序资源地址
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private string BuildAddress = "../../Builds/Unity_Data/StreamingAssets";
|
||||
/// <summary>
|
||||
/// 是否自动你讲打包资源复制到打包后的StreamingAssets地址
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsAutoAssetCopeToBuildAddress()
|
||||
{
|
||||
return isAutoAssetCopeToBuildAddress;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取打包程序资源地址
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetBuildAddress()
|
||||
{
|
||||
return BuildAddress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否加载远程资源
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public LoadResWayWebGL GetLoadResWayWebGL()
|
||||
{
|
||||
return LoadResWayWebGL;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取资源下载路径。
|
||||
/// </summary>
|
||||
|
@@ -76,7 +76,12 @@ namespace TEngine
|
||||
/// 备用热更URL。
|
||||
/// </summary>
|
||||
string FallbackHostServerURL { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// WebGL平台加载本地资源/加载远程资源。
|
||||
/// </summary>
|
||||
LoadResWayWebGL LoadResWayWebGL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置资源对象池自动释放可释放对象的间隔秒数。
|
||||
/// </summary>
|
||||
|
@@ -53,6 +53,11 @@ namespace TEngine
|
||||
public string HostServerURL { get; set; }
|
||||
|
||||
public string FallbackHostServerURL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// WebGL:加载资源方式
|
||||
/// </summary>
|
||||
public LoadResWayWebGL LoadResWayWebGL { get; set; }
|
||||
|
||||
private string _applicableGameVersion;
|
||||
|
||||
@@ -207,7 +212,10 @@ namespace TEngine
|
||||
createParameters.WebServerFileSystemParameters = WechatFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteServices, webDecryptionServices);
|
||||
#else
|
||||
Log.Info("=======================UNITY_WEBGL=======================");
|
||||
createParameters.WebRemoteFileSystemParameters = FileSystemParameters.CreateDefaultWebRemoteFileSystemParameters(remoteServices, webDecryptionServices);
|
||||
if (LoadResWayWebGL==LoadResWayWebGL.Remote)
|
||||
{
|
||||
createParameters.WebRemoteFileSystemParameters = FileSystemParameters.CreateDefaultWebRemoteFileSystemParameters(remoteServices, webDecryptionServices);
|
||||
}
|
||||
createParameters.WebServerFileSystemParameters = FileSystemParameters.CreateDefaultWebServerFileSystemParameters(webDecryptionServices);
|
||||
#endif
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
|
@@ -250,6 +250,7 @@ namespace TEngine
|
||||
_resourceModule.Milliseconds = milliseconds;
|
||||
_resourceModule.HostServerURL = Settings.UpdateSetting.GetResDownLoadPath();
|
||||
_resourceModule.FallbackHostServerURL = Settings.UpdateSetting.GetFallbackResDownLoadPath();
|
||||
_resourceModule.LoadResWayWebGL=Settings.UpdateSetting.GetLoadResWayWebGL();
|
||||
_resourceModule.DownloadingMaxNum = DownloadingMaxNum;
|
||||
_resourceModule.FailedTryAgain = FailedTryAgain;
|
||||
_resourceModule.UpdatableWhilePlaying = UpdatableWhilePlaying;
|
||||
|
Reference in New Issue
Block a user