2025-03-28 09:37:20 +08:00
|
|
|
|
using System;
|
2024-12-23 13:43:20 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2025-03-28 09:37:20 +08:00
|
|
|
|
using UnityEditor;
|
2024-12-23 13:43:20 +08:00
|
|
|
|
using UnityEditor.Build;
|
|
|
|
|
|
using UnityEditor.Build.Reporting;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class VirtualFPostProcess : IPostprocessBuildWithReport
|
|
|
|
|
|
{
|
|
|
|
|
|
public int callbackOrder => 0;
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPostprocessBuild(BuildReport report)
|
|
|
|
|
|
{
|
|
|
|
|
|
string projectPath = Application.dataPath;
|
|
|
|
|
|
string dataFolderPath = Path.Combine(projectPath, "../Data");
|
2025-03-25 17:34:51 +08:00
|
|
|
|
string buildOutputPath = GetValidBuildPath(report);
|
2024-12-23 13:43:20 +08:00
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(dataFolderPath))
|
|
|
|
|
|
{
|
2025-03-25 17:34:51 +08:00
|
|
|
|
// Ŀ<><C4BF>Ŀ¼ǿ<C2BC><C7BF>Сд
|
2025-03-28 08:48:11 +08:00
|
|
|
|
string targetDataPath = Path.Combine(buildOutputPath, "Data");
|
2025-03-25 17:34:51 +08:00
|
|
|
|
CopyDirectoryWithLowerCaseNames(dataFolderPath, targetDataPath);
|
|
|
|
|
|
Debug.Log($"<22><><EFBFBD><EFBFBD>Ŀ¼<C4BF>Ѹ<EFBFBD><D1B8>Ƶ<EFBFBD>: {targetDataPath}");
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-25 17:34:51 +08:00
|
|
|
|
Debug.LogWarning("δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ŀ¼: " + dataFolderPath);
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
2025-03-28 09:37:20 +08:00
|
|
|
|
DeletAssetBundle(buildOutputPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ǰƽ̨<C6BD><CCA8><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void DeletAssetBundle(string buildOutPutPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL)
|
|
|
|
|
|
{
|
|
|
|
|
|
string path = Path.Combine(buildOutPutPath, "StreamingAssets", "AssetBundles");
|
|
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] allDirectories = Directory.GetDirectories(path);
|
|
|
|
|
|
foreach (string dir in allDirectories)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dirName = Path.GetFileName(dir);
|
|
|
|
|
|
if (!dirName.Equals("WebGL", StringComparison.OrdinalIgnoreCase)) // <20><><EFBFBD>Դ<EFBFBD>Сд
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.Delete(dir, true);
|
|
|
|
|
|
Debug.Log($"Deleted directory: {dir}");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"Failed to delete {dir}: {e.Message}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"Directory not found: {path}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows|| EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64)
|
|
|
|
|
|
{
|
|
|
|
|
|
string path = Path.Combine(buildOutPutPath, "VirtualFramwork_Data", "StreamingAssets", "AssetBundles");
|
|
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] allDirectories = Directory.GetDirectories(path);
|
|
|
|
|
|
foreach (string dir in allDirectories)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dirName = Path.GetFileName(dir);
|
|
|
|
|
|
if (!dirName.Equals("Windows", StringComparison.OrdinalIgnoreCase)) // <20><><EFBFBD>Դ<EFBFBD>Сд
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.Delete(dir, true);
|
|
|
|
|
|
Debug.Log($"Deleted directory: {dir}");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"Failed to delete {dir}: {e.Message}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"Directory not found: {path}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-25 17:34:51 +08:00
|
|
|
|
private string GetValidBuildPath(BuildReport report)
|
2024-12-23 13:43:20 +08:00
|
|
|
|
{
|
2025-03-25 17:34:51 +08:00
|
|
|
|
string path = report.summary.outputPath;
|
|
|
|
|
|
if (path.Contains(".exe"))
|
2024-12-23 13:43:20 +08:00
|
|
|
|
{
|
2025-03-25 17:34:51 +08:00
|
|
|
|
return Path.GetDirectoryName(path);
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
2025-03-25 17:34:51 +08:00
|
|
|
|
return path;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CopyDirectoryWithLowerCaseNames(string sourceDir, string targetDir)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>СдĿ<D0B4><C4BF>Ŀ¼
|
2025-03-28 08:48:11 +08:00
|
|
|
|
//var lowerTargetDir = ConvertToLowerPath(targetDir);
|
|
|
|
|
|
Directory.CreateDirectory(targetDir);
|
2024-12-23 13:43:20 +08:00
|
|
|
|
|
2025-03-25 17:34:51 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Сдת<D0B4><D7AA><EFBFBD><EFBFBD>
|
|
|
|
|
|
foreach (var file in Directory.GetFiles(sourceDir))
|
2024-12-23 13:43:20 +08:00
|
|
|
|
{
|
2025-03-25 17:34:51 +08:00
|
|
|
|
string fileName = Path.GetFileName(file);
|
2025-03-28 08:48:11 +08:00
|
|
|
|
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Сдת<D0B4><D7AA>
|
|
|
|
|
|
//string lowerName = ConvertToLowerPath(fileName);
|
|
|
|
|
|
File.Copy(file, Path.Combine(targetDir, fileName), true);
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-25 17:34:51 +08:00
|
|
|
|
// <20>ݹ鴦<DDB9><E9B4A6><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>Сдת<D0B4><D7AA><EFBFBD><EFBFBD>
|
|
|
|
|
|
foreach (var dir in Directory.GetDirectories(sourceDir))
|
|
|
|
|
|
{
|
|
|
|
|
|
string dirName = Path.GetFileName(dir);
|
2025-03-28 08:48:11 +08:00
|
|
|
|
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Сдת<D0B4><D7AA>
|
|
|
|
|
|
//string lowerDirName = ConvertToLowerPath(dirName);
|
|
|
|
|
|
CopyDirectoryWithLowerCaseNames(dir, Path.Combine(targetDir, dirName));
|
2025-03-25 17:34:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>Ӣ<EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>·<EFBFBD><C2B7>תСд
|
|
|
|
|
|
private string ConvertToLowerPath(string input)
|
|
|
|
|
|
{
|
|
|
|
|
|
char[] chars = input.ToCharArray();
|
|
|
|
|
|
for (int i = 0; i < chars.Length; i++)
|
2024-12-23 13:43:20 +08:00
|
|
|
|
{
|
2025-03-25 17:34:51 +08:00
|
|
|
|
// ֻ<><D6BB><EFBFBD><EFBFBD>ASCII<49><49>ĸ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>Unicode<64>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2>䣩
|
|
|
|
|
|
if (chars[i] >= 'A' && chars[i] <= 'Z')
|
|
|
|
|
|
{
|
|
|
|
|
|
chars[i] = (char)(chars[i] | 0x20); // <20><><EFBFBD><EFBFBD>תСд
|
|
|
|
|
|
}
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
2025-03-25 17:34:51 +08:00
|
|
|
|
return new string(chars);
|
2024-12-23 13:43:20 +08:00
|
|
|
|
}
|
2025-03-25 17:34:51 +08:00
|
|
|
|
}
|