111
This commit is contained in:
@@ -24,6 +24,8 @@ namespace Stary.Evo.Editor
|
||||
private bool _isBuilding;
|
||||
private UnityEditor.Build.Reporting.BuildReport _lastBuildReport;
|
||||
private string[] _scenePaths;
|
||||
private string _buildAssetTagName;
|
||||
private string buildAPKTagName;
|
||||
|
||||
[Title("设备类型选择", titleAlignment: TitleAlignments.Centered)] [EnumToggleButtons, HideLabel]
|
||||
public DeviceType deviceType = DeviceType.Xreal;
|
||||
@@ -34,12 +36,14 @@ namespace Stary.Evo.Editor
|
||||
[OnValueChanged("OnPackageNameChanged")]
|
||||
public string selectedPackageName;
|
||||
|
||||
[Title("打包配置", titleAlignment: TitleAlignments.Centered)] [ToggleLeft] [LabelText("自动递增版本号")]
|
||||
[TitleGroup("打包配置", alignment: TitleAlignments.Centered)] [ToggleLeft] [LabelText("自动递增版本号")]
|
||||
public bool autoIncrementVersion = true;
|
||||
|
||||
[Title("打包配置", titleAlignment: TitleAlignments.Centered)] [ToggleLeft] [LabelText("是否添加水印")]
|
||||
[TitleGroup("打包配置", alignment: TitleAlignments.Centered)] [ToggleLeft] [LabelText("是否添加水印")]
|
||||
public bool isWatermark = false;
|
||||
|
||||
[TitleGroup("打包配置", alignment: TitleAlignments.Centered)] [ToggleLeft] [LabelText("是否服务器热更包")]
|
||||
[OnValueChanged("OnServerChangedTag")]
|
||||
public bool isServer = false;
|
||||
[ToggleLeft] [LabelText("构建完成后打开文件夹")] public bool openFolderOnComplete = true;
|
||||
|
||||
[BoxGroup("缓存管理", centerLabel: true)]
|
||||
@@ -48,24 +52,38 @@ namespace Stary.Evo.Editor
|
||||
{
|
||||
ClearCache();
|
||||
}
|
||||
|
||||
[Button("$GetBuildTargetName", ButtonSizes.Large)]
|
||||
private void ResourceManagement()
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
StreamingAssetsFilter.OnPostprocessBuild();
|
||||
StreamingAssetsFilter.KeepFiles = new[]
|
||||
{
|
||||
$"{YooAssetSettingsData.GetDefaultYooFolderName()}/Main",
|
||||
$"{YooAssetSettingsData.GetDefaultYooFolderName()}/{selectedPackageName}"
|
||||
};
|
||||
StreamingAssetsFilter.OnPreprocessBuild();
|
||||
}
|
||||
else
|
||||
{
|
||||
StreamingAssetsFilter.KeepFiles=new string[0];
|
||||
StreamingAssetsFilter.OnPreprocessBuild();
|
||||
}
|
||||
}
|
||||
[ButtonGroup]
|
||||
[Button("本地普通包", ButtonSizes.Large, ButtonStyle.FoldoutButton)]
|
||||
[Button("$GetBuildAPKName", ButtonSizes.Large, ButtonStyle.FoldoutButton)]
|
||||
private void BuildNormalPackage()
|
||||
{
|
||||
|
||||
StreamingAssetsFilter.KeepFiles = new[]
|
||||
if (!isServer)
|
||||
{
|
||||
$"{YooAssetSettingsData.GetDefaultYooFolderName()}/Main",
|
||||
$"{YooAssetSettingsData.GetDefaultYooFolderName()}/{selectedPackageName}"
|
||||
};
|
||||
StartBuild(PLayerMode.LOCAL_PLAYMODE);
|
||||
}
|
||||
|
||||
[Button("服务器热更包", ButtonSizes.Large, ButtonStyle.FoldoutButton)]
|
||||
private void BuildServerPackage()
|
||||
{
|
||||
StartBuild(PLayerMode.HOST_PLAYMODE);
|
||||
|
||||
StartBuild(PLayerMode.LOCAL_PLAYMODE);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartBuild(PLayerMode.HOST_PLAYMODE);
|
||||
}
|
||||
}
|
||||
|
||||
[Title("打包状态", titleAlignment: TitleAlignments.Centered)] [ReadOnly] [LabelText("当前状态")]
|
||||
@@ -643,6 +661,19 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void OnServerChangedTag()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private string GetBuildTargetName()
|
||||
{
|
||||
return isServer ? "清空所有资源" : "拷贝打包资源";
|
||||
}
|
||||
private string GetBuildAPKName()
|
||||
{
|
||||
return isServer ? "打包服务器热更包" : "打包本地运行包";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 枚举
|
||||
|
||||
@@ -4,18 +4,18 @@ using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
public class StreamingAssetsFilter : IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
public static class StreamingAssetsFilter
|
||||
{
|
||||
// 需要保留的文件/文件夹(相对于 StreamingAssets 的路径)
|
||||
public static string[] KeepFiles;
|
||||
|
||||
private string streamingAssetsPath;
|
||||
private string tempBackupPath;
|
||||
public int callbackOrder => 0; // 执行优先级
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
private static string streamingAssetsPath;
|
||||
private static string tempBackupPath;
|
||||
public static int callbackOrder => 0; // 执行优先级
|
||||
// 要删除的文件后缀列表
|
||||
private const string extensionsToDelete = ".meta";
|
||||
public static void OnPreprocessBuild()
|
||||
{
|
||||
if (report.summary.platform != BuildTarget.Android) return;
|
||||
|
||||
streamingAssetsPath = Application.dataPath + "/StreamingAssets";
|
||||
tempBackupPath = Application.dataPath + "/../Temp/StreamingAssets_Backup";
|
||||
@@ -30,6 +30,11 @@ public class StreamingAssetsFilter : IPreprocessBuildWithReport, IPostprocessBui
|
||||
|
||||
foreach (var file in allFiles)
|
||||
{
|
||||
if (file.Contains( extensionsToDelete, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string relativePath = file.Replace(streamingAssetsPath + Path.DirectorySeparatorChar, "")
|
||||
.Replace(streamingAssetsPath, "");
|
||||
|
||||
@@ -44,11 +49,11 @@ public class StreamingAssetsFilter : IPreprocessBuildWithReport, IPostprocessBui
|
||||
}
|
||||
|
||||
Debug.Log($"[StreamingAssetsFilter] 已过滤,保留 {KeepFiles.Length} 项,其余已移至临时目录");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
public static void OnPostprocessBuild()
|
||||
{
|
||||
if (report.summary.platform != BuildTarget.Android) return;
|
||||
|
||||
if (!Directory.Exists(tempBackupPath)) return;
|
||||
|
||||
@@ -57,6 +62,13 @@ public class StreamingAssetsFilter : IPreprocessBuildWithReport, IPostprocessBui
|
||||
|
||||
foreach (var file in backupFiles)
|
||||
{
|
||||
if (file.Contains( extensionsToDelete, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Debug.Log($"删除文件: {file}");
|
||||
File.Delete(file);
|
||||
continue;
|
||||
|
||||
}
|
||||
string relativePath = file.Replace(tempBackupPath + Path.DirectorySeparatorChar, "")
|
||||
.Replace(tempBackupPath, "");
|
||||
string originalPath = Path.Combine(streamingAssetsPath, relativePath);
|
||||
@@ -71,10 +83,10 @@ public class StreamingAssetsFilter : IPreprocessBuildWithReport, IPostprocessBui
|
||||
Debug.Log("[StreamingAssetsFilter] 已恢复所有文件到 StreamingAssets");
|
||||
}
|
||||
|
||||
private bool ShouldKeep(string relativePath)
|
||||
private static bool ShouldKeep(string relativePath)
|
||||
{
|
||||
string normalizedPath = relativePath.Replace('\\', '/');
|
||||
|
||||
if(KeepFiles==null||KeepFiles.Length==0) return false;
|
||||
foreach (var keep in KeepFiles)
|
||||
{
|
||||
string normalizedKeep = keep.Replace('\\', '/');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.tools",
|
||||
"version": "1.3.24",
|
||||
"version": "1.3.25",
|
||||
"displayName": "00.StaryEvo.Tools",
|
||||
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
||||
"unity": "2021.3",
|
||||
|
||||
Reference in New Issue
Block a user