// 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 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"); // 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"); // if (!Directory.Exists(sourceImageFolder)) // { // Debug.LogError("Image folder does not exist: " + sourceImageFolder); // return; // } // // 确保 Images.xcassets 文件夹存在 // if (!Directory.Exists(destinationAssetsFolder)) // { // Directory.CreateDirectory(destinationAssetsFolder); // } // // 遍历 Plugins/iOS 文件夹中的所有 PNG 文件 // string[] pngFiles = Directory.GetFiles(sourceImageFolder, "*.png"); // foreach (var file in pngFiles) // { // // 获取文件名 // string fileName = Path.GetFileName(file); // // 确保文件被添加到 xcassets 中 // string destinationFilePath = Path.Combine(destinationAssetsFolder, fileName); // // 将文件复制到 xcassets 目录 // if (!File.Exists(destinationFilePath)) // { // File.Copy(file, destinationFilePath); // Debug.Log("Added " + fileName + " to " + destinationAssetsFolder); // } // else // { // Debug.LogWarning(fileName + " already exists in the destination."); // } // } // } // }