From 1b6da6b04ba2beb49c3b23ab08a022f6026d5bac Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 07 十月 2026 18:24:49 +0800
Subject: [PATCH] 0312 欢游硬核新SDK -  IOS打包;需要复测下 IOS包是否正常

---
 Assets/Editor/XCodeProjectMod.cs |  433 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 360 insertions(+), 73 deletions(-)

diff --git a/Assets/Editor/XCodeProjectMod.cs b/Assets/Editor/XCodeProjectMod.cs
index 8f22f56..010c268 100644
--- a/Assets/Editor/XCodeProjectMod.cs
+++ b/Assets/Editor/XCodeProjectMod.cs
@@ -1,6 +1,7 @@
 锘縰sing System;
 using System.Collections.Generic;
 using System.IO;
+using System.Text.RegularExpressions;
 using UnityEditor;
 using UnityEditor.iOS.Xcode.Custom;
 using UnityEngine;
@@ -10,6 +11,34 @@
     // Channel 鎻掍欢瀛樻斁鐩綍锛圔uildIpa 鍓嶇敱 ClientPackage.BuildIpa 浠� _sdkPath 鎷疯礉鍒� Assets/Plugins/iOS/Channel锛�
     private static readonly string iOSPluginPath = Application.dataPath + "/Plugins/iOS/Channel";
 
+    // ===== 娓犻亾鏍囪瘑锛氫笌 ClientPackage 涓� VersionConfig.appId / sdkFileName 瀵瑰簲 =====
+    private const string CHANNEL_SGHY = "sghy";   // 鍘熸湁娓犻亾锛坒impfunSDK + Firebase/Facebook/Adjust锛�
+    private const string CHANNEL_HYYH = "hyyh";   // 娆㈡父纭牳锛圚GameSDK锛�
+
+    private static string s_Channel = null;
+
+    /// <summary>褰撳墠鎵撳寘娓犻亾锛屾湭璇嗗埆鍒版椂鎸� sghy 澶勭悊锛屼繚璇佸師鏈夋墦鍖呰涓轰笉鍙�</summary>
+    private static string Channel
+    {
+        get
+        {
+            if (s_Channel == null)
+            {
+                s_Channel = DetectChannel();
+            }
+            return s_Channel;
+        }
+    }
+
+    private static bool IsSghy { get { return Channel == CHANNEL_SGHY; } }
+    private static bool IsHyyh { get { return Channel == CHANNEL_HYYH; } }
+
+    private static string DetectChannel()
+    {
+       
+        return VersionConfig.Get().appId;;
+    }
+
     [UnityEditor.Callbacks.PostProcessBuild(999)]
     public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
     {
@@ -18,18 +47,19 @@
             return;
         }
 
+        // 涓�娆� Editor 浼氳瘽鍙兘杩炵画鎵撳涓笭閬撶殑鍖咃紝杩欓噷閲嶆柊璇嗗埆娓犻亾
+        s_Channel = null;
+        Debug.Log("[XCodeProjectMod] 褰撳墠 iOS 娓犻亾: " + Channel);
 
         DoPBXProject(path);
         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);
+        // SPM 渚濊禆锛團irebase / Facebook / Adjust锛変负 sghy 娓犻亾浣跨敤锛岄渶瑕侀�氳繃 .xcworkspace 绠$悊
+        if (IsSghy)
+        {
+            CreateWorkspaceWithSPM(path);
+        }
     }
 
     static void DoPBXProject(string path)
