Skip to content

Commit cbb9038

Browse files
committed
docs: 添加中文版README并更新英文版格式
- 新增 README_ZH.md 及其元文件,提供完整中文文档 - 重构英文 README.md 结构,添加语言切换导航栏 - 统一两个文档的格式和内容,确保中英文版本一致性
1 parent a16bc05 commit cbb9038

3 files changed

Lines changed: 201 additions & 50 deletions

File tree

README.md

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
1-
# Unity 获取分发渠道号 (iOS 和 Android)
1+
<div align="center">
2+
<a href="README.md">English</a> |
3+
<a href="README_ZH.md">中文</a>
4+
</div>
25

3-
本插件用于在 Unity 项目中获取 iOS 和 Android 平台的分发渠道号。它是 `https://github.com/GameFrameX/GameFrameX` 项目的一个子模块。
6+
# Unity Get Channel for iOS and Android
47

5-
## 主要功能
8+
This plugin is used to retrieve distribution channel identifiers for iOS and Android platforms in Unity projects. It is a submodule of the `https://github.com/GameFrameX/GameFrameX` project.
69

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

11-
## 如何安装
12+
- **Multi-platform support**: iOS, tvOS, visionOS, Android, Editor, PC (Windows/Mac/Linux), WebGL, UWP, PS4, PS5, Xbox One, Nintendo Switch.
13+
- Provides a simple API to retrieve predefined channel information.
14+
- Automatically adds a default channel to `Info.plist` during iOS builds (if not already set).
1215

13-
您可以通过以下三种方式将此插件添加到您的 Unity 项目中:
16+
## Installation
1417

15-
1. **通过 `manifest.json` 添加依赖:**
16-
在项目 `Packages` 目录下的 `manifest.json` 文件的 `dependencies` 节点中添加如下内容:
18+
You can add this plugin to your Unity project in one of the following three ways:
19+
20+
1. **Add via `manifest.json`:**
21+
Add the following to the `dependencies` node in the `manifest.json` file in your project's `Packages` directory:
1722
```json
1823
{
1924
"dependencies": {
2025
"com.gameframex.unity.getchannel": "https://github.com/gameframex/com.gameframex.unity.getchannel.git",
21-
// ... 其他依赖
26+
// ... other dependencies
2227
}
2328
}
2429
```
2530

26-
2. **通过 Unity Package Manager 使用 Git URL**
27-
Unity 编辑器中,打开 `Window -> Package Manager`
28-
点击左上角的 `+` 号按钮,选择 `Add package from git URL...`
29-
输入以下 URL 并点击 `Add`:
31+
2. **Via Unity Package Manager using Git URL:**
32+
In the Unity Editor, open `Window -> Package Manager`.
33+
Click the `+` button in the top-left corner and select `Add package from git URL...`.
34+
Enter the following URL and click `Add`:
3035
```
3136
https://github.com/gameframex/com.gameframex.unity.getchannel.git
3237
```
3338

34-
3. **直接下载或克隆仓库:**
35-
将此仓库下载或克隆到您 Unity 项目的 `Packages` 目录下。Unity 会自动识别并加载该插件。
39+
3. **Download or Clone Repository:**
40+
Download or clone this repository into the `Packages` directory of your Unity project. Unity will automatically recognize and load the plugin.
3641

37-
## 如何使用
42+
## Usage
3843

39-
### 1. 获取渠道号
44+
### 1. Getting Channel Information
4045

41-
在您的 C# 脚本中,使用 `BlankGetChannel.GetChannelName(string key)` 方法来获取渠道号。参数 `key` 是您在对应平台设置渠道号时使用的键名。
46+
In your C# scripts, use the `BlankGetChannel.GetChannelName(string key)` method to retrieve channel information. The `key` parameter is the key name you used when setting up the channel information on the corresponding platform.
4247

43-
**示例代码:**
48+
**Example Code:**
4449

