Skip to content

Commit 25cb16a

Browse files
committed
docs(BlankGetChannel): 完善渠道信息获取工具的文档和注释
添加详细的XML文档注释,包括各平台配置说明、方法参数说明和示例代码 优化类摘要描述,使用更清晰的格式展示不同平台的配置要求
1 parent 884d32f commit 25cb16a

1 file changed

Lines changed: 67 additions & 12 deletions

File tree

Runtime/BlankGetChannel.cs

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,92 @@
77
using UnityEngine;
88

99
/// <summary>
10-
/// 获取渠道名称
11-
/// Android:
12-
/// 需要在主启动的Activity 中添加
10+
/// 渠道信息获取工具类
11+
/// </summary>
12+
/// <remarks>
13+
/// 用于在Unity应用中获取当前运行平台的渠道信息。
14+
///
15+
/// <para><b>Android 平台配置:</b></para>
16+
/// 需要在主启动的 Activity 中添加以下 meta-data 标签:
17+
/// <code><![CDATA[
1318
/// <meta-data android:name="channel" android:value="android_cn_taptap" />
19+
/// ]]></code>
1420
///
15-
/// iOS :
16-
/// 需要在Info.plist中添加
17-
/// Key ==> value String 类型
18-
/// channel ==> ios_cn_xxx
19-
///
20-
/// </summary>
21+
/// <para><b>iOS 平台配置:</b></para>
22+
/// 需要在 Info.plist 中添加以下键值对(String 类型):
23+
/// <code><![CDATA[
24+
/// <key>channel</key>
25+
/// <string>ios_cn_xxx</string>
26+
/// ]]></code>
27+
///
28+
/// <para><b>Editor/PC 平台配置:</b></para>
29+
/// 在 StreamingAssets 文件夹下创建 channel.txt 文件,格式如下:
30+
/// <code><![CDATA[
31+
/// channel=editor_cn_test
32+
/// ]]></code>
33+
/// </remarks>
2134
public sealed class BlankGetChannel
2235
{
2336
#if UNITY_IOS
37+
/// <summary>
38+
/// iOS 平台原生方法:从 Info.plist 中获取渠道名称
39+
/// </summary>
40+
/// <param name="channelKey">渠道键名,默认为 "channel"</param>
41+
/// <returns>渠道名称</returns>
2442
[DllImport("__Internal")]
2543
private static extern string getChannelName(string channelKey);
2644

2745
#endif
46+
/// <summary>
47+
/// 渠道信息缓存字典,用于避免重复读取配置
48+
/// </summary>
2849
private static readonly Dictionary<string, string> ChannelCache = new Dictionary<string, string>();
2950

3051
/// <summary>
31-
/// 获取渠道值
52+
/// 获取指定渠道键对应的渠道名称
3253
/// </summary>
33-
public static string GetChannelName(string channelKey = "channel")
54+
/// <remarks>
55+
/// 该方法会根据当前运行平台从相应的配置源读取渠道信息,并使用缓存避免重复读取。
56+
/// <list type="table">
57+
/// <listheader>
58+
/// <term>平台</term>
59+
/// <description>配置源</description>
60+
/// </listheader>
61+
/// <item>
62+
/// <term>Android</term>
63+
/// <description>AndroidManifest.xml 中的 meta-data</description>
64+
/// </item>
65+
/// <item>
66+
/// <term>iOS</term>
67+
/// <description>Info.plist 中的键值对</description>
68+
/// </item>
69+
/// <item>
70+
/// <term>Editor/PC</term>
71+
/// <description>StreamingAssets/channel.txt 文件</description>
72+
/// </item>
73+
/// </list>
74+
/// </remarks>
75+
/// <param name="channelKey">渠道键名,默认为 "channel"</param>
76+
/// <param name="defaultValue">当未找到渠道配置时返回的默认值,默认为 "default"</param>
77+
/// <returns>渠道名称,如果未配置则返回 <paramref name="defaultValue"/></returns>
78+
/// <example>
79+
/// 以下示例展示如何获取渠道名称:
80+
/// <code><![CDATA[
81+
/// // 使用默认参数获取主渠道
82+
/// string channel = BlankGetChannel.GetChannelName();
83+
///
84+
/// // 获取指定键的渠道
85+
/// string subChannel = BlankGetChannel.GetChannelName("sub_channel", "unknown");
86+
/// ]]></code>
87+
/// </example>
88+
public static string GetChannelName(string channelKey = "channel", string defaultValue = "default")
3489
{
3590
if (ChannelCache.TryGetValue(channelKey, out var value))
3691
{
3792
return value;
3893
}
3994

40-
string channelName = "default";
95+
string channelName = defaultValue;
4196
#if UNITY_STANDALONE || UNITY_EDITOR
4297
string path = Application.streamingAssetsPath + "/channel.txt";
4398
if (File.Exists(path))

0 commit comments

Comments
 (0)