@@ -47,53 +77,86 @@
         project.SetBuildProperty(fwTargetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
 
         project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
-
-        // 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);
-
         //UnityFramework
         project.AddBuildProperty(fwTargetGUID, "OTHER_LDFLAGS", "-ObjC");
 
-        // 娣诲姞 GoogleService-Info.plist 鍜� funshine.plist 鍒板伐绋�
-        string[] configPlists = { "GoogleService-Info.plist", "funshine.plist" };
-        foreach (var plistName in configPlists)
+        // sghy 娓犻亾锛欶irebase 璋冭瘯鏃ュ織鍙傛暟
+        if (IsSghy)
         {
-            string srcPath = iOSPluginPath + "/" + plistName;
-            if (File.Exists(srcPath))
+            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);
+            // 娣诲姞 GoogleService-Info.plist 鍜� funshine.plist 鍒板伐绋�
+            string[] configPlists = { "GoogleService-Info.plist", "funshine.plist" };
+            foreach (var plistName in configPlists)
             {
-                string destPath = path + "/" + plistName;
-                File.Copy(srcPath, destPath, true);
-                string fileGuid = project.AddFile(plistName, plistName, PBXSourceTree.Source);
+                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);
+                }
+            }
+            // hfsdk.xcframework 娣诲姞鍒板伐绋嬪苟璁剧疆涓� Embed & Sign锛坰ghy 娓犻亾锛�
+            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);
             }
-            else
-            {
-                Debug.LogWarning("[XCodeProjectMod] " + plistName + " 鏈壘鍒�: " + srcPath);
-            }
+
+            project.AddFrameworkToProject(fwTargetGUID, "AdServices.framework", true);
+            project.AddFrameworkToProject(fwTargetGUID, "AdSupport.framework", true);
+            project.AddFrameworkToProject(fwTargetGUID, "AppTrackingTransparency.framework", true);
+            project.AddFrameworkToProject(fwTargetGUID, "StoreKit.framework", true);
         }
 
-        // hfsdk.xcframework 娣诲姞鍒板伐绋嬪苟璁剧疆涓� Embed & Sign
-        string hfFrameworkPath = path + "/Frameworks/hfsdk.xcframework";
-        if (Directory.Exists(hfFrameworkPath))
+
+        // hyyh 娓犻亾锛欻GameSDK.xcframework / HGameChannelSdk.xcframework 璁剧疆涓� Embed & Sign
+        if (IsHyyh)
         {
-            string fileGuid = project.AddFile(hfFrameworkPath, "Frameworks/hfsdk.xcframework", PBXSourceTree.Source);
-            project.AddFileToBuild(fwTargetGUID, fileGuid);
-            // Embed & Sign: 娣诲姞鍒� main target 鐨� Embed Frameworks
-            project.AddFileToBuild(targetGUID, fileGuid);
+            AddEmbedFramework(project, path, fwTargetGUID, targetGUID, "HGameSDK.xcframework");
+            AddEmbedFramework(project, path, fwTargetGUID, targetGUID, "HGameChannelSdk.xcframework");
         }
-
-        // 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>
+    /// 灏嗗鍑哄伐绋� Frameworks 鐩綍涓嬬殑 xcframework 鍔犲叆宸ョ▼骞惰缃� Embed & Sign銆�
+    /// Unity 浼氭妸 Assets/Plugins/iOS 涓嬬殑 .xcframework 鎷疯礉鍒� &lt;瀵煎嚭宸ョ▼&gt;/Frameworks 涓嬨��
+    /// </summary>
+    private static void AddEmbedFramework(PBXProject project, string projectPath, string fwTargetGUID, string targetGUID, string frameworkName)
+    {
+        string relPath = "Frameworks/" + frameworkName;
+        string frameworkPath = projectPath + "/" + relPath;
+        if (!Directory.Exists(frameworkPath))
+        {
+            // Unity 涓嶅悓鐗堟湰鏀剧疆浣嶇疆鍙兘涓嶅悓锛團rameworks 涓嬫垨鎻掍欢瀛愮洰褰曪級锛岃繖閲岄�掑綊鍏滃簳鏌ユ壘
+            string[] found = Directory.GetDirectories(projectPath, frameworkName, SearchOption.AllDirectories);
+            if (found == null || found.Length == 0)
+            {
+                Debug.LogWarning("[XCodeProjectMod] " + frameworkName + " 鏈壘鍒�: " + frameworkPath);
+                return;
+            }
+            frameworkPath = found[0];
+            relPath = frameworkPath.Substring(projectPath.Length).TrimStart('/', '\\').Replace("\\", "/");
+        }
+
+        string fileGuid = project.AddFile(frameworkPath, relPath, PBXSourceTree.Source);
+        project.AddFileToBuild(fwTargetGUID, fileGuid);  // Link Binary With Libraries
+        project.AddFileToBuild(targetGUID, fileGuid);    // Embed Frameworks
+        Debug.Log("[XCodeProjectMod] 宸叉坊鍔�(Embed & Sign): " + relPath);
     }
 
     /// <summary>
