【m】资源目录索引
This commit is contained in:
@@ -9,6 +9,7 @@ using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
@@ -52,6 +53,11 @@ namespace Stary.Evo.Editor
|
||||
[Button("本地普通包", ButtonSizes.Large, ButtonStyle.FoldoutButton)]
|
||||
private void BuildNormalPackage()
|
||||
{
|
||||
|
||||
StreamingAssetsFilter.KeepFiles = new[]
|
||||
{
|
||||
$"{YooAssetSettingsData.GetDefaultYooFolderName()}/{selectedPackageName}"
|
||||
};
|
||||
StartBuild(PLayerMode.LOCAL_PLAYMODE);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
public class StreamingAssetsFilter : IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
{
|
||||
// 需要保留的文件/文件夹(相对于 StreamingAssets 的路径)
|
||||
public static string[] KeepFiles;
|
||||
|
||||
private string streamingAssetsPath;
|
||||
private string tempBackupPath;
|
||||
public int callbackOrder => 0; // 执行优先级
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
if (report.summary.platform != BuildTarget.Android) return;
|
||||
|
||||
streamingAssetsPath = Application.dataPath + "/StreamingAssets";
|
||||
tempBackupPath = Application.dataPath + "/../Temp/StreamingAssets_Backup";
|
||||
|
||||
if (!Directory.Exists(streamingAssetsPath)) return;
|
||||
|
||||
// 创建临时目录
|
||||
Directory.CreateDirectory(tempBackupPath);
|
||||
|
||||
// 获取所有文件
|
||||
var allFiles = Directory.GetFiles(streamingAssetsPath, "*", SearchOption.AllDirectories);
|
||||
|
||||
foreach (var file in allFiles)
|
||||
{
|
||||
string relativePath = file.Replace(streamingAssetsPath + Path.DirectorySeparatorChar, "")
|
||||
.Replace(streamingAssetsPath, "");
|
||||
|
||||
// 检查是否需要保留
|
||||
if (!ShouldKeep(relativePath))
|
||||
{
|
||||
// 移动到临时目录
|
||||
string backupPath = Path.Combine(tempBackupPath, relativePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(backupPath));
|
||||
File.Move(file, backupPath);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"[StreamingAssetsFilter] 已过滤,保留 {KeepFiles.Length} 项,其余已移至临时目录");
|
||||
}
|
||||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
if (report.summary.platform != BuildTarget.Android) return;
|
||||
|
||||
if (!Directory.Exists(tempBackupPath)) return;
|
||||
|
||||
// 恢复所有文件
|
||||
var backupFiles = Directory.GetFiles(tempBackupPath, "*", SearchOption.AllDirectories);
|
||||
|
||||
foreach (var file in backupFiles)
|
||||
{
|
||||
string relativePath = file.Replace(tempBackupPath + Path.DirectorySeparatorChar, "")
|
||||
.Replace(tempBackupPath, "");
|
||||
string originalPath = Path.Combine(streamingAssetsPath, relativePath);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(originalPath));
|
||||
File.Move(file, originalPath);
|
||||
}
|
||||
|
||||
// 删除临时目录
|
||||
Directory.Delete(tempBackupPath, true);
|
||||
|
||||
Debug.Log("[StreamingAssetsFilter] 已恢复所有文件到 StreamingAssets");
|
||||
}
|
||||
|
||||
private bool ShouldKeep(string relativePath)
|
||||
{
|
||||
string normalizedPath = relativePath.Replace('\\', '/');
|
||||
|
||||
foreach (var keep in KeepFiles)
|
||||
{
|
||||
string normalizedKeep = keep.Replace('\\', '/');
|
||||
|
||||
// 检查是否是文件夹或匹配文件
|
||||
if (normalizedPath.StartsWith(normalizedKeep, System.StringComparison.OrdinalIgnoreCase) ||
|
||||
normalizedKeep.StartsWith(normalizedPath, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9622c6696be77ae4085248147d7e9733
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.tools",
|
||||
"version": "1.3.21",
|
||||
"version": "1.3.22",
|
||||
"displayName": "00.StaryEvo.Tools",
|
||||
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
||||
"unity": "2021.3",
|
||||
|
||||
Reference in New Issue
Block a user