Skip to content

Commit 41e8d8a

Browse files
committed
docs: 更新 README 以反映多平台支持和 API 增强
- 扩展支持平台列表,新增 tvOS、visionOS、Editor、PC、WebGL、UWP 及主机平台 - 更新代码示例,展示 GetChannelName 方法的重载用法(默认键、自定义键、带默认值) - 为 iOS/tvOS/visionOS 和 Android 平台添加配置文件示例 - 新增 Editor/PC/主机平台使用 Resources/app_info.txt 的配置说明 - 补充注意事项,明确各平台的配置文件对应关系及性能优化说明
1 parent ccf260a commit 41e8d8a

1 file changed

Lines changed: 51 additions & 13 deletions

File tree

README.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## 主要功能
66

7-
- 支持 iOSAndroid 双平台
7+
- 支持多平台:iOS、tvOS、visionOS、Android、Editor、PC(Windows/Mac/Linux)、WebGL、UWP、PS4、PS5、Xbox One、Nintendo Switch
88
- 提供简单的 API 来获取预设的渠道信息。
99
- iOS 平台在构建时自动在 `Info.plist` 中添加默认渠道号 (如果未设置)。
1010

@@ -49,30 +49,44 @@ public class MyGameScript : MonoBehaviour
4949
{
5050
void Start()
5151
{
52-
// 假设您在 AndroidManifest.xml 或 Info.plist 中使用的键是 "channelName"
53-
string channel = BlankGetChannel.GetChannelName("channelName");
52+
// 获取默认渠道号(键名为 "channel")
53+
string channel = BlankGetChannel.GetChannelName();
5454
Debug.Log("当前渠道号: " + channel);
5555

56-
// 示例中使用的键是 "appchannel"
57-
// string exampleChannel = BlankGetChannel.GetChannelName("appchannel");
58-
// Debug.Log("示例渠道号: " + exampleChannel);
56+
// 获取指定键的渠道号
57+
string customChannel = BlankGetChannel.GetChannelName("channelName");
58+
Debug.Log("自定义渠道号: " + customChannel);
59+
60+
// 获取渠道号,并指定默认值
61+
string subChannel = BlankGetChannel.GetChannelName("sub_channel", "unknown");
62+
Debug.Log("子渠道号: " + subChannel);
5963
}
6064
}
6165
```
6266

63-
### 2. iOS 平台设置
67+
### 2. iOS / tvOS / visionOS 平台设置
6468

65-
对于 iOS 平台,插件包含一个构建后处理器 (`PostProcessBuildHandler.cs`)。如果在构建时项目的 `Info.plist` 文件中:
69+
对于 iOS、tvOS 和 visionOS 平台,插件包含一个构建后处理器 (`PostProcessBuildHandler.cs`)。如果在构建时项目的 `Info.plist` 文件中:
6670
- **没有** 名为 `channel` 的键,该脚本会自动添加一个键为 `channel`,值为 `default` 的条目。
6771
- **已经存在** 名为 `channel` 的键,则不会进行任何修改。
6872

6973
您可以在 Xcode 项目的 `Info.plist` 文件中修改 `channel` 的值,或者在调用 `BlankGetChannel.GetChannelName()` 时使用您自定义的键名(确保该键名存在于 `Info.plist` 中)。
7074

75+
**Info.plist 配置示例:**
76+
77+
```xml
78+
<key>channel</key>
79+
<string>ios_cn_taptap</string>
80+
81+
<key>sub_channel</key>
82+
<string>beta</string>
83+
```
84+
7185
### 3. Android 平台设置
7286

7387
对于 Android 平台,您需要在 `AndroidManifest.xml` 文件中定义渠道信息。通常,这是通过在 `<application>` 标签内添加 `<meta-data>` 标签来完成的。
7488

75-
例如,如果您想使用键名 `channelName` 和值为 `myCustomChannel`
89+
例如,如果您想使用键名 `channel` 和值为 `android_cn_taptap`
7690

7791
```xml
7892
<application ...>
@@ -81,16 +95,40 @@ public class MyGameScript : MonoBehaviour
8195
</activity>
8296

8397
<meta-data
84-
android:name="channelName"
85-
android:value="myCustomChannel" />
98+
android:name="channel"
99+
android:value="android_cn_taptap" />
100+
101+
<meta-data
102+
android:name="sub_channel"
103+
android:value="beta" />
86104

87105
<!-- 其他 meta-data -->
88106
</application>
89107
```
90108

91-
然后,您可以在 C# 代码中通过 `BlankGetChannel.GetChannelName("channelName")` 来获取这个值 (`myCustomChannel`)。
109+
然后,您可以在 C# 代码中通过 `BlankGetChannel.GetChannelName("channel")` 来获取这个值。
110+
111+
### 4. Editor / PC / WebGL / UWP / 主机平台设置
112+
113+
对于 Editor、PC(Windows/Mac/Linux)、WebGL、UWP、PS4、PS5、Xbox One、Nintendo Switch 等平台,您需要在 Unity 项目的 `Resources` 文件夹下创建一个名为 `app_info.txt` 的文本文件。
114+
115+
**app_info.txt 文件格式示例:**
116+
117+
```
118+
channel=editor_cn_test
119+
sub_channel=beta
120+
other_key=other_value
121+
```
122+
123+
每行格式为:`键名=值`
124+
125+
插件会自动读取该文件中的键值对,并缓存起来供后续使用。
92126

93127
## 注意事项
94128

95-
- 确保您在调用 `BlankGetChannel.GetChannelName(string key)` 时使用的 `key` 与您在 `Info.plist` (iOS) 或 `AndroidManifest.xml` (Android) 中设置的键名一致。
129+
- 确保您在调用 `BlankGetChannel.GetChannelName(string key)` 时使用的 `key` 与您在对应平台的配置文件中设置的键名一致:
130+
- **iOS / tvOS / visionOS**`Info.plist` 文件
131+
- **Android**`AndroidManifest.xml` 文件中的 `<meta-data>` 标签
132+
- **Editor / PC / WebGL / UWP / 主机平台**`Resources/app_info.txt` 文件
96133
- 插件包含 `link.xml` 文件以防止代码被 Unity 的代码裁剪功能移除。
134+
- `GetChannelName()` 方法会缓存渠道信息,避免重复读取配置文件,提高性能。

0 commit comments

Comments
 (0)