From 47921ce315e894bbbed712cbf04ee358be345113 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 09 七月 2026 11:08:41 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_client
---
Assets/Editor/XCodeProjectMod.cs | 292 +++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 226 insertions(+), 66 deletions(-)
diff --git a/Assets/Editor/XCodeProjectMod.cs b/Assets/Editor/XCodeProjectMod.cs
index 331e453..9a935b5 100644
--- a/Assets/Editor/XCodeProjectMod.cs
+++ b/Assets/Editor/XCodeProjectMod.cs
@@ -1,5 +1,4 @@
-锘縰sing DG.Tweening.Plugins.Core.PathCore;
-using System;
+锘縰sing System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
@@ -8,11 +7,8 @@
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 鎻掍欢瀛樻斁鐩綍锛圔uildIpa 鍓嶇敱 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)
@@ -27,8 +23,13 @@
BuildPlist(path);
ModifyFile(path);
-
-
+ // 鐢熸垚 .xcworkspace 缁撴瀯锛屾柟渚垮紑鍙戣�呭湪 Xcode 涓墜鍔� Add Package Dependency
+ // SPM 渚濊禆蹇呴』閫氳繃 .xcworkspace 绠$悊锛�.xcodeproj 鍗曠嫭鏃犳硶姝g‘ 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)
@@ -41,48 +42,28 @@
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 鐜瑕佹眰锛歩OS 13.0 鍙婁互涓�
+ project.SetBuildProperty(targetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
+ project.SetBuildProperty(fwTargetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
- project.AddBuildProperty(targetGUID, "GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
- //wkwebview
+ // Firebase 璋冭瘯鏃ュ織鍙傛暟
+ project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsDebugEnabled");
+ project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRDebugEnabled");
+ project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsVerboseLoggingEnabled");
+
+ // WebKit锛堟枃妗h姹傦級
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;
@@ -90,9 +71,67 @@
string fileGuid = project.AddFile(plistName, plistName, PBXSourceTree.Source);
project.AddFileToBuild(targetGUID, fileGuid);
}
+ else
+ {
+ Debug.LogWarning("[XCodeProjectMod] " + plistName + " 鏈壘鍒�: " + srcPath);
+ }
}
+ // hfsdk.xcframework 娣诲姞鍒板伐绋嬪苟璁剧疆涓� Embed & Sign
+ string hfFrameworkPath = path + "/Frameworks/hfsdk.xcframework";
+ if (Directory.Exists(hfFrameworkPath))
+ {
+ string fileGuid = project.AddFile(hfFrameworkPath, "Frameworks/hfsdk.xcframework", PBXSourceTree.Source);
+ project.AddFileToBuild(fwTargetGUID, fileGuid);
+ // Embed & Sign: 娣诲姞鍒� main target 鐨� Embed Frameworks
+ project.AddFileToBuild(targetGUID, fileGuid);
+ }
+
+ // Adjust SDK 渚濊禆鐨勭郴缁熸鏋讹紙鏂囨。瑕佹眰 Status 璁句负 Optional锛�
+ project.AddFrameworkToProject(fwTargetGUID, "AdServices.framework", true);
+ project.AddFrameworkToProject(fwTargetGUID, "AdSupport.framework", true);
+ project.AddFrameworkToProject(fwTargetGUID, "AppTrackingTransparency.framework", true);
+ project.AddFrameworkToProject(fwTargetGUID, "StoreKit.framework", true);
+
File.WriteAllText(_projectPath, project.WriteToString());
+ }
+
+ /// <summary>
+ /// 鐢熸垚 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 鍚庤嚜鍔ㄧ敓鎴愶紝浠g爜涓嶅仛澶勭悊銆�
+ /// </summary>
+ private static void CreateWorkspaceWithSPM(string projectPath)
+ {
+ string workspacePath = projectPath + "/Unity-iPhone.xcworkspace";
+ string xcodeprojAbsPath = projectPath + "/Unity-iPhone.xcodeproj";
+
+ if (!Directory.Exists(xcodeprojAbsPath))
+ {
+ Debug.LogWarning("[XCodeProjectMod] xcodeproj not found, skip creating workspace: " + xcodeprojAbsPath);
+ return;
+ }
+
+ Directory.CreateDirectory(workspacePath);
+
+ 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);
+
+ 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)
@@ -103,23 +142,23 @@
_plist.ReadFromString(File.ReadAllText(_plistPath));
PlistElementDict _rootDict = _plist.root;
- PlistElementDict _nsAppTransportSecurity = _rootDict.CreateDict("NSAppTransportSecurity");
- _nsAppTransportSecurity.SetBoolean("NSAllowsArbitraryLoads", true);
-
- _rootDict.SetString("NSPhotoLibraryAddUsageDescription", "You must grant the photo album permission to take screenshots and save data for users");
- _rootDict.SetString("NSCameraUsageDescription", "Please allow application permission access, otherwise the function cannot be started");
- _rootDict.SetString("NSUserTrackingUsageDescription", "This guide will display personalized ads specifically for you");
-
- // Adjust (funshine.plist: kAdjustAppToken)
- _rootDict.SetString("AdjustAppToken", "nbevz727gy68");
+ _rootDict.SetString("NSUserTrackingUsageDescription", "Please rest assured, granting permission will not access your private information on other websites. This permission is only used to identify the device and ensure service security and enhance browsing experience");
// 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");
- _rootDict.SetBoolean("FacebookAutoLogAppEventsEnabled", true);
- _rootDict.SetBoolean("FacebookAdvertiserIDCollectionEnabled", true);
+ // 閫傞厤娆х洘鍦板尯鏀跨瓥娉曡 - Google Analytics 榛樿鍏佽
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE", true);
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE", true);
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA", true);
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS", 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();
@@ -130,18 +169,7 @@
var array1 = _rootDict.CreateArray("LSApplicationQueriesSchemes");
array1.AddString("fbapi");
- array1.AddString("fbapi20130214");
- array1.AddString("fbapi20130410");
- array1.AddString("fbapi20130702");
- array1.AddString("fbapi20131010");
- array1.AddString("fbapi20131219");
- array1.AddString("fbapi20140410");
- array1.AddString("fbapi20140116");
- array1.AddString("fbapi20150313");
- array1.AddString("fbapi20150629");
- array1.AddString("fbapi20160328");
- array1.AddString("fbauth");
- array1.AddString("fb-messenger-share-api");
+ array1.AddString("fb-messenger-api");
array1.AddString("fbauth2");
array1.AddString("fbshareextension");
@@ -170,6 +198,7 @@
// 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("::printf(\"-> applicationDidBecomeActive()\\n\");", "[_fimpfunBridge applicationDidBecomeActive:application];");
@@ -179,9 +208,126 @@
_xclass.WriteBelow("DisplayConnection* _mainDisplay;", "FimpfunBridge* _fimpfunBridge;");
_xclass.WriteBelow("@property (readonly, copy, nonatomic) DisplayConnection* mainDisplay;",
"@property (readonly, copy, nonatomic) FimpfunBridge* fimpfunBridge;");
+
+ // 3.1 閫傞厤娆х洘鏀跨瓥锛氬湪 viewDidAppear 涓皟鐢� adaptingEUGDPR锛堟枃妗h姹傦級
+ // 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锛圓pp 鍚嶇О鏈湴鍖栵級
+ CreateInfoPlistStrings(projectPath);
}
-
+ /// <summary>
+ /// 鍒涘缓 InfoPlist.strings 鏂囦欢鐢ㄤ簬 App 鍚嶇О鏈湴鍖�
+ /// </summary>
+ private static void CreateInfoPlistStrings(string projectPath)
+ {
+ // 鑻辨枃锛堥粯璁わ級
+ string enDir = projectPath + "/English.lproj";
+ if (!Directory.Exists(enDir))
+ {
+ Directory.CreateDirectory(enDir);
+ }
+ string enStringsPath = enDir + "/InfoPlist.strings";
+ if (!File.Exists(enStringsPath))
+ {
+ 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);
+ try
+ {
+ PBXProject project = new PBXProject();
+ project.ReadFromString(File.ReadAllText(_projectPath));
+ string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName());
+
+ // 鑻辨枃
+ string enRelPath = "English.lproj/InfoPlist.strings";
+ string enFileGuid = project.AddFile(enRelPath, enRelPath, PBXSourceTree.Source);
+ project.AddFileToBuild(targetGUID, enFileGuid);
+
+ // 涓枃
+ string zhRelPath = "zh-Hans.lproj/InfoPlist.strings";
+ string zhFileGuid = project.AddFile(zhRelPath, zhRelPath, PBXSourceTree.Source);
+ project.AddFileToBuild(targetGUID, zhFileGuid);
+
+ // 娣诲姞 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>
+ /// 娣诲姞 Sign In with Apple 绛� entitlements
+ /// </summary>
+ private static void AddEntitlements(string projectPath, PBXProject project, string targetGUID)
+ {
+ string entPath = projectPath + "/" + PBXProject.GetUnityTargetName() + ".entitlements";
+
+ // 濡傛灉 entitlements 鏂囦欢涓嶅瓨鍦紝鍒涘缓
+ if (!File.Exists(entPath))
+ {
+ string entContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" +
+ "<plist version=\"1.0\">\n" +
+ "<dict>\n" +
+ "\t<key>com.apple.developer.applesignin</key>\n" +
+ "\t<array>\n" +
+ "\t\t<string>Default</string>\n" +
+ "\t</array>\n" +
+ "</dict>\n" +
+ "</plist>\n";
+ File.WriteAllText(entPath, entContent);
+ }
+ else
+ {
+ // 宸叉湁 entitlements 鏂囦欢锛屾鏌ユ槸鍚﹀凡鏈� Sign In with Apple
+ string existingContent = File.ReadAllText(entPath);
+ if (!existingContent.Contains("com.apple.developer.applesignin"))
+ {
+ existingContent = existingContent.Replace("</dict>",
+ "\t<key>com.apple.developer.applesignin</key>\n" +
+ "\t<array>\n" +
+ "\t\t<string>Default</string>\n" +
+ "\t</array>\n" +
+ "</dict>");
+ File.WriteAllText(entPath, existingContent);
+ }
+ }
+
+ // 璁剧疆 CODE_SIGN_ENTITLEMENTS build property锛堜笉鍔犲叆 Copy Bundle Resources锛�
+ // entitlements 鏂囦欢鍙渶瑕佸湪 Build Settings 涓紩鐢紝涓嶉渶瑕佸姞鍏ヤ换浣� Build Phase
+ string entFileName = PBXProject.GetUnityTargetName() + ".entitlements";
+ project.SetBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", entFileName);
+ }
private static string GetBuildPath()
{
@@ -211,6 +357,21 @@
}
}
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;
@@ -250,5 +411,4 @@
p.Start();
p.WaitForExit();
}
-
}
--
Gitblit v1.8.0