4550
```csharp
4651
using UnityEngine;
@@ -49,30 +54,30 @@ public class MyGameScript : MonoBehaviour
4954
{
5055
void Start()
5156
{
52-
// 获取默认渠道号(键名为 "channel"
57+
// Get default channel (key name is "channel")
5358
string channel = BlankGetChannel.GetChannelName();
54-
Debug.Log("当前渠道号: " + channel);
59+
Debug.Log("Current channel: " + channel);
5560

56-
// 获取指定键的渠道号
61+
// Get channel with a specific key
5762
string customChannel = BlankGetChannel.GetChannelName("channelName");
58-
Debug.Log("自定义渠道号: " + customChannel);
63+
Debug.Log("Custom channel: " + customChannel);
5964

60-
// 获取渠道号,并指定默认值
65+
// Get channel with a default fallback value
6166
string subChannel = BlankGetChannel.GetChannelName("sub_channel", "unknown");
62-
Debug.Log("子渠道号: " + subChannel);
67+
Debug.Log("Sub channel: " + subChannel);
6368
}
6469
}
6570
```
6671

67-
### 2. iOS / tvOS / visionOS 平台设置
72+
### 2. iOS / tvOS / visionOS Platform Setup
6873

69-
对于 iOStvOS visionOS 平台,插件包含一个构建后处理器 (`PostProcessBuildHandler.cs`)。如果在构建时项目的 `Info.plist` 文件中:
70-
- **没有** 名为 `channel` 的键,该脚本会自动添加一个键为 `channel`,值为 `default` 的条目。
71-
- **已经存在** 名为 `channel` 的键,则不会进行任何修改。
74+
For iOS, tvOS, and visionOS platforms, the plugin includes a build post-processor (`PostProcessBuildHandler.cs`). When building, if the project's `Info.plist` file:
75+
- **Does not** have a key named `channel`, the script will automatically add an entry with key `channel` and value `default`.
76+
- **Already has** a key named `channel`, no modifications will be made.
7277

73-
您可以在 Xcode 项目的 `Info.plist` 文件中修改 `channel` 的值,或者在调用 `BlankGetChannel.GetChannelName()` 时使用您自定义的键名(确保该键名存在于 `Info.plist` 中)。
78+
You can modify the `channel` value in the Xcode project's `Info.plist` file, or use your custom key name when calling `BlankGetChannel.GetChannelName()` (ensure that key name exists in `Info.plist`).
7479

75-
**Info.plist 配置示例:**
80+
**Info.plist Configuration Example:**
7681

7782
```xml
7883
<key>channel</key>
@@ -82,11 +87,11 @@ public class MyGameScript : MonoBehaviour
8287
<string>beta</string>
8388
```
8489

85-
### 3. Android 平台设置
90+
### 3. Android Platform Setup
8691

87-
对于 Android 平台,您需要在 `AndroidManifest.xml` 文件中定义渠道信息。通常,这是通过在 `<application>` 标签内添加 `<meta-data>` 标签来完成的。
92+
For the Android platform, you need to define channel information in the `AndroidManifest.xml` file. This is typically done by adding `<meta-data>` tags within the `<application>` tag.
8893

89-
例如,如果您想使用键名 `channel` 和值为 `android_cn_taptap`
94+
For example, if you want to use the key name `channel` and value `android_cn_taptap`:
9095

9196
```xml
9297
<application ...>
@@ -102,33 +107,33 @@ public class MyGameScript : MonoBehaviour
102107
android:name="sub_channel"
103108
android:value="beta" />
104109

105-
<!-- 其他 meta-data -->
110+
<!-- other meta-data -->
106111
</application>
107112
```
108113

109-
然后,您可以在 C# 代码中通过 `BlankGetChannel.GetChannelName("channel")` 来获取这个值。
114+
Then, you can retrieve this value in C# code using `BlankGetChannel.GetChannelName("channel")`.
110115

111-
### 4. Editor / PC / WebGL / UWP / 主机平台设置
116+
### 4. Editor / PC / WebGL / UWP / Console Platforms Setup
112117

