Files
BingoGrassland/Assets/Editor/PostProcessBuild.cs
T

57 lines
2.0 KiB
C#
Raw Normal View History

2026-04-20 13:49:36 +08:00
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.IO;
using UnityEditor.Build;
2026-06-09 15:16:52 +08:00
using UnityEditor.Build.Reporting;
2026-04-20 13:49:36 +08:00
using UnityEngine;
public class PostProcessBuild : IPostprocessBuildWithReport
{
public int callbackOrder => 1;
2026-06-09 15:16:52 +08:00
public void OnPostprocessBuild(BuildReport report)
2026-04-20 13:49:36 +08:00
{
2026-06-09 15:16:52 +08:00
// 检查是否为 iOS 平台构建
2026-05-11 10:32:47 +08:00
if (report.summary.platform == BuildTarget.iOS)
{
string projectPath = report.summary.outputPath;
2026-06-09 15:16:52 +08:00
string projFilePath = PBXProject.GetPBXProjectPath(projectPath);
PBXProject proj = new PBXProject();
proj.ReadFromFile(projFilePath);
string targetGuid = proj.GetUnityFrameworkTargetGuid();
// 示例:复制自定义 UnityAppController.mm
string customControllerPath = "Assets/Editor/UnityAppController.mm";
2026-05-11 10:32:47 +08:00
string destinationPath = Path.Combine(projectPath, "Classes/UnityAppController.mm");
2026-04-20 13:49:36 +08:00
2026-05-11 10:32:47 +08:00
if (File.Exists(customControllerPath))
{
File.Copy(customControllerPath, destinationPath, overwrite: true);
Debug.Log("Custom UnityAppController.mm has been copied to Xcode project.");
}
else
{
Debug.LogError("Custom UnityAppController.mm file not found at " + customControllerPath);
}
2026-06-09 15:16:52 +08:00
// 示例:添加插件文件时避免重复
string pluginPath = Path.Combine(projectPath, "Libraries/Plugins/iOS/pluginIOs.mm");
if (!proj.ContainsFileByRealPath(pluginPath))
{
string fileGuid = proj.AddFile(pluginPath, "Libraries/Plugins/iOS/pluginIOs.mm", PBXSourceTree.Source);
proj.AddFileToBuild(targetGuid, fileGuid);
Debug.Log("pluginIOs.mm added to UnityFramework target.");
}
else
{
Debug.Log("pluginIOs.mm already exists, skip adding.");
}
File.WriteAllText(projFilePath, proj.WriteToString());
2026-05-11 10:32:47 +08:00
}
2026-04-20 13:49:36 +08:00
}
2026-06-09 15:16:52 +08:00
}