提交
This commit is contained in:
@@ -1,56 +1,87 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using System.IO;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
// using UnityEditor;
|
||||
// using UnityEditor.Callbacks;
|
||||
// using UnityEditor.iOS.Xcode;
|
||||
// using System.IO;
|
||||
// using UnityEditor.Build;
|
||||
// using UnityEngine;
|
||||
|
||||
public class PostProcessBuild : IPostprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder => 1;
|
||||
// public class PostProcessBuild : IPostprocessBuildWithReport
|
||||
// {
|
||||
// public int callbackOrder => 1;
|
||||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
// 检查是否为 iOS 平台构建
|
||||
if (report.summary.platform == BuildTarget.iOS)
|
||||
{
|
||||
string projectPath = report.summary.outputPath;
|
||||
string projFilePath = PBXProject.GetPBXProjectPath(projectPath);
|
||||
// public void OnPostprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
// {
|
||||
// // 检查是否为 iOS 平台构建
|
||||
// if (report.summary.platform == BuildTarget.iOS)
|
||||
// {
|
||||
|
||||
// string projectPath = report.summary.outputPath;
|
||||
// string customControllerPath = "Assets/Editor/UnityAppController.mm"; // 自定义文件的路径
|
||||
// string destinationPath = Path.Combine(projectPath, "Classes/UnityAppController.mm");
|
||||
|
||||
PBXProject proj = new PBXProject();
|
||||
proj.ReadFromFile(projFilePath);
|
||||
// if (File.Exists(customControllerPath))
|
||||
// {
|
||||
// // 复制文件到 Xcode 项目中
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 这是一个 PostProcessBuild 脚本,在 Unity 构建完成后自动执行
|
||||
// [PostProcessBuild]
|
||||
// public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
|
||||
// {
|
||||
// // 仅对 iOS 构建进行处理
|
||||
// if (buildTarget == BuildTarget.iOS)
|
||||
// {
|
||||
// AddImagesToXcodeProject(pathToBuiltProject);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 将 PNG 文件添加到 Xcode 项目中的 Images.xcassets
|
||||
// private static void AddImagesToXcodeProject(string xcodeProjectPath)
|
||||
// {
|
||||
// string sourceImageFolder = "Assets/Plugins/iOS/"; // 你要打包的 PNG 文件所在文件夹
|
||||
// string destinationAssetsFolder = Path.Combine(xcodeProjectPath, "Images.xcassets");
|
||||
|
||||
string targetGuid = proj.GetUnityFrameworkTargetGuid();
|
||||
// if (!Directory.Exists(sourceImageFolder))
|
||||
// {
|
||||
// Debug.LogError("Image folder does not exist: " + sourceImageFolder);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 示例:复制自定义 UnityAppController.mm
|
||||
string customControllerPath = "Assets/Editor/UnityAppController.mm";
|
||||
string destinationPath = Path.Combine(projectPath, "Classes/UnityAppController.mm");
|
||||
// // 确保 Images.xcassets 文件夹存在
|
||||
// if (!Directory.Exists(destinationAssetsFolder))
|
||||
// {
|
||||
// Directory.CreateDirectory(destinationAssetsFolder);
|
||||
// }
|
||||
|
||||
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);
|
||||
}
|
||||
// // 遍历 Plugins/iOS 文件夹中的所有 PNG 文件
|
||||
// string[] pngFiles = Directory.GetFiles(sourceImageFolder, "*.png");
|
||||
|
||||
// 示例:添加插件文件时避免重复
|
||||
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.");
|
||||
}
|
||||
// foreach (var file in pngFiles)
|
||||
// {
|
||||
// // 获取文件名
|
||||
// string fileName = Path.GetFileName(file);
|
||||
|
||||
// // 确保文件被添加到 xcassets 中
|
||||
// string destinationFilePath = Path.Combine(destinationAssetsFolder, fileName);
|
||||
|
||||
File.WriteAllText(projFilePath, proj.WriteToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
// // 将文件复制到 xcassets 目录
|
||||
// if (!File.Exists(destinationFilePath))
|
||||
// {
|
||||
// File.Copy(file, destinationFilePath);
|
||||
// Debug.Log("Added " + fileName + " to " + destinationAssetsFolder);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogWarning(fileName + " already exists in the destination.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user