113-
对于 Editor、PC(Windows/Mac/Linux)、WebGLUWPPS4PS5Xbox OneNintendo Switch 等平台,您需要在 Unity 项目的 `Resources` 文件夹下创建一个名为 `app_info.txt` 的文本文件。
118+
For Editor, PC (Windows/Mac/Linux), WebGL, UWP, PS4, PS5, Xbox One, Nintendo Switch, and other platforms, you need to create a text file named `app_info.txt` in the `Resources` folder of your Unity project.
114119

115-
**app_info.txt 文件格式示例:**
120+
**app_info.txt File Format Example:**
116121

117122
```
118123
channel=editor_cn_test
119124
sub_channel=beta
120125
other_key=other_value
121126
```
122127

123-
每行格式为:`键名=值`
128+
Each line format is: `key=value`
124129

125-
插件会自动读取该文件中的键值对,并缓存起来供后续使用。
130+
The plugin will automatically read the key-value pairs from this file and cache them for subsequent use.
126131

127-
## 注意事项
132+
## Notes
128133

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` 文件
133-
- 插件包含 `link.xml` 文件以防止代码被 Unity 的代码裁剪功能移除。
134-
- `GetChannelName()` 方法会缓存渠道信息,避免重复读取配置文件,提高性能。
134+
- Ensure that the `key` you use when calling `BlankGetChannel.GetChannelName(string key)` matches the key name you set in the corresponding platform's configuration file:
135+
- **iOS / tvOS / visionOS**: `Info.plist` file
136+
- **Android**: `<meta-data>` tags in `AndroidManifest.xml` file
137+
- **Editor / PC / WebGL / UWP / Console Platforms**: `Resources/app_info.txt` file
138+
- The plugin includes a `link.xml` file to prevent code from being removed by Unity's code stripping feature.
139+
- The `GetChannelName()` method caches channel information to avoid repeated reading of configuration files, improving performance.

README_ZH.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<div align="center">
2+
<a href="README.md">English</a> |
3+
<a href="README_ZH.md">中文</a>
4+
</div>
5+
6+
# Unity 获取分发渠道号 (iOS 和 Android)
7+
8+
本插件用于在 Unity 项目中获取 iOS 和 Android 平台的分发渠道号。它是 `https://github.com/GameFrameX/GameFrameX` 项目的一个子模块。
9+
10+
## 主要功能
11+
12+
- 支持多平台:iOS、tvOS、visionOS、Android、Editor、PC(Windows/Mac/Linux)、WebGL、UWP、PS4、PS5、Xbox One、Nintendo Switch。
13+
- 提供简单的 API 来获取预设的渠道信息。
14+
- iOS 平台在构建时自动在 `Info.plist` 中添加默认渠道号 (如果未设置)。
15+
16+
## 如何安装
17+
18+
您可以通过以下三种方式将此插件添加到您的 Unity 项目中:
19+
20+
1. **通过 `manifest.json` 添加依赖:**
21+
在项目 `Packages` 目录下的 `manifest.json` 文件的 `dependencies` 节点中添加如下内容:
22+
```json
23+
{
24+
"dependencies": {
25+
"com.gameframex.unity.getchannel": "https://github.com/gameframex/com.gameframex.unity.getchannel.git",
26+
// ... 其他依赖
27+
}
28+
}
29+
```
30+
31+
2. **通过 Unity Package Manager 使用 Git URL:**
32+
在 Unity 编辑器中,打开 `Window -> Package Manager`。
33+
点击左上角的 `+` 号按钮,选择 `Add package from git URL...`。
34+
输入以下 URL 并点击 `Add`:
35+
```
36+
https://github.com/gameframex/com.gameframex.unity.getchannel.git
37+
```
38+
39+
3. **直接下载或克隆仓库:**
40+
将此仓库下载或克隆到您 Unity 项目的 `Packages` 目录下。Unity 会自动识别并加载该插件。
41+
42+
## 如何使用
43+
44+
### 1. 获取渠道号
45+
46+
在您的 C# 脚本中,使用 `BlankGetChannel.GetChannelName(string key)` 方法来获取渠道号。参数 `key` 是您在对应平台设置渠道号时使用的键名。
47+
48+
**示例代码:**
49+
50+
```csharp
51+
using UnityEngine;
52+
53+
public class MyGameScript : MonoBehaviour
54+
{
55+
void Start()
56+
{
57+
// 获取默认渠道号(键名为 "channel")
58+
string channel = BlankGetChannel.GetChannelName();
59+
Debug.Log("当前渠道号: " + channel);
60+
61+
// 获取指定键的渠道号
62+
string customChannel = BlankGetChannel.GetChannelName("channelName");
63+
Debug.Log("自定义渠道号: " + customChannel);
64+
65+
// 获取渠道号,并指定默认值
66+
string subChannel = BlankGetChannel.GetChannelName("sub_channel", "unknown");
67+
Debug.Log("子渠道号: " + subChannel);
68+
}
69+
}
70+
```
71+
72+
### 2. iOS / tvOS / visionOS 平台设置
73+
74+
对于 iOS、tvOS 和 visionOS 平台,插件包含一个构建后处理器 (`PostProcessBuildHandler.cs`)。如果在构建时项目的 `Info.plist` 文件中:
75+
- **没有** 名为 `channel` 的键,该脚本会自动添加一个键为 `channel`,值为 `default` 的条目。
76+
- **已经存在** 名为 `channel` 的键,则不会进行任何修改。
77+
78+
您可以在 Xcode 项目的 `Info.plist` 文件中修改 `channel` 的值,或者在调用 `BlankGetChannel.GetChannelName()` 时使用您自定义的键名(确保该键名存在于 `Info.plist` 中)。
79+
80+
**Info.plist 配置示例:**
81+
82+
```xml
83+
<key>channel</key>
84+
<string>ios_cn_taptap</string>
85+
86+
<key>sub_channel</key>
87+
<string>beta</string>
88+
```
89+
90+
### 3. Android 平台设置
91+
92+
对于 Android 平台,您需要在 `AndroidManifest.xml` 文件中定义渠道信息。通常,这是通过在 `<application>` 标签内添加 `<meta-data>` 标签来完成的。
93+
94+
例如,如果您想使用键名 `channel` 和值为 `android_cn_taptap`
95+
96+
```xml
97+
<application ...>
98+
<activity ...>
99+
...
100+
</activity>
101+
102+
<meta-data
103+
android:name="channel"
104+
android:value="android_cn_taptap" />
105+
106+
<meta-data
107+
android:name="sub_channel"
108+
android:value="beta" />
109+
110+
<!-- 其他 meta-data -->
111+
</application>
112+
```
113+
114+
然后,您可以在 C# 代码中通过 `BlankGetChannel.GetChannelName("channel")` 来获取这个值。
115+
116+
### 4. Editor / PC / WebGL / UWP / 主机平台设置
117+
118+
对于 Editor、PC(Windows/Mac/Linux)、WebGL、UWP、PS4、PS5、Xbox One、Nintendo Switch 等平台,您需要在 Unity 项目的 `Resources` 文件夹下创建一个名为 `app_info.txt` 的文本文件。
119+
120+
**app_info.txt 文件格式示例:**
121+
122+
```
123+
channel=editor_cn_test
124+
sub_channel=beta
125+
other_key=other_value
126+
```
127+
128+
每行格式为:`键名=值`
129+
130+
插件会自动读取该文件中的键值对,并缓存起来供后续使用。
131+
132+
## 注意事项
133+
134+
- 确保您在调用 `BlankGetChannel.GetChannelName(string key)` 时使用的 `key` 与您在对应平台的配置文件中设置的键名一致:
135+
- **iOS / tvOS / visionOS**`Info.plist` 文件
136+
- **Android**`AndroidManifest.xml` 文件中的 `<meta-data>` 标签
137+
- **Editor / PC / WebGL / UWP / 主机平台**`Resources/app_info.txt` 文件
138+
- 插件包含 `link.xml` 文件以防止代码被 Unity 的代码裁剪功能移除。
139+
- `GetChannelName()` 方法会缓存渠道信息,避免重复读取配置文件,提高性能。

README_ZH.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)