@@ -144,21 +207,40 @@
         PlistElementDict _rootDict = _plist.root;
         _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", "1103765897fb67ffc898e6a8ee2d9aec");
-        _rootDict.SetString("FacebookDisplayName", "EZ PZ: Byte Heroes");
+        // sghy 娓犻亾锛欶acebook锛坒unshine.plist: kFacebookAppID / kFacebookAppSecret锛�
+        if (IsSghy)
+        {
+            _rootDict.SetString("FacebookAppID", "1445747540428317");
+            _rootDict.SetString("FacebookClientToken", "1103765897fb67ffc898e6a8ee2d9aec");
+            _rootDict.SetString("FacebookDisplayName", "EZ PZ: Byte Heroes");
 
-        // 閫傞厤娆х洘鍦板尯鏀跨瓥娉曡 - 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);
+            PlistElementArray nsURLTypes = _rootDict.CreateArray("CFBundleURLTypes");
+            var dict0 = nsURLTypes.AddDict();
+            dict0.SetString("CFBundleTypeRole", "Editor");
+            dict0.SetString("CFBundleURLName", "fb");
+            var schemesArray = dict0.CreateArray("CFBundleURLSchemes");
+            schemesArray.AddString("fb1445747540428317");
 
-        // App 鍚嶇О鏈湴鍖�
-        _rootDict.SetBoolean("Application has localized display name", true);
-        _rootDict.SetString("CFBundleDevelopmentRegion", "english");
-        _rootDict.SetString("Localization native development region", "english");
+            var array1 = _rootDict.CreateArray("LSApplicationQueriesSchemes");
+            array1.AddString("fbapi");
+            array1.AddString("fb-messenger-api");
+            array1.AddString("fbauth2");
+            array1.AddString("fbshareextension");
+            // 閫傞厤娆х洘鍦板尯鏀跨瓥娉曡 - 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 鍚嶇О鏈湴鍖栵紙闇�瑕� InfoPlist.strings 涓瓨鍦� CFBundleDisplayName锛岃 CreateInfoPlistStrings锛�
+        if (HasDisplayName())
+        {
+            _rootDict.SetBoolean("Application has localized display name", true);
+            _rootDict.SetString("CFBundleDevelopmentRegion", "english");
+            _rootDict.SetString("Localization native development region", "english");
+        }
 
         // ===== 鍚姩灞忕櫧搴曪紙Info.plist 鏂瑰紡锛歎ILaunchScreen -> Background color锛�=====
         // iOS 13+ 鏀寔鐢� Info.plist 鐨� UILaunchScreen 瀛楀吀鎻忚堪鍚姩灞忥紝鏃犻渶 storyboard銆�
@@ -177,19 +259,6 @@
         PlistElementDict launchScreenDict = _rootDict.CreateDict("UILaunchScreen");
         launchScreenDict.SetString("UIColorName", launchScreenColorName);
         // =====================================================================
-
-        PlistElementArray nsURLTypes = _rootDict.CreateArray("CFBundleURLTypes");
-        var dict0 = nsURLTypes.AddDict();
-        dict0.SetString("CFBundleTypeRole", "Editor");
-        dict0.SetString("CFBundleURLName", "fb");
-        var schemesArray = dict0.CreateArray("CFBundleURLSchemes");
-        schemesArray.AddString("fb1445747540428317");
-
-        var array1 = _rootDict.CreateArray("LSApplicationQueriesSchemes");
-        array1.AddString("fbapi");
-        array1.AddString("fb-messenger-api");
-        array1.AddString("fbauth2");
-        array1.AddString("fbshareextension");
 
         File.WriteAllText(_plistPath, _plist.WriteToString());
     }
