Skip to content

Commit 36da128

Browse files
author
Ocean
committed
2 parents 4aef33c + 1e98b80 commit 36da128

File tree

129 files changed

+17505
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+17505
-169
lines changed

.config/.vitepress/config.mts

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export default defineConfig({
118118
{ text: "优化Unity WebGL的渲染性能", link: "/Design/RenderOptimization" },
119119
{ text: "定制微信小游戏的 URP 管线", link: "/Design/CustomURP" },
120120
{ text: "WebGL2.0渲染支持说明", link: "/Design/WebGL2" },
121+
{ text: "性能深度分析工具", link: "/Design/DeepProfileTool" },
122+
{ text: "高精度时间", link: "/Design/HighPreciseTime" },
121123
],
122124
},
123125
],
@@ -141,7 +143,8 @@ export default defineConfig({
141143
{ text: "后端服务指引", link: "/Design/BackendServiceStartup" },
142144
{ text: "网络通信适配", link: "/Design/UsingNetworking" },
143145
{ text: "使用水印保护代码包安全", link: "/Design/wasmWaterMark" },
144-
{ text: "配置构建模板", link: "/Design/BuildTemplate.md" }
146+
{ text: "配置构建模板", link: "/Design/BuildTemplate.md" },
147+
{ text: "实时预览工具", link: "/Design/WechatPreview.md" },
145148
],
146149
},
147150
{

Demo/API_V2/Assets/API/APISO.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ MonoBehaviour:
1919
- {fileID: 11400000, guid: 9977a581037b84833a32b508e00eb1a2, type: 2}
2020
- {fileID: 11400000, guid: 56f316e0e10ba419bbf19bd7a68bfc4c, type: 2}
2121
- {fileID: 11400000, guid: 6f0972f5fdc56c543b23c9873d760bf5, type: 2}
22-
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
2322
- {fileID: 11400000, guid: 7ef06699cee7846b7823e4cc421418eb, type: 2}
23+
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
2424
- {fileID: 11400000, guid: 55de20d536f8c4689bbd80553d87fe46, type: 2}
2525
- {fileID: 11400000, guid: f2c56d751bb7c4c398db7c1db352517d, type: 2}
2626
- {fileID: 11400000, guid: b4a6196f623dd4435a4f3bd70af92d06, type: 2}

Demo/API_V2/Assets/API/Facility/FacilitySO.asset

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ MonoBehaviour:
1515
categoryName: "\u8BBE\u5907"
1616
categorySprite: {fileID: 21300000, guid: 53dd2b1922e5142ec8a53037f362fc56, type: 3}
1717
entryList:
18-
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
19-
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
2018
- {fileID: 11400000, guid: a24af43ae51914d26b0bf637c283dab2, type: 2}
2119
- {fileID: 11400000, guid: 4eba2c9f2f2064e4081be74302ca4c33, type: 2}
20+
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
21+
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
2222
- {fileID: 11400000, guid: ac09abff5d8bc48bbabd08bde820b58b, type: 2}
2323
- {fileID: 11400000, guid: 3bf339b994c544db3860ddf0a0dc8e20, type: 2}
2424
- {fileID: 11400000, guid: e92d94924be504167a342e42e1162f21, type: 2}

Demo/API_V2/Assets/API/Facility/Screen/ScreenSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ MonoBehaviour:
2626
- buttonText: "\u67E5\u8BE2\u7528\u6237\u662F\u5426\u5728\u5F55\u5C4F"
2727
- buttonText: "\u83B7\u53D6\u5C4F\u5E55\u4EAE\u5EA6"
2828
initialResultList: []
29+
entryOrder: 0

Demo/API_V2/Assets/API/FileSystem/FileSystemSO.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ MonoBehaviour:
2424
- {fileID: 11400000, guid: 65ab1b01a722b4542a14fcf9decca3de, type: 2}
2525
- {fileID: 11400000, guid: 19b80cb144f0c4ea28a4ddca7a2c2f09, type: 2}
2626
- {fileID: 11400000, guid: 0aa5d76237c844275add1612c47bddaa, type: 2}
27-
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
2827
- {fileID: 11400000, guid: 65a826f5f949544d8990e673231bb80f, type: 2}
28+
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
2929
- {fileID: 11400000, guid: 3a901e80b59ad4aafbe373ee6a8df2d8, type: 2}
3030
- {fileID: 11400000, guid: e7ea0be62dc6543b0a8dc629489c5e7e, type: 2}
3131
categoryOrder: 11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using UnityEngine;
2+
using TMPro;
3+
4+
// 添加 Text 组件的依赖
5+
[RequireComponent(typeof(TMP_Text))]
6+
public class TMPTextInit : MonoBehaviour
7+
{
8+
private TMP_Text _text;
9+
10+
11+
private void Awake()
12+
{
13+
// 获取 Text 组件
14+
_text = GetComponent<TMP_Text>();
15+
}
16+
17+
private void Start()
18+
{
19+
// 如果 GameManager 的字体已经加载,直接设置 Text 的字体
20+
if (GameManager.Instance.font != null)
21+
{
22+
_text.font = GameManager.Instance.fonts;
23+
}
24+
else
25+
{
26+
// 如果字体还未加载,添加字体加载事件监听器
27+
GameManager.Instance.OnTMPFontLoaded += OnFontLoaded;
28+
}
29+
}
30+
31+
private void OnDestroy()
32+
{
33+
// 移除字体加载事件监听器
34+
GameManager.Instance.OnTMPFontLoaded -= OnFontLoaded;
35+
}
36+
37+
// 当字体加载完成时,设置 Text 的字体
38+
private void OnFontLoaded(TMP_FontAsset fonts)
39+
{
40+
_text.font = fonts;
41+
}
42+
}

Demo/API_V2/Assets/API/InputField/TmpTextInit.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/InputField/WXInputFieldAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private void ShowKeyboard()
6262

6363
WX.ShowKeyboard(new ShowKeyboardOption()
6464
{
65-
defaultValue = "xxx",
65+
defaultValue = _inputField.text,
6666
maxLength = 20,
6767
confirmType = "go"
6868
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using UnityEngine;
2+
using WeChatWASM;
3+
using TMPro;
4+
using UnityEngine.EventSystems;
5+
6+
// 要求该组件必须附加 TMP_InputField 组件
7+
[RequireComponent(typeof(TMP_InputField))]
8+
public class WXInputFieldTmpAdapter : MonoBehaviour, IPointerClickHandler, IPointerExitHandler
9+
{
10+
private TMP_InputField _inputField; // 存储 TMP_InputField 组件的引用
11+
private bool _isShowKeyboard = false; // 标记键盘是否显示
12+
13+
private void Start()
14+
{
15+
// 获取挂载在同一游戏对象上的 TMP_InputField 组件
16+
_inputField = GetComponent<TMP_InputField>();
17+
}
18+
19+
// 当指针点击该组件时调用
20+
public void OnPointerClick(PointerEventData eventData)
21+
{
22+
ShowKeyboard(); // 显示键盘
23+
}
24+
25+
// 当指针离开该组件时调用
26+
public void OnPointerExit(PointerEventData eventData)
27+
{
28+
// 如果 TMP_InputField 没有被聚焦,则隐藏键盘
29+
if (!_inputField.isFocused)
30+
{
31+
HideKeyboard();
32+
}
33+
}
34+
35+
// 输入法输入回调
36+
private void OnInput(OnKeyboardInputListenerResult v)
37+
{
38+
// 如果 TMP_InputField 被聚焦,则将输入值赋给 TMP_InputField
39+
if (_inputField.isFocused)
40+
{
41+
_inputField.text = v.value;
42+
}
43+
}
44+
45+
// 输入法确认回调
46+
private void OnConfirm(OnKeyboardInputListenerResult v)
47+
{
48+
HideKeyboard(); // 隐藏键盘
49+
}
50+
51+
// 输入法完成回调
52+
private void OnComplete(OnKeyboardInputListenerResult v)
53+
{
54+
HideKeyboard(); // 隐藏键盘
55+
}
56+
57+
// 显示键盘的方法
58+
private void ShowKeyboard()
59+
{
60+
// 如果键盘已经显示,则直接返回
61+
if (_isShowKeyboard) return;
62+
63+
// 调用 WeChat API 显示键盘
64+
WX.ShowKeyboard(new ShowKeyboardOption()
65+
{
66+
defaultValue = _inputField.text,//传入当前文本作为默认值
67+
maxLength = 20, // 最大输入长度
68+
confirmType = "go" // 确认按钮类型
69+
});
70+
71+
// 绑定键盘事件回调
72+
WX.OnKeyboardConfirm(this.OnConfirm);
73+
WX.OnKeyboardComplete(this.OnComplete);
74+
WX.OnKeyboardInput(this.OnInput);
75+
_isShowKeyboard = true; // 更新键盘显示状态
76+
}
77+
78+
// 隐藏键盘的方法
79+
private void HideKeyboard()
80+
{
81+
// 如果键盘未显示,则直接返回
82+
if (!_isShowKeyboard) return;
83+
84+
// 调用 WeChat API 隐藏键盘
85+
WX.HideKeyboard(new HideKeyboardOption());
86+
// 移除事件监听
87+
WX.OffKeyboardInput(this.OnInput);
88+
WX.OffKeyboardConfirm(this.OnConfirm);
89+
WX.OffKeyboardComplete(this.OnComplete);
90+
_isShowKeyboard = false; // 更新键盘显示状态
91+
}
92+
}

Demo/API_V2/Assets/API/InputField/WXInputFieldTmpAdapter.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Media/CameraAPI/CameraAPISO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ MonoBehaviour:
2222
initialButtonText: "\u5F00\u59CB\u76D1\u542C\u5E27\u6570\u636E"
2323
extraButtonList: []
2424
initialResultList: []
25+
entryOrder: 0

Demo/API_V2/Assets/API/Media/MediaSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ MonoBehaviour:
1717
entryList:
1818
- {fileID: 11400000, guid: 1d998af43281d4eee9e1effc8f83bddd, type: 2}
1919
- {fileID: 11400000, guid: 1055cfc5cdda7407298fa2ff9997d0c6, type: 2}
20+
- {fileID: 11400000, guid: 480646e3cd4d6a948a7538d483c1b043, type: 2}
2021
- {fileID: 11400000, guid: ad04526c3748b4e2b8498f998dfea973, type: 2}
2122
- {fileID: 11400000, guid: 38b7b2300105146ce94a785a915252de, type: 2}
2223
- {fileID: 11400000, guid: 04a7c5dbfc2464252841043ba677dcab, type: 2}

Demo/API_V2/Assets/API/Media/PlayLocalFileAudio.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Collections;
3+
using UnityEngine;
4+
using UnityEngine.Networking;
5+
using WeChatWASM;
6+
7+
public class PlayLocalFileAudio : Details
8+
{
9+
public AudioSource audioSource;
10+
public AudioClip currentAudioClip;
11+
12+
private void Awake()
13+
{
14+
audioSource = GetComponent<AudioSource>();
15+
if (audioSource == null)
16+
{
17+
audioSource = gameObject.AddComponent<AudioSource>();
18+
}
19+
}
20+
21+
private void DownloadFileAudio()
22+
{
23+
WX.DownloadFile(new DownloadFileOption()
24+
{
25+
url = "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20220901/211827/CallMeTeenTop.mp3",
26+
success = (res) =>
27+
{
28+
Debug.Log("WX.DownloadFile success");
29+
if (res.statusCode == 200)
30+
{
31+
Debug.Log(res.tempFilePath);
32+
var fs = WX.GetFileSystemManager();
33+
var filePath = fs.SaveFileSync(res.tempFilePath, WX.env.USER_DATA_PATH + "/CallMeTeenTop.mp3");
34+
StartCoroutine(LoadAndPlayAudio(filePath));
35+
}
36+
},
37+
fail = (res) =>
38+
{
39+
Debug.Log("WX.DownloadFile fail");
40+
},
41+
complete = (res) =>
42+
{
43+
Debug.Log("WX.DownloadFile complete");
44+
}
45+
});
46+
}
47+
48+
IEnumerator LoadAndPlayAudio(string localFilePath)
49+
{
50+
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(new Uri(localFilePath), AudioType.MPEG))
51+
{
52+
yield return www.SendWebRequest();
53+
54+
if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
55+
{
56+
Debug.LogError(www.error);
57+
}
58+
else
59+
{
60+
AudioClip audioClip = DownloadHandlerAudioClip.GetContent(www);
61+
62+
audioSource.clip = audioClip;
63+
audioSource.Play();
64+
}
65+
}
66+
}
67+
private void CleanupAudio()
68+
{
69+
if (audioSource != null)
70+
{
71+
audioSource.Stop();
72+
audioSource.clip = null;
73+
}
74+
75+
if (currentAudioClip != null)
76+
{
77+
Destroy(currentAudioClip);
78+
currentAudioClip = null;
79+
}
80+
}
81+
protected override void TestAPI(string[] args)
82+
{
83+
DownloadFileAudio();
84+
}
85+
86+
private void OnDestroy()
87+
{
88+
CleanupAudio();
89+
}
90+
}

Demo/API_V2/Assets/API/Media/PlayLocalFileAudio/PlayLocalFileAudio.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: PlayLocalFileAudioSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: PlayLocalFileAudio
16+
entryName: "\u64AD\u653E\u672C\u5730\u6587\u4EF6\u8DEF\u5F84\u97F3\u9891"
17+
entryAPI:
18+
entryDescription: "\u8BE5\u529F\u80FD\u9700\u8981\u4FEE\u6539UnityPlugin\u7248\u672C\u4E3A1.2.68\u4EE5\u4E0A"
19+
optionList: []
20+
initialButtonText: "\u64AD\u653E\u672C\u5730\u8DEF\u5F84\u7684\u97F3\u9891"
21+
extraButtonList: []
22+
initialResultList: []
23+
entryOrder: 0

Demo/API_V2/Assets/API/Media/PlayLocalFileAudio/PlayLocalFileAudioSO.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoderSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ MonoBehaviour:
2323
- buttonText: "\u8DF3\u8F6C"
2424
- buttonText: "\u83B7\u5F97\u4E0B\u4E00\u5E27"
2525
initialResultList: []
26+
entryOrder: 0

Demo/API_V2/Assets/API/Render/RenderSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ MonoBehaviour:
1717
entryList:
1818
- {fileID: 11400000, guid: 3742edf3f50854504ba8632134064e94, type: 2}
1919
- {fileID: 11400000, guid: c185ac653050d49608ea734a26e8dbaa, type: 2}
20+
- {fileID: 11400000, guid: f9a70ffa3b7f4db40b550f6b153c4ed2, type: 2}
2021
categoryOrder: 8
Binary file not shown.

0 commit comments

Comments
 (0)