Skip to content

Commit 43ecdf9

Browse files
committed
userinfo-demo
1 parent bc72699 commit 43ecdf9

File tree

7 files changed

+2594
-279
lines changed

7 files changed

+2594
-279
lines changed

Demo/API_V2/Assets/API/OpenInterface/UserInfo.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.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
using System.Threading;
7+
8+
public class UserInfo : Details
9+
{
10+
private WXUserInfoButton _button;
11+
12+
private readonly Action<WXUserInfoResponse> _onTap = (res) => {
13+
var result = "onTap\n" + JsonMapper.ToJson(res);
14+
GameManager.Instance.detailsController.AddResult(new ResultData()
15+
{
16+
initialContentText = result
17+
});
18+
};
19+
20+
21+
private void Start()
22+
{
23+
StartCoroutine(SetTimeout(1.0f));
24+
}
25+
26+
IEnumerator SetTimeout(float delay)
27+
{
28+
yield return new WaitForSeconds(delay);
29+
30+
Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
31+
Vector2 position = GameManager.Instance.detailsController.GetInitialButtonPosition();
32+
Debug.Log(position);
33+
Debug.Log(size);
34+
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x), Math.Abs((int)position.y), (int)size.x, (int)size.y, "en", true);
35+
_button.OnTap(_onTap);
36+
}
37+
38+
39+
// 测试 API
40+
protected override void TestAPI(string[] args){}
41+
42+
// 微信小游戏示例 demo
43+
public void getUserInfo() {
44+
WX.GetSetting(new GetSettingOption
45+
{
46+
success = (res) => {
47+
Debug.Log("GetSetting\n" + JsonMapper.ToJson(res));
48+
if (res.authSetting["scope.userInfo"]) {
49+
WX.GetUserInfo(new GetUserInfoOption
50+
{
51+
success = (res) => {
52+
Debug.Log("getuserinfo\n" + JsonMapper.ToJson(res));
53+
}
54+
});
55+
} else {
56+
// 参数依次为 x, y, width, height, lang, withCredentials
57+
WXUserInfoButton button = WX.CreateUserInfoButton(20, 20, 400, 200, "en", true);
58+
button.OnTap(_onTap);
59+
}
60+
}
61+
});
62+
}
63+
64+
private void OnDestroy()
65+
{
66+
_button.Destroy();
67+
}
68+
}

Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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: UserInfoSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: UserInfo
16+
entryName: "\u83B7\u53D6\u7528\u6237\u4FE1\u606F"
17+
entryAPI: getUserINfo, createUserInfoButton
18+
entryDescription:
19+
optionList: []
20+
initialButtonText: "\u83B7\u53D6\u7528\u6237\u4FE1\u606F"
21+
extraButtonList: []
22+
initialResultList: []

Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfoSO.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)