Skip to content

Commit 1298b35

Browse files
committed
Merge branch 'TMP_InputField-Demo' into TMP_InputField
2 parents ce3fa02 + e26d85d commit 1298b35

File tree

93 files changed

+18395
-120
lines changed

Some content is hidden

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

93 files changed

+18395
-120
lines changed

Demo/API_V2/Assets/API/APISO.asset

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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/Screen.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class Screen : Details
2828
);
2929
};
3030

31+
public static float height { get; internal set; }
32+
3133
private void Start()
3234
{
3335
GameManager.Instance.detailsController.BindExtraButtonAction(0, setScreenBrightness);

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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using TMPro;
4+
5+
// 添加 Text 组件的依赖
6+
[RequireComponent(typeof(TMP_Text))]
7+
public class TMPTextInit : MonoBehaviour
8+
{
9+
private TMP_Text _text;
10+
11+
12+
private void Awake()
13+
{
14+
// 获取 Text 组件
15+
_text = GetComponent<TMP_Text>();
16+
}
17+
18+
private void Start()
19+
{
20+
// 如果 GameManager 的字体已经加载,直接设置 Text 的字体
21+
if (GameManager.Instance.font != null)
22+
{
23+
_text.font = GameManager.Instance.fonts;
24+
}
25+
else
26+
{
27+
// 如果字体还未加载,添加字体加载事件监听器
28+
GameManager.Instance.OnTMPFontLoaded += OnFontLoaded;
29+
}
30+
}
31+
32+
private void OnDestroy()
33+
{
34+
// 移除字体加载事件监听器
35+
GameManager.Instance.OnTMPFontLoaded -= OnFontLoaded;
36+
}
37+
38+
// 当字体加载完成时,设置 Text 的字体
39+
private void OnFontLoaded(TMP_FontAsset fonts)
40+
{
41+
_text.font = fonts;
42+
}
43+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using UnityEngine; // 引入 Unity 引擎命名空间
2+
using WeChatWASM; // 引入 WeChat WASM 命名空间
3+
using TMPro; // 引入 TextMeshPro 命名空间
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+
Debug.Log("OnPointerClick"); // 输出点击事件日志
23+
ShowKeyboard(); // 显示键盘
24+
}
25+
26+
// 当指针离开该组件时调用
27+
public void OnPointerExit(PointerEventData eventData)
28+
{
29+
Debug.Log("OnPointerExit"); // 输出离开事件日志
30+
// 如果 TMP_InputField 没有被聚焦,则隐藏键盘
31+
if (!_inputField.isFocused)
32+
{
33+
HideKeyboard();
34+
}
35+
}
36+
37+
// 输入法输入回调
38+
private void OnInput(OnKeyboardInputListenerResult v)
39+
{
40+
Debug.Log("onInput"); // 输出输入事件日志
41+
Debug.Log(v.value); // 输出输入的值
42+
// 如果 TMP_InputField 被聚焦,则将输入值赋给 TMP_InputField
43+
if (_inputField.isFocused)
44+
{
45+
_inputField.text = v.value;
46+
}
47+
}
48+
49+
// 输入法确认回调
50+
private void OnConfirm(OnKeyboardInputListenerResult v)
51+
{
52+
Debug.Log("onConfirm"); // 输出确认事件日志
53+
Debug.Log(v.value); // 输出确认的值
54+
HideKeyboard(); // 隐藏键盘
55+
}
56+
57+
// 输入法完成回调
58+
private void OnComplete(OnKeyboardInputListenerResult v)
59+
{
60+
Debug.Log("OnComplete"); // 输出完成事件日志
61+
Debug.Log(v.value); // 输出完成的值
62+
HideKeyboard(); // 隐藏键盘
63+
}
64+
65+
// 显示键盘的方法
66+
private void ShowKeyboard()
67+
{
68+
// 如果键盘已经显示,则直接返回
69+
if (_isShowKeyboard) return;
70+
71+
// 调用 WeChat API 显示键盘
72+
WX.ShowKeyboard(new ShowKeyboardOption()
73+
{
74+
defaultValue = "xxx", // 键盘默认值
75+
maxLength = 20, // 最大输入长度
76+
confirmType = "go" // 确认按钮类型
77+
});
78+
79+
// 绑定键盘事件回调
80+
WX.OnKeyboardConfirm(this.OnConfirm);
81+
WX.OnKeyboardComplete(this.OnComplete);
82+
WX.OnKeyboardInput(this.OnInput);
83+
_isShowKeyboard = true; // 更新键盘显示状态
84+
}
85+
86+
// 隐藏键盘的方法
87+
private void HideKeyboard()
88+
{
89+
// 如果键盘未显示,则直接返回
90+
if (!_isShowKeyboard) return;
91+
92+
// 调用 WeChat API 隐藏键盘
93+
WX.HideKeyboard(new HideKeyboardOption());
94+
// 移除事件监听
95+
WX.OffKeyboardInput(this.OnInput);
96+
WX.OffKeyboardConfirm(this.OnConfirm);
97+
WX.OffKeyboardComplete(this.OnComplete);
98+
_isShowKeyboard = false; // 更新键盘显示状态
99+
}
100+
}

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

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

Demo/API_V2/Assets/API/Render/SetFont/LiberationSans SDF.asset

Lines changed: 2981 additions & 0 deletions
Large diffs are not rendered by default.

Demo/API_V2/Assets/API/Render/SetFont/LiberationSans SDF.asset.meta

Lines changed: 8 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)