@@ -247,6 +316,27 @@
 
     private static void ModifyFile(string projectPath)
     {
+        if (IsHyyh)
+        {
+            ModifyFileForHyyh(projectPath);
+        }
+        else
+        {
+            ModifyFileForSghy(projectPath);
+        }
+
+        // 鍒涘缓 InfoPlist.strings锛圓pp 鍚嶇О鏈湴鍖栵級
+        CreateInfoPlistStrings(projectPath);
+
+        // Sign In with Apple entitlements
+        SetupEntitlements(projectPath);
+    }
+
+    /// <summary>
+    /// sghy 娓犻亾锛坒impfunSDK + Firebase/Facebook/Adjust锛夌殑 AppController 娉ㄥ叆
+    /// </summary>
+    private static void ModifyFileForSghy(string projectPath)
+    {
         //淇敼UnityAppController.mm 鏂囦欢
         var _xclass = new XClass(projectPath + "/Classes/UnityAppController.mm");
         //寮曞叆fimpfunSDK
@@ -289,9 +379,179 @@
         {
             Debug.LogWarning("[XCodeProjectMod] UnityViewControllerBase.mm 鏂囦欢涓嶅瓨鍦紝璺宠繃 viewDidAppear 娉ㄥ叆銆傛 Unity 鐗堟湰鍙兘宸茬Щ闄よ鏂囦欢銆�");
         }
+    }
 
