11#if UNITY_IOS
2+ using System ;
23using System . Collections . Generic ;
34using System . IO ;
45using UnityEditor ;
@@ -8,6 +9,25 @@ namespace GameFrameX.Xcode.Editor
89{
910 public class SettingLoader
1011 {
12+ private const string CHANNEL_ARG = "-channel" ;
13+
14+ /// <summary>
15+ /// 从命令行参数中获取当前渠道标识
16+ /// </summary>
17+ public static string GetChannel ( )
18+ {
19+ var args = Environment . GetCommandLineArgs ( ) ;
20+ for ( int i = 0 ; i < args . Length - 1 ; i ++ )
21+ {
22+ if ( args [ i ] . Equals ( CHANNEL_ARG , StringComparison . OrdinalIgnoreCase ) )
23+ {
24+ return args [ i + 1 ] ;
25+ }
26+ }
27+
28+ return null ;
29+ }
30+
1131 /// <summary>
1232 /// 加载所有匹配的配置文件
1333 /// </summary>
@@ -33,6 +53,40 @@ public static List<string> LoadSettingsData(string fileName)
3353 results . Sort ( ) ;
3454 return results ;
3555 }
56+
57+ /// <summary>
58+ /// 加载渠道专属配置文件,文件名格式为 XCodeConfig.{channel}.json
59+ /// </summary>
60+ /// <param name="baseFileName">基础文件名,如 XCodeConfig.json</param>
61+ /// <param name="channel">渠道标识</param>
62+ /// <returns>文件路径列表</returns>
63+ public static List < string > LoadChannelSettingsData ( string baseFileName , string channel )
64+ {
65+ if ( string . IsNullOrEmpty ( channel ) )
66+ {
67+ return new List < string > ( 0 ) ;
68+ }
69+
70+ string baseName = Path . GetFileNameWithoutExtension ( baseFileName ) ;
71+ string ext = Path . GetExtension ( baseFileName ) ;
72+ string channelFileName = $ "{ baseName } .{ channel } { ext } ";
73+
74+ var guids = AssetDatabase . FindAssets ( $ "t:textasset") ;
75+ var results = new List < string > ( 4 ) ;
76+ foreach ( var guid in guids )
77+ {
78+ string path = AssetDatabase . GUIDToAssetPath ( guid ) ;
79+ var newFileName = Path . GetFileName ( path ) ;
80+
81+ if ( newFileName . Equals ( channelFileName , StringComparison . OrdinalIgnoreCase ) )
82+ {
83+ results . Add ( path ) ;
84+ }
85+ }
86+
87+ results . Sort ( ) ;
88+ return results ;
89+ }
3690 }
3791}
3892#endif
0 commit comments