| | |
| | | using DG.Tweening.Plugins.Core.PathCore; |
| | | using System; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using UnityEditor; |
| | |
| | | |
| | | public class XCodeProjectMod |
| | | { |
| | | private const string CODE_SIGN_DEVELOPER = ""; |
| | | private const string CODE_SIGN_DISTRIBUTION = ""; |
| | | private const string PROVISIONING_DEVELOPER = ""; |
| | | private const string PROVISIONING_DISTRIBUTION = ""; |
| | | private const string TEAM = ""; |
| | | // Channel 插件存放目录(BuildIpa 前由 ClientPackage.BuildIpa 从 _sdkPath 拷贝到 Assets/Plugins/iOS/Channel) |
| | | private static readonly string iOSPluginPath = Application.dataPath + "/Plugins/iOS/Channel"; |
| | | |
| | | [UnityEditor.Callbacks.PostProcessBuild(999)] |
| | | public static void OnPostprocessBuild(BuildTarget buildTarget, string path) |
| | |
| | | BuildPlist(path); |
| | | ModifyFile(path); |
| | | |
| | | |
| | | |
| | | // 生成 .xcworkspace 结构,方便开发者在 Xcode 中手动 Add Package Dependency |
| | | // SPM 依赖必须通过 .xcworkspace 管理,.xcodeproj 单独无法正确 resolve |
| | | // 开发者需在 Xcode 中手动 File → Add Package Dependency 添加以下仓库,并选择所需的产品包: |
| | | // - Firebase: https://github.com/firebase/firebase-ios-sdk |
| | | // - Facebook: https://github.com/facebook/facebook-ios-sdk |
| | | // - Adjust: https://github.com/adjust/ios_sdk |
| | | CreateWorkspaceWithSPM(path); |
| | | } |
| | | |
| | | static void DoPBXProject(string path) |
| | |
| | | string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName()); |
| | | string fwTargetGUID = project.TargetGuidByName("UnityFramework"); |
| | | |
| | | // BuildSetting里的相关设置 |
| | | project.SetBuildProperty(project.ProjectGuid(), "ENABLE_BITCODE", "NO"); |
| | | project.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO"); |
| | | project.SetBuildProperty(targetGUID, "DEVELOPMENT_TEAM", TEAM); |
| | | |
| | | // 1.1 环境要求:iOS 13.0 及以上 |
| | | project.SetBuildProperty(targetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0"); |
| | | project.SetBuildProperty(fwTargetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0"); |
| | |
| | | project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRDebugEnabled"); |
| | | project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsVerboseLoggingEnabled"); |
| | | |
| | | //wkwebview |
| | | // WebKit(文档要求) |
| | | project.AddFrameworkToProject(fwTargetGUID, "WebKit.framework", true); |
| | | |
| | | project.AddFrameworkToProject(fwTargetGUID, "SystemConfiguration.framework", true); |
| | | project.AddFrameworkToProject(fwTargetGUID, "Security.framework", true); |
| | | project.AddFrameworkToProject(fwTargetGUID, "JavaScriptCore.framework", true); |
| | | project.AddFrameworkToProject(fwTargetGUID, "Accelerate.framework", true); |
| | | |
| | | // fimpfunSDK.framework 添加到工程并设置为 Embed & Sign |
| | | string fimpfunFrameworkPath = path + "/Frameworks/fimpfunSDK.framework"; |
| | | if (Directory.Exists(fimpfunFrameworkPath)) |
| | | { |
| | | string fileGuid = project.AddFile(fimpfunFrameworkPath, "Frameworks/fimpfunSDK.framework", PBXSourceTree.Source); |
| | | project.AddFileToBuild(fwTargetGUID, fileGuid); |
| | | // Embed & Sign: 添加到 main target 的 Embed Frameworks |
| | | project.AddFileToBuild(targetGUID, fileGuid); |
| | | } |
| | | |
| | | // 处理 库文件 |
| | | project.AddFileToBuild(fwTargetGUID, project.AddFile("/usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk)); |
| | | project.AddFileToBuild(fwTargetGUID, project.AddFile("/usr/lib/libsqlite3.tbd", "Frameworks/libsqlite3.tbd", PBXSourceTree.Sdk)); |
| | | project.AddFileToBuild(fwTargetGUID, project.AddFile("/usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk)); |
| | | project.AddFileToBuild(fwTargetGUID, project.AddFile("/usr/lib/libiconv.tbd", "Frameworks/libiconv.tbd", PBXSourceTree.Sdk)); |
| | | project.AddFileToBuild(fwTargetGUID, project.AddFile("/usr/lib/libresolv.tbd", "Frameworks/libresolv.tbd", PBXSourceTree.Sdk)); |
| | | |
| | | //UnityFramework |
| | | project.AddBuildProperty(fwTargetGUID, "OTHER_LDFLAGS", "-ObjC"); |
| | | |
| | | // 添加 GoogleService-Info.plist 和 funshine.plist 到工程 |
| | | string iosPluginPath = path + "/Libraries/Plugins/iOS/Channel"; |
| | | string[] configPlists = { "GoogleService-Info.plist", "funshine.plist" }; |
| | | foreach (var plistName in configPlists) |
| | | { |
| | | string srcPath = iosPluginPath + "/" + plistName; |
| | | string srcPath = iOSPluginPath + "/" + plistName; |
| | | if (File.Exists(srcPath)) |
| | | { |
| | | string destPath = path + "/" + plistName; |
| | | File.Copy(srcPath, destPath, true); |
| | | string fileGuid = project.AddFile(plistName, plistName, PBXSourceTree.Source); |
| | | project.AddFileToBuild(targetGUID, fileGuid); |
| | | } |
| | | else |
| | | { |
| | | Debug.LogWarning("[XCodeProjectMod] " + plistName + " 未找到: " + srcPath); |
| | | } |
| | | } |
| | | |
| | |
| | | project.AddFrameworkToProject(fwTargetGUID, "StoreKit.framework", true); |
| | | |
| | | File.WriteAllText(_projectPath, project.WriteToString()); |
| | | |
| | | // SPM 依赖:Firebase / Facebook / Adjust(Unity PBXProject API 不支持 SPM,需直接操作 pbxproj) |
| | | AddSwiftPackageDependencies(_projectPath, targetGUID); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 向 pbxproj 注入 Swift Package Manager 依赖(XCRemoteSwiftPackageReference + XCSwiftPackageProductDependency) |
| | | /// 版本号需根据 demo 或实际需求调整 |
| | | /// 生成 Unity-iPhone.xcworkspace 结构,仅包含 contents.xcworkspacedata。 |
| | | /// SPM 依赖由开发者在 Xcode 中手动 File → Add Package Dependency 添加并选择所需产品包: |
| | | /// - Firebase: https://github.com/firebase/firebase-ios-sdk |
| | | /// - Facebook: https://github.com/facebook/facebook-ios-sdk |
| | | /// - Adjust: https://github.com/adjust/ios_sdk |
| | | /// Package.resolved 由 Xcode 在 resolve 后自动生成,代码不做处理。 |
| | | /// </summary> |
| | | private static void AddSwiftPackageDependencies(string projectPath, string targetGUID) |
| | | private static void CreateWorkspaceWithSPM(string projectPath) |
| | | { |
| | | string content = File.ReadAllText(projectPath); |
| | | string workspacePath = projectPath + "/Unity-iPhone.xcworkspace"; |
| | | string xcodeprojAbsPath = projectPath + "/Unity-iPhone.xcodeproj"; |
| | | |
| | | // ---- 1. 生成 GUID(使用确定性命名避免重复注入)---- |
| | | string firebasePkgRefGuid = "FIMPSPM00001"; // XCRemoteSwiftPackageReference |
| | | string fbPkgRefGuid = "FIMPSPM00002"; |
| | | string adjustPkgRefGuid = "FIMPSPM00003"; |
| | | |
| | | string firebaseAnalyticsProdGuid = "FIMPSPM00011"; // XCSwiftPackageProductDependency (FirebaseAnalytics) |
| | | string firebaseCoreProdGuid = "FIMPSPM00012"; // XCSwiftPackageProductDependency (FirebaseCore) |
| | | string fbCoreKitProdGuid = "FIMPSPM00021"; // XCSwiftPackageProductDependency (FacebookCore) |
| | | string fbLoginKitProdGuid = "FIMPSPM00022"; // XCSwiftPackageProductDependency (FacebookLogin) |
| | | string adjustProdGuid = "FIMPSPM00031"; // XCSwiftPackageProductDependency (Adjust) |
| | | |
| | | // 如果已经注入过,跳过 |
| | | if (content.Contains(firebasePkgRefGuid)) |
| | | if (!Directory.Exists(xcodeprojAbsPath)) |
| | | { |
| | | UnityEngine.Debug.Log("[XCodeProjectMod] SPM dependencies already injected, skipping."); |
| | | Debug.LogWarning("[XCodeProjectMod] xcodeproj not found, skip creating workspace: " + xcodeprojAbsPath); |
| | | return; |
| | | } |
| | | |
| | | // ---- 2. XCRemoteSwiftPackageReference section ---- |
| | | string pkgRefSection = "/* XCRemoteSwiftPackageReference section */"; |
| | | string pkgRefEntries = string.Format( |
| | | "\t\t{{0}} /* XCRemoteSwiftPackageReference \"Firebase\" */ = {{isa = XCRemoteSwiftPackageReference; repositoryURL = \"https://github.com/firebase/firebase-ios-sdk\"; requirement = {{kind = upToNextMajorVersion; minimumVersion = 10.24.0; }}; }};\n" + |
| | | "\t\t{{1}} /* XCRemoteSwiftPackageReference \"Facebook\" */ = {{isa = XCRemoteSwiftPackageReference; repositoryURL = \"https://github.com/facebook/facebook-ios-sdk\"; requirement = {{kind = upToNextMajorVersion; minimumVersion = 17.0.0; }}; }};\n" + |
| | | "\t\t{{2}} /* XCRemoteSwiftPackageReference \"Adjust\" */ = {{isa = XCRemoteSwiftPackageReference; repositoryURL = \"https://github.com/adjust/ios_sdk\"; requirement = {{kind = upToNextMajorVersion; minimumVersion = 4.38.2; }}; }};\n", |
| | | firebasePkgRefGuid, fbPkgRefGuid, adjustPkgRefGuid); |
| | | content = content.Replace(pkgRefSection, pkgRefSection + "\n" + pkgRefEntries); |
| | | Directory.CreateDirectory(workspacePath); |
| | | |
| | | // ---- 3. XCSwiftPackageProductDependency section ---- |
| | | string pkgProdSection = "/* XCSwiftPackageProductDependency section */"; |
| | | string pkgProdEntries = string.Format( |
| | | "\t\t{{0}} /* FirebaseAnalytics */ = {{isa = XCSwiftPackageProductDependency; package = {{1}} /* XCRemoteSwiftPackageReference \"Firebase\" */; productName = FirebaseAnalytics; }};\n" + |
| | | "\t\t{{2}} /* FirebaseCore */ = {{isa = XCSwiftPackageProductDependency; package = {{1}} /* XCRemoteSwiftPackageReference \"Firebase\" */; productName = FirebaseCore; }};\n" + |
| | | "\t\t{{3}} /* FacebookCore */ = {{isa = XCSwiftPackageProductDependency; package = {{4}} /* XCRemoteSwiftPackageReference \"Facebook\" */; productName = FacebookCore; }};\n" + |
| | | "\t\t{{5}} /* FacebookLogin */ = {{isa = XCSwiftPackageProductDependency; package = {{4}} /* XCRemoteSwiftPackageReference \"Facebook\" */; productName = FacebookLogin; }};\n" + |
| | | "\t\t{{6}} /* Adjust */ = {{isa = XCSwiftPackageProductDependency; package = {{7}} /* XCRemoteSwiftPackageReference \"Adjust\" */; productName = Adjust; }};\n", |
| | | firebaseAnalyticsProdGuid, firebasePkgRefGuid, |
| | | firebaseCoreProdGuid, |
| | | fbCoreKitProdGuid, fbPkgRefGuid, |
| | | fbLoginKitProdGuid, |
| | | adjustProdGuid, adjustPkgRefGuid); |
| | | content = content.Replace(pkgProdSection, pkgProdSection + "\n" + pkgProdEntries); |
| | | string contentsXml = @"<?xml version=""1.0"" encoding=""UTF-8""?> |
| | | <Workspace |
| | | version = ""1.0""> |
| | | <FileRef |
| | | location = ""group:Unity-iPhone.xcodeproj""> |
| | | </FileRef> |
| | | </Workspace> |
| | | "; |
| | | File.WriteAllText(workspacePath + "/contents.xcworkspacedata", contentsXml); |
| | | |
| | | // ---- 4. PBXNativeTarget packageProductDependencies ---- |
| | | // 在 target 的 packageProductDependencies 中添加引用 |
| | | string pkgProdDeps = string.Format( |
| | | "\t\t\t\tpackageProductDependencies = (\n" + |
| | | "\t\t\t\t\t{0} /* FirebaseAnalytics */,\n" + |
| | | "\t\t\t\t\t{1} /* FirebaseCore */,\n" + |
| | | "\t\t\t\t\t{2} /* FacebookCore */,\n" + |
| | | "\t\t\t\t\t{3} /* FacebookLogin */,\n" + |
| | | "\t\t\t\t\t{4} /* Adjust */,\n" + |
| | | "\t\t\t\t);", |
| | | firebaseAnalyticsProdGuid, firebaseCoreProdGuid, |
| | | fbCoreKitProdGuid, fbLoginKitProdGuid, |
| | | adjustProdGuid); |
| | | |
| | | // 找到 main target 的 buildPhases 结束位置附近,插入 packageProductDependencies |
| | | // 在 target 的 buildPhases 数组结束后添加 |
| | | string targetMarker = targetGUID + " /* " + PBXProject.GetUnityTargetName() + " */"; |
| | | int targetStart = content.IndexOf(targetMarker); |
| | | if (targetStart >= 0) |
| | | { |
| | | // 找到这个 target dict 中的 buildPhases 结束的 ); |
| | | int buildPhasesEnd = FindClosingParen(content, targetStart, "buildPhases"); |
| | | if (buildPhasesEnd >= 0) |
| | | { |
| | | content = content.Insert(buildPhasesEnd, "\n" + pkgProdDeps); |
| | | } |
| | | } |
| | | |
| | | // ---- 5. PBXProject packageReferences ---- |
| | | // 在 project 的 packageReferences 中添加引用 |
| | | string pkgRefs = string.Format( |
| | | "\t\t\t\tpackageReferences = (\n" + |
| | | "\t\t\t\t\t{{0}} /* XCRemoteSwiftPackageReference \"Firebase\" */,\n" + |
| | | "\t\t\t\t\t{{1}} /* XCRemoteSwiftPackageReference \"Facebook\" */,\n" + |
| | | "\t\t\t\t\t{{2}} /* XCRemoteSwiftPackageReference \"Adjust\" */,\n" + |
| | | "\t\t\t\t);", |
| | | firebasePkgRefGuid, fbPkgRefGuid, adjustPkgRefGuid); |
| | | |
| | | // 在 PBXProject 的 mainGroup 后面添加 packageReferences |
| | | int projectSection = content.IndexOf("/* PBXProject */ = {"); |
| | | if (projectSection >= 0) |
| | | { |
| | | // 找到 attributes 区块 |
| | | int attrsPos = content.IndexOf("attributes = {", projectSection); |
| | | if (attrsPos >= 0) |
| | | { |
| | | // 在 attributes 闭括号前插入 |
| | | int attrsClose = content.IndexOf("};", attrsPos + 14); |
| | | if (attrsClose >= 0) |
| | | { |
| | | content = content.Insert(attrsClose, "\n" + pkgRefs); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ---- 6. PBXFrameworksBuildPhase ---- |
| | | // 将 SPM product 加到 Frameworks build phase |
| | | string frameworkBuildPhaseMarker = "/* Frameworks */ = {"; |
| | | int fwPhaseIdx = content.IndexOf(frameworkBuildPhaseMarker); |
| | | if (fwPhaseIdx >= 0) |
| | | { |
| | | int filesStart = content.IndexOf("files = (", fwPhaseIdx); |
| | | if (filesStart >= 0) |
| | | { |
| | | int filesEnd = content.IndexOf(");", filesStart + 9); |
| | | if (filesEnd >= 0) |
| | | { |
| | | string fwEntries = string.Format( |
| | | "\t\t\t\t{0} /* FirebaseAnalytics in Frameworks */,\n" + |
| | | "\t\t\t\t{1} /* FirebaseCore in Frameworks */,\n" + |
| | | "\t\t\t\t{2} /* FacebookCore in Frameworks */,\n" + |
| | | "\t\t\t\t{3} /* FacebookLogin in Frameworks */,\n" + |
| | | "\t\t\t\t{4} /* Adjust in Frameworks */,\n", |
| | | firebaseAnalyticsProdGuid, firebaseCoreProdGuid, |
| | | fbCoreKitProdGuid, fbLoginKitProdGuid, |
| | | adjustProdGuid); |
| | | content = content.Insert(filesEnd, fwEntries); |
| | | } |
| | | } |
| | | } |
| | | |
| | | File.WriteAllText(projectPath, content); |
| | | UnityEngine.Debug.Log("[XCodeProjectMod] SPM dependencies (Firebase/Facebook/Adjust) injected successfully."); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 在 pbxproj 文本中,从指定 key(如 buildPhases)的数组起始位置找到其闭括号 ");" 的位置 |
| | | /// </summary> |
| | | private static int FindClosingParen(string content, int searchStart, string key) |
| | | { |
| | | int keyIdx = content.IndexOf(key + " = (", searchStart); |
| | | if (keyIdx < 0) return -1; |
| | | int openIdx = content.IndexOf("(", keyIdx); |
| | | return content.IndexOf(");", openIdx); |
| | | Debug.Log("[XCodeProjectMod] Unity-iPhone.xcworkspace created at: " + workspacePath); |
| | | Debug.Log("[XCodeProjectMod] 请在 Xcode 中打开 .xcworkspace,手动 File → Add Package Dependency 添加 SPM 仓库:"); |
| | | Debug.Log("[XCodeProjectMod] - Firebase: https://github.com/firebase/firebase-ios-sdk"); |
| | | Debug.Log("[XCodeProjectMod] - Facebook: https://github.com/facebook/facebook-ios-sdk"); |
| | | Debug.Log("[XCodeProjectMod] - Adjust: https://github.com/adjust/ios_sdk"); |
| | | } |
| | | |
| | | private static void BuildPlist(string path) |
| | |
| | | |
| | | // Facebook (funshine.plist: kFacebookAppID / kFacebookAppSecret) |
| | | _rootDict.SetString("FacebookAppID", "1445747540428317"); |
| | | _rootDict.SetString("FacebookClientToken", ""); |
| | | _rootDict.SetString("FacebookDisplayName", "Legend of the Sword Master"); |
| | | _rootDict.SetString("FacebookClientToken", "1103765897fb67ffc898e6a8ee2d9aec"); |
| | | _rootDict.SetString("FacebookDisplayName", "EZ PZ: Byte Heroes"); |
| | | |
| | | // 适配欧盟地区政策法规 - Google Analytics 默认允许 |
| | | _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE", true); |
| | |
| | | // App 名称本地化 |
| | | _rootDict.SetBoolean("Application has localized display name", true); |
| | | _rootDict.SetString("CFBundleDevelopmentRegion", "english"); |
| | | _rootDict.SetString("Localization native development region", "english"); |
| | | |
| | | PlistElementArray nsURLTypes = _rootDict.CreateArray("CFBundleURLTypes"); |
| | | var dict0 = nsURLTypes.AddDict(); |
| | |
| | | |
| | | // fimpfunSDK 生命周期 |
| | | _xclass.WriteBelow("- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options\n{", "\n [_fimpfunBridge application:app openURL:url options:options];"); |
| | | _xclass.WriteBelow("- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation\n{", "\n return [_fimpfunBridge application:application openURL:url sourceApplication:sourceApplication annotation:annotation];"); |
| | | |
| | | _xclass.WriteBelow("::printf(\"-> applicationDidBecomeActive()\\n\");", "[_fimpfunBridge applicationDidBecomeActive:application];"); |
| | | |
| | | |
| | |
| | | "@property (readonly, copy, nonatomic) FimpfunBridge* fimpfunBridge;"); |
| | | |
| | | // 3.1 适配欧盟政策:在 viewDidAppear 中调用 adaptingEUGDPR(文档要求) |
| | | var _viewController = new XClass(projectPath + "/Classes/UnityViewControllerBase.mm"); |
| | | _viewController.WriteBelow("@implementation UnityViewControllerBase", |
| | | "\n- (void)viewDidAppear:(BOOL)animated {\n [super viewDidAppear:animated];\n [GetAppController().fimpfunBridge viewDidAppear];\n}\n"); |
| | | // UnityViewControllerBase.mm 在较新 Unity 版本(如 2022.3+)中可能不存在 |
| | | string viewControllerPath = projectPath + "/Classes/UnityViewControllerBase.mm"; |
| | | if (System.IO.File.Exists(viewControllerPath)) |
| | | { |
| | | var _viewController = new XClass(viewControllerPath); |
| | | _viewController.WriteBelow("@implementation UnityViewControllerBase", |
| | | "\n- (void)viewDidAppear:(BOOL)animated {\n [super viewDidAppear:animated];\n [GetAppController().fimpfunBridge viewDidAppear];\n}\n"); |
| | | } |
| | | else |
| | | { |
| | | Debug.LogWarning("[XCodeProjectMod] UnityViewControllerBase.mm 文件不存在,跳过 viewDidAppear 注入。此 Unity 版本可能已移除该文件。"); |
| | | } |
| | | |
| | | // 创建 InfoPlist.strings(App 名称本地化) |
| | | CreateInfoPlistStrings(projectPath); |
| | |
| | | /// </summary> |
| | | private static void CreateInfoPlistStrings(string projectPath) |
| | | { |
| | | string stringsDir = projectPath + "/English.lproj"; |
| | | if (!Directory.Exists(stringsDir)) |
| | | // 英文(默认) |
| | | string enDir = projectPath + "/English.lproj"; |
| | | if (!Directory.Exists(enDir)) |
| | | { |
| | | Directory.CreateDirectory(stringsDir); |
| | | Directory.CreateDirectory(enDir); |
| | | } |
| | | string stringsPath = stringsDir + "/InfoPlist.strings"; |
| | | if (!File.Exists(stringsPath)) |
| | | string enStringsPath = enDir + "/InfoPlist.strings"; |
| | | if (!File.Exists(enStringsPath)) |
| | | { |
| | | File.WriteAllText(stringsPath, "CFBundleDisplayName = \"Legend of the Sword Master\";\n"); |
| | | File.WriteAllText(enStringsPath, "CFBundleDisplayName = \"EZ PZ\";\n"); |
| | | } |
| | | |
| | | // 中文 |
| | | string zhDir = projectPath + "/zh-Hans.lproj"; |
| | | if (!Directory.Exists(zhDir)) |
| | | { |
| | | Directory.CreateDirectory(zhDir); |
| | | } |
| | | string zhStringsPath = zhDir + "/InfoPlist.strings"; |
| | | if (!File.Exists(zhStringsPath)) |
| | | { |
| | | File.WriteAllText(zhStringsPath, "CFBundleDisplayName = \"懒人三国\";\n"); |
| | | } |
| | | |
| | | // 将 InfoPlist.strings 添加到 Xcode 工程 |
| | | string _projectPath = PBXProject.GetPBXProjectPath(projectPath); |
| | | PBXProject project = new PBXProject(); |
| | | project.ReadFromString(File.ReadAllText(_projectPath)); |
| | | string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName()); |
| | | try |
| | | { |
| | | PBXProject project = new PBXProject(); |
| | | project.ReadFromString(File.ReadAllText(_projectPath)); |
| | | string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName()); |
| | | |
| | | string relPath = "English.lproj/InfoPlist.strings"; |
| | | string fileGuid = project.AddFile(relPath, relPath, PBXSourceTree.Source); |
| | | project.AddFileToBuild(targetGUID, fileGuid); |
| | | // 英文 |
| | | string enRelPath = "English.lproj/InfoPlist.strings"; |
| | | string enFileGuid = project.AddFile(enRelPath, enRelPath, PBXSourceTree.Source); |
| | | project.AddFileToBuild(targetGUID, enFileGuid); |
| | | |
| | | // 添加 Sign In with Apple entitlements |
| | | AddEntitlements(projectPath, project, targetGUID); |
| | | // 中文 |
| | | string zhRelPath = "zh-Hans.lproj/InfoPlist.strings"; |
| | | string zhFileGuid = project.AddFile(zhRelPath, zhRelPath, PBXSourceTree.Source); |
| | | project.AddFileToBuild(targetGUID, zhFileGuid); |
| | | |
| | | File.WriteAllText(_projectPath, project.WriteToString()); |
| | | // 添加 Sign In with Apple entitlements |
| | | AddEntitlements(projectPath, project, targetGUID); |
| | | |
| | | File.WriteAllText(_projectPath, project.WriteToString()); |
| | | } |
| | | catch (System.Exception e) |
| | | { |
| | | Debug.LogError("[XCodeProjectMod] 将 InfoPlist.strings 添加到 Xcode 工程失败: " + e.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | } |
| | | |
| | | // 将 entitlements 文件加入工程并设置 build property |
| | | // 设置 CODE_SIGN_ENTITLEMENTS build property(不加入 Copy Bundle Resources) |
| | | // entitlements 文件只需要在 Build Settings 中引用,不需要加入任何 Build Phase |
| | | string entFileName = PBXProject.GetUnityTargetName() + ".entitlements"; |
| | | string fileGuid = project.AddFile(entFileName, entFileName, PBXSourceTree.Source); |
| | | project.AddFileToBuild(targetGUID, fileGuid); |
| | | project.SetBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", entFileName); |
| | | } |
| | | |
| | | |
| | | |
| | | private static string GetBuildPath() |
| | | { |
| | |
| | | } |
| | | } |
| | | return _sceneNames.ToArray(); |
| | | } |
| | | |
| | | private static void CopyDirectory(string sourceDir, string destDir) |
| | | { |
| | | Directory.CreateDirectory(destDir); |
| | | foreach (var file in Directory.GetFiles(sourceDir)) |
| | | { |
| | | string destFile = Path.Combine(destDir, Path.GetFileName(file)); |
| | | File.Copy(file, destFile, true); |
| | | } |
| | | foreach (var dir in Directory.GetDirectories(sourceDir)) |
| | | { |
| | | string destSubDir = Path.Combine(destDir, Path.GetFileName(dir)); |
| | | CopyDirectory(dir, destSubDir); |
| | | } |
| | | } |
| | | |
| | | private static bool s_IsAppend = false; |
| | |
| | | p.Start(); |
| | | p.WaitForExit(); |
| | | } |
| | | |
| | | } |