提交修改
This commit is contained in:
co-authored by
changyunjia
parent
d4442fc21f
commit
3ac4fe0cd0
@@ -3,24 +3,32 @@ using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using System.IO;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
public class PostProcessBuild : IPostprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder => 1;
|
||||
|
||||
public void OnPostprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
//检查是否为 iOS 平台构建
|
||||
// 检查是否为 iOS 平台构建
|
||||
if (report.summary.platform == BuildTarget.iOS)
|
||||
{
|
||||
string projectPath = report.summary.outputPath;
|
||||
string customControllerPath = "Assets/Editor/UnityAppController.mm"; // 自定义文件的路径
|
||||
string projFilePath = PBXProject.GetPBXProjectPath(projectPath);
|
||||
|
||||
PBXProject proj = new PBXProject();
|
||||
proj.ReadFromFile(projFilePath);
|
||||
|
||||
string targetGuid = proj.GetUnityFrameworkTargetGuid();
|
||||
|
||||
// 示例:复制自定义 UnityAppController.mm
|
||||
string customControllerPath = "Assets/Editor/UnityAppController.mm";
|
||||
string destinationPath = Path.Combine(projectPath, "Classes/UnityAppController.mm");
|
||||
|
||||
if (File.Exists(customControllerPath))
|
||||
{
|
||||
// 复制文件到 Xcode 项目中
|
||||
File.Copy(customControllerPath, destinationPath, overwrite: true);
|
||||
Debug.Log("Custom UnityAppController.mm has been copied to Xcode project.");
|
||||
}
|
||||
@@ -28,6 +36,21 @@ public class PostProcessBuild : IPostprocessBuildWithReport
|
||||
{
|
||||
Debug.LogError("Custom UnityAppController.mm file not found at " + customControllerPath);
|
||||
}
|
||||
|
||||
// 示例:添加插件文件时避免重复
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user