-        // 鍒涘缓 InfoPlist.strings锛圓pp 鍚嶇О鏈湴鍖栵級
-        CreateInfoPlistStrings(projectPath);
+    /// <summary>
+    /// hyyh 娓犻亾锛圚GameSDK锛夌殑 AppController 娉ㄥ叆锛�
+    /// 寮曞叆 UniversalSDK銆佹毚闇� IOSUniyMessageHandle 缁� C#锛圓otSdkUtility锛夈�佸垵濮嬪寲骞惰浆鍙� AppDelegate 鐢熷懡鍛ㄦ湡銆�
+    /// </summary>
+    private static void ModifyFileForHyyh(string projectPath)
+    {
+        string mmPath = projectPath + "/Classes/UnityAppController.mm";
+        string hPath = projectPath + "/Classes/UnityAppController.h";
+
+        if (!File.Exists(mmPath) || !File.Exists(hPath))
+        {
+            Debug.LogError("[XCodeProjectMod][hyyh] UnityAppController 鏂囦欢涓嶅瓨鍦�: " + projectPath + "/Classes");
+            return;
+        }
+
+        // 寮曞叆 UniversalSDK锛堟笭閬撴彃浠� wgyx/UniversalSDK.h锛�
+        InsertBelowPattern(mmPath, @"#include\s+""PluginBase/AppDelegateListener\.h""",
+                           "#import \"UniversalSDK.h\"", "import UniversalSDK");
+
+        // C# 璋冪敤鍏ュ彛锛屼笌 AotSdkUtility.IOSUniyMessageHandle 瀵瑰簲
+        string entryCode = "\n" +
+                           "extern \"C\" void IOSUniyMessageHandle(const char* jsonString) {\n" +
+                           "    [GetAppController().universalSDK HandleUnityMessage:[NSString stringWithUTF8String:jsonString]];\n" +
+                           "}";
+        InsertBelowPattern(mmPath, @"extern\s+""C""\s+ScreenOrientation\s+UnityCurrentOrientation\s*\(\s*\)",
+                           entryCode, "IOSUniyMessageHandle");
+
+        // 鍒濆鍖� HGameSDK锛堝繀椤诲湪涓荤嚎绋嬨�佸湪 delegate 璁剧疆涔嬪悗锛�
+        string initCode = "\n" +
+                          "    _universalSDK = [[UniversalSDK alloc] init];\n" +
+                          "    [_universalSDK HGameSDKInit:application didFinishLaunchingWithOptions:launchOptions];";
+        InsertBelowPattern(mmPath, @"::printf\(""-> applicationDidFinishLaunching\(\\n""\);",
+                           initCode, "initSdk");
+
+        // ===== UIApplicationDelegate 鐢熷懡鍛ㄦ湡杞彂锛圚GameSDK 蹇呮帴锛�=====
+        InsertBelowPattern(mmPath, @"- \(BOOL\)application:[^\n]*openURL:[^\n]*\n\s*\{",
+                           "    [_universalSDK application:[UIApplication sharedApplication] openURL:url options:options];", "openURL");
+
+        InsertBelowPattern(mmPath, @"- \(void\)applicationWillResignActive:[^\n]*\n\s*\{",
+                           "    [_universalSDK applicationWillResignActive:[UIApplication sharedApplication]];", "willResignActive");
+
+        InsertBelowPattern(mmPath, @"- \(void\)applicationDidEnterBackground:[^\n]*\n\s*\{",
+                           "    [_universalSDK applicationDidEnterBackground:[UIApplication sharedApplication]];", "didEnterBackground");
+
+        InsertBelowPattern(mmPath, @"- \(void\)applicationWillEnterForeground:[^\n]*\n\s*\{",
+                           "    [_universalSDK applicationWillEnterForeground:[UIApplication sharedApplication]];", "willEnterForeground");
+
+        InsertBelowPattern(mmPath, @"- \(void\)applicationDidBecomeActive:[^\n]*\n\s*\{",
+                           "    [_universalSDK applicationDidBecomeActive:[UIApplication sharedApplication]];", "didBecomeActive");
+
+        InsertBelowPattern(mmPath, @"- \(void\)applicationWillTerminate:[^\n]*\n\s*\{",
+                           "    [_universalSDK applicationWillTerminate:[UIApplication sharedApplication]];", "willTerminate");
+
+        InsertBelowPattern(mmPath, @"- \(void\)application:[^\n]*didRegisterForRemoteNotificationsWithDeviceToken:[^\n]*\n\s*\{",
+                           "    [_universalSDK application:[UIApplication sharedApplication] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];", "didRegisterToken");
+
+        InsertBelowPattern(mmPath, @"- \(void\)application:[^\n]*didFailToRegisterForRemoteNotificationsWithError:[^\n]*\n\s*\{",
+                           "    [_universalSDK application:[UIApplication sharedApplication] didFailToRegisterForRemoteNotificationsWithError:error];", "didFailRegister");
+
+        // 闈欓粯杩滅▼閫氱煡锛氫紭鍏堝鐢� Unity 宸叉湁鐨勭幇浠e洖璋冿紱Unity 鏈0鏄庤鏂规硶鏃惰ˉ涓�涓畬鏁村疄鐜帮紙鏂囨。蹇呮帴锛�
+        string remotePattern = @"- \(void\)application:[^\n]*didReceiveRemoteNotification:[^\n]*fetchCompletionHandler:[^\n]*\n\s*\{";
+        string remoteForward = "    [_universalSDK application:[UIApplication sharedApplication] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];";
+        if (!InsertBelowPattern(mmPath, remotePattern, remoteForward, "didReceiveRemoteNotification"))
+        {
+            AppendMethod(mmPath,
+                "- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler\n{\n" +
+                "    [_universalSDK application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];\n}",
+                "didReceiveRemoteNotification");
+        }
+
+        // 灞忓箷鏂瑰悜锛氭笭閬撹繑鍥� 0 琛ㄧず涓嶆帴绠★紝缁х画璧� Unity 鍘熸湁閫昏緫
+        InsertBelowPattern(mmPath, @"- \(NSUInteger\)application:[^\n]*supportedInterfaceOrientationsForWindow:[^\n]*\n\s*\{",
+                           "    NSUInteger sdkOrientations = [_universalSDK application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:window];\n" +
+                           "    if (sdkOrientations != 0) {\n        return sdkOrientations;\n    }", "supportedInterfaceOrientations");
+
+        // Universal Link锛氫紭鍏堝鐢� Unity 宸叉湁鍥炶皟锛涙病鏈夊垯琛ヤ竴涓畬鏁村疄鐜帮紙鏂囨。蹇呮帴锛�
+        string continuePattern = @"- \(BOOL\)application:[^\n]*continueUserActivity:[^\n]*\n\s*\{";
+        string continueForward = "    if ([_universalSDK application:[UIApplication sharedApplication] continueUserActivity:userActivity restorationHandler:restorationHandler]) {\n        return YES;\n    }";
+        if (!InsertBelowPattern(mmPath, continuePattern, continueForward, "continueUserActivity"))
+        {
+            AppendMethod(mmPath,
+                "- (BOOL)application:(UIApplication*)application continueUserActivity:(NSUserActivity*)userActivity restorationHandler:(void (^)(NSArray*))restorationHandler\n{\n" +
+                "    if ([_universalSDK application:application continueUserActivity:userActivity restorationHandler:restorationHandler]) {\n        return YES;\n    }\n" +
+                "    return NO;\n}",
+                "continueUserActivity");
+        }
+
+        // 淇敼 UnityAppController.h
+        var _xclass = new XClass(hPath);
+        _xclass.WriteBelow("@class DisplayConnection;", "@class UniversalSDK;");
+        _xclass.WriteBelow("DisplayConnection*  _mainDisplay;", "UniversalSDK* _universalSDK;");
+        _xclass.WriteBelow("@property (readonly, copy, nonatomic) DisplayConnection*    mainDisplay;",
+                           "@property (readonly, copy, nonatomic) UniversalSDK*  universalSDK;");
+    }
+
+    /// <summary>
+    /// 鎸夋鍒欐煡鎵炬敞鍏ョ偣锛屽苟鍦ㄨ琛屼箣鍚庢彃鍏ヤ唬鐮併�傛壘涓嶅埌鏃跺彧鍛婅锛屼笉淇敼鏂囦欢銆�
+    /// </summary>
+    private static bool InsertBelowPattern(string filePath, string pattern, string text, string tag)
+    {
+        if (!File.Exists(filePath))
+        {
+            Debug.LogWarning("[XCodeProjectMod] 鏂囦欢涓嶅瓨鍦紝璺宠繃娉ㄥ叆[" + tag + "]: " + filePath);
+            return false;
+        }
+
+        string content = File.ReadAllText(filePath);
+        Match match = Regex.Match(content, pattern);
+        if (!match.Success)
+        {
+            Debug.LogWarning("[XCodeProjectMod] 鏈壘鍒版敞鍏ョ偣[" + tag + "]锛岃烦杩�: " + pattern);
+            return false;
+        }
+
+        int lineEnd = content.IndexOf('\n', match.Index + match.Length - 1);
+        if (lineEnd < 0)
+        {
+            lineEnd = content.Length;
+        }
+
+        content = content.Substring(0, lineEnd) + "\n" + text + content.Substring(lineEnd);
+        File.WriteAllText(filePath, content);
+        return true;
+    }
+
+    /// <summary>
+    /// 鍦� UnityAppController.mm 鐨� @implementation UnityAppController 鍧楁湯灏捐拷鍔犱竴涓畬鏁寸殑 delegate 鏂规硶銆�
+    /// 鐢ㄤ簬 Unity 鏈0鏄庤鏂规硶銆佷絾娓犻亾 SDK 瑕佹眰蹇呴』杞彂鐨勫満鏅紙鏂囨。蹇呮帴椤癸級銆�
+    /// </summary>
+    private static bool AppendMethod(string filePath, string methodText, string tag)
+    {
+        if (!File.Exists(filePath))
+        {
+            Debug.LogWarning("[XCodeProjectMod] 鏂囦欢涓嶅瓨鍦紝璺宠繃杩藉姞[" + tag + "]: " + filePath);
+            return false;
+        }
+
+        string content = File.ReadAllText(filePath);
+        int implIndex = content.IndexOf("@implementation UnityAppController", StringComparison.Ordinal);
+        if (implIndex < 0)
+        {
+            Debug.LogError("[XCodeProjectMod] 鏈壘鍒� @implementation UnityAppController锛屾棤娉曡拷鍔燵" + tag + "]");
+            return false;
+        }
+
+        int endIndex = content.IndexOf("@end", implIndex, StringComparison.Ordinal);
+        if (endIndex < 0)
+        {
+            Debug.LogError("[XCodeProjectMod] 鏈壘鍒� @end锛屾棤娉曡拷鍔燵" + tag + "]");
+            return false;
+        }
+
+        content = content.Substring(0, endIndex) + "\n" + methodText + "\n\n" + content.Substring(endIndex);
+        File.WriteAllText(filePath, content);
+        Debug.Log("[XCodeProjectMod] 宸茶拷鍔� delegate 鏂规硶[" + tag + "]");
+        return true;
+    }
+
+    /// <summary>
+    /// 鍚勬笭閬撶殑 App 鏄剧ず鍚嶇О锛歔娓犻亾] = { 鑻辨枃, 绠�浣撲腑鏂� }
+    /// 鏈厤缃殑娓犻亾涓嶄細鐢熸垚鏈湴鍖栧悕绉帮紝鐩存帴浣跨敤 PlayerSettings 涓殑 Product Name銆�
+    /// </summary>
+    private static readonly Dictionary<string, string[]> DisplayNames = new Dictionary<string, string[]>
+    {
+        { CHANNEL_SGHY, new[] { "EZ PZ", "鎳掍汉涓夊浗" } },
+        // TODO hyyh 娓犻亾纭 App 鍚嶇О鍚庡湪杩欓噷琛ュ厖锛歿 CHANNEL_HYYH, new[] { "鑻辨枃鍚�", "涓枃鍚�" } },
+    };
+
+    private static bool HasDisplayName()
+    {
+        return DisplayNames.ContainsKey(Channel);
     }
 
     /// <summary>
