增加打包后Data文件自动复制到输出目录
This commit is contained in:
parent
89231a48d8
commit
764db1059f
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Progress;
|
||||
|
||||
namespace QFramework
|
||||
{
|
||||
|
||||
62
Assets/Scripts/Editor/VirtualFPostProcess.cs
Normal file
62
Assets/Scripts/Editor/VirtualFPostProcess.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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;
|
||||
|
||||
// 获取Data文件夹的路径
|
||||
string dataFolderPath = Path.Combine(projectPath, "../Data");
|
||||
|
||||
// 获取打包后的输出目录
|
||||
string buildOutputPath = report.summary.outputPath;
|
||||
|
||||
// 检查Data文件夹是否存在
|
||||
if (Directory.Exists(dataFolderPath))
|
||||
{
|
||||
// 将Data文件夹复制到打包后的目标目录
|
||||
string targetDataPath = Path.Combine(buildOutputPath, "Data");
|
||||
CopyDirectory(dataFolderPath, targetDataPath);
|
||||
Debug.Log($"Data folder copied to build output directory: {targetDataPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Data folder not found at: " + dataFolderPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 递归复制文件夹的辅助方法,覆盖已有文件和文件夹
|
||||
private void CopyDirectory(string sourceDir, string destinationDir)
|
||||
{
|
||||
// 确保目标目录存在
|
||||
if (!Directory.Exists(destinationDir))
|
||||
{
|
||||
Directory.CreateDirectory(destinationDir);
|
||||
}
|
||||
|
||||
// 遍历源目录中的文件
|
||||
foreach (string file in Directory.GetFiles(sourceDir))
|
||||
{
|
||||
string destFile = Path.Combine(destinationDir, Path.GetFileName(file));
|
||||
File.Copy(file, destFile, true); // 覆盖已有文件
|
||||
}
|
||||
|
||||
// 遍历源目录中的子文件夹
|
||||
foreach (string subDir in Directory.GetDirectories(sourceDir))
|
||||
{
|
||||
string destSubDir = Path.Combine(destinationDir, Path.GetFileName(subDir));
|
||||
CopyDirectory(subDir, destSubDir); // 递归复制子文件夹
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/VirtualFPostProcess.cs.meta
Normal file
11
Assets/Scripts/Editor/VirtualFPostProcess.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f59102734fe9cb4f841df4c5037930c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user