@@ -299,6 +559,14 @@
     /// </summary>
     private static void CreateInfoPlistStrings(string projectPath)
     {
+        if (!HasDisplayName())
+        {
+            Debug.LogWarning("[XCodeProjectMod] 娓犻亾 " + Channel + " 鏈厤缃� App 鏄剧ず鍚嶇О锛岃烦杩� InfoPlist.strings 鏈湴鍖�");
+            return;
+        }
+
+        string[] names = DisplayNames[Channel];
+
         // 鑻辨枃锛堥粯璁わ級
         string enDir = projectPath + "/English.lproj";
         if (!Directory.Exists(enDir))
@@ -308,7 +576,7 @@
         string enStringsPath = enDir + "/InfoPlist.strings";
         if (!File.Exists(enStringsPath))
         {
-            File.WriteAllText(enStringsPath, "CFBundleDisplayName = \"EZ PZ\";\n");
+            File.WriteAllText(enStringsPath, "CFBundleDisplayName = \"" + names[0] + "\";\n");
         }
 
         // 涓枃
@@ -320,7 +588,7 @@
         string zhStringsPath = zhDir + "/InfoPlist.strings";
         if (!File.Exists(zhStringsPath))
         {
-            File.WriteAllText(zhStringsPath, "CFBundleDisplayName = \"鎳掍汉涓夊浗\";\n");
+            File.WriteAllText(zhStringsPath, "CFBundleDisplayName = \"" + names[1] + "\";\n");
         }
 
         // 灏� InfoPlist.strings 娣诲姞鍒� Xcode 宸ョ▼
@@ -341,14 +609,33 @@
             string zhFileGuid = project.AddFile(zhRelPath, zhRelPath, PBXSourceTree.Source);
             project.AddFileToBuild(targetGUID, zhFileGuid);
 
-            // 娣诲姞 Sign In with Apple entitlements
+            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 SetupEntitlements(string projectPath)
+    {
+        string _projectPath = PBXProject.GetPBXProjectPath(projectPath);
+        try
+        {
+            PBXProject project = new PBXProject();
+            project.ReadFromString(File.ReadAllText(_projectPath));
+            string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName());
+
             AddEntitlements(projectPath, project, targetGUID);
 
             File.WriteAllText(_projectPath, project.WriteToString());
         }
         catch (System.Exception e)
         {
-            Debug.LogError("[XCodeProjectMod] 灏� InfoPlist.strings 娣诲姞鍒� Xcode 宸ョ▼澶辫触: " + e.Message);
+            Debug.LogError("[XCodeProjectMod] 娣诲姞 entitlements 澶辫触: " + e.Message);
         }
     }
 

--
Gitblit v1.8.0