Skip to content

Commit 4fb6880

Browse files
committed
fix: API_V2 移除废弃的SystemInfo接口
1 parent 35b4ae1 commit 4fb6880

File tree

14 files changed

+385
-245
lines changed

14 files changed

+385
-245
lines changed

Demo/API_V2/Assets/API/Media/WXVideo/WXvideo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void Start()
1919

2020
private void AutoPlayVideo()
2121
{
22-
var systemInfo = WX.GetSystemInfoSync();
22+
var windowInfo = GameManager.Instance.WindowInfo;
2323
_video = WX.CreateVideo(
2424
new WXCreateVideoParam()
2525
{
@@ -31,8 +31,8 @@ private void AutoPlayVideo()
3131
autoplay = true,
3232
showCenterPlayBtn = false,
3333
underGameView = true,
34-
width = ((int)systemInfo.screenWidth),
35-
height = ((int)systemInfo.screenHeight),
34+
width = ((int)windowInfo.screenWidth),
35+
height = ((int)windowInfo.screenHeight),
3636
}
3737
);
3838
_video.OnPlay(() =>

Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocket.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using LitJson;
41
using UnityEngine;
52
using WeChatWASM;
63

Demo/API_V2/Assets/API/OpenInterface/GameClub/GameClub.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
22
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Threading;
5-
using LitJson;
63
using UnityEngine;
74
using WeChatWASM;
85

@@ -29,17 +26,17 @@ IEnumerator CreateGameClubButton(float delay)
2926

3027
Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
3128
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(0);
32-
var systemInfo = WX.GetSystemInfoSync();
29+
var windowInfo = GameManager.Instance.WindowInfo;
3330
_gameClubButton = WX.CreateGameClubButton(
3431
new WXCreateGameClubButtonParam()
3532
{
3633
type = GameClubButtonType.text,
3734
style = new GameClubButtonStyle()
3835
{
39-
left = Math.Abs((int)(position.x / systemInfo.pixelRatio)),
40-
top = Math.Abs((int)(position.y / systemInfo.pixelRatio)),
41-
width = (int)(size.x * systemInfo.screenWidth / 1080f),
42-
height = (int)(size.y * systemInfo.screenWidth / 1080f),
36+
left = Math.Abs((int)(position.x / windowInfo.pixelRatio)),
37+
top = Math.Abs((int)(position.y / windowInfo.pixelRatio)),
38+
width = (int)(size.x * windowInfo.screenWidth / 1080f),
39+
height = (int)(size.y * windowInfo.screenWidth / 1080f),
4340
}
4441
}
4542
);

Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Threading;
54
using UnityEngine;
65
using WeChatWASM;
76

@@ -59,18 +58,18 @@ IEnumerator CreateFeedbackButton(float delay)
5958

6059
Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
6160
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(0);
62-
var systemInfo = WX.GetSystemInfoSync();
61+
var windowInfo = GameManager.Instance.WindowInfo;
6362
_feedbackButton = WX.CreateFeedbackButton(
6463
new CreateOpenSettingButtonOption()
6564
{
6665
type = "text",
6766
text = "",
6867
style = new OptionStyle()
6968
{
70-
left = Math.Abs((int)(position.x / systemInfo.pixelRatio)),
71-
top = Math.Abs((int)(position.y / systemInfo.pixelRatio)),
72-
width = (int)(size.x * systemInfo.screenWidth / 1080f),
73-
height = (int)(size.y * systemInfo.screenWidth / 1080f),
69+
left = Math.Abs((int)(position.x / windowInfo.pixelRatio)),
70+
top = Math.Abs((int)(position.y / windowInfo.pixelRatio)),
71+
width = (int)(size.x * windowInfo.screenWidth / 1080f),
72+
height = (int)(size.y * windowInfo.screenWidth / 1080f),
7473
}
7574
}
7675
);

Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ IEnumerator SetTimeout(float delay)
3030
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(-1);
3131
Debug.Log(position);
3232
Debug.Log(size);
33-
var systemInfo = WX.GetSystemInfoSync();
34-
var canvasWidth = (int)(systemInfo.screenWidth * systemInfo.pixelRatio);
35-
var canvasHeight = (int)(systemInfo.screenHeight * systemInfo.pixelRatio);
33+
var windowInfo = GameManager.Instance.WindowInfo;
34+
var canvasWidth = (int)(windowInfo.screenWidth * windowInfo.pixelRatio);
35+
var canvasHeight = (int)(windowInfo.screenHeight * windowInfo.pixelRatio);
3636
_button = WX.CreateUserInfoButton(
3737
Math.Abs((int)position.x),
3838
Math.Abs((int)position.y),

Demo/API_V2/Assets/Scenes/MainScene.unity

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 170076734}
41-
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657886, g: 0.49641275, b: 0.5748176, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -6075,7 +6075,7 @@ LightingSettings:
60756075
m_AlbedoBoost: 1
60766076
m_IndirectOutputScale: 1
60776077
m_UsingShadowmask: 1
6078-
m_BakeBackend: 1
6078+
m_BakeBackend: 2
60796079
m_LightmapMaxSize: 512
60806080
m_BakeResolution: 10
60816081
m_Padding: 2
@@ -24723,8 +24723,8 @@ MonoBehaviour:
2472324723
m_EditorClassIdentifier:
2472424724
detailsController: {fileID: 0}
2472524725
font: {fileID: 0}
24726-
_mainCanvas: {fileID: 0}
24727-
_detailsCanvas: {fileID: 0}
24726+
mainCanvas: {fileID: 0}
24727+
detailsCanvas: {fileID: 0}
2472824728
--- !u!4 &1274177269
2472924729
Transform:
2473024730
m_ObjectHideFlags: 0

Demo/API_V2/Assets/Scripts/APIController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private void Start()
2929
// 根据系统安全区域调整标题的位置
3030
title.anchoredPosition = new Vector2(
3131
title.anchoredPosition.x,
32-
-125f - (float)GameManager.Instance.systemInfo.safeArea.top
32+
-125f - (float)GameManager.Instance.WindowInfo.safeArea.top
3333
);
3434
}
3535

Demo/API_V2/Assets/Scripts/DetailsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public class DetailsController : MonoBehaviour
6565
private void Start()
6666
{
6767
var res = WX.GetMenuButtonBoundingClientRect();
68-
var info = WX.GetSystemInfoSync();
68+
var info = GameManager.Instance.WindowInfo;
6969
float height = (float)res.height;
70-
float safeArea = (float)GameManager.Instance.systemInfo.safeArea.top;
70+
float safeArea = (float)GameManager.Instance.WindowInfo.safeArea.top;
7171
// 根据系统安全区域调整标题和返回按钮的位置
7272
titleTransform.anchoredPosition = new Vector2(
7373
titleTransform.anchoredPosition.x,

Demo/API_V2/Assets/Scripts/GameManager.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using UnityEngine;
55
using UnityEngine.SceneManagement;
66
using WeChatWASM;
7-
using SystemInfo = WeChatWASM.SystemInfo;
87

98
public class GameManager : MonoBehaviour
109
{
@@ -18,20 +17,20 @@ public class GameManager : MonoBehaviour
1817
// 字体相关
1918
[Header("Font")]
2019
public Font font;
21-
public Action<Font> onFontLoaded;
20+
public Action<Font> OnFontLoaded;
2221

2322
// 用于在 MainCanvas 和 DetailsCanvas 之间切换
2423
[Header("Canvas Switch")]
2524
[SerializeField]
26-
private GameObject _mainCanvas;
25+
private GameObject mainCanvas;
2726

2827
[SerializeField]
29-
private GameObject _detailsCanvas;
28+
private GameObject detailsCanvas;
3029
private bool _isMainCanvasActive = true;
3130

3231
// 用于获取微信小游戏的系统信息
3332
[Header("System Info")]
34-
public SystemInfo systemInfo;
33+
public WindowInfo WindowInfo;
3534

3635
private void Awake()
3736
{
@@ -60,34 +59,38 @@ private void Awake()
6059
var fallbackFont = Application.streamingAssetsPath + "/Fz.ttf";
6160
WX.GetWXFont(
6261
fallbackFont,
63-
(font) =>
62+
(wxFont) =>
6463
{
65-
if (!font)
64+
if (!wxFont)
6665
return;
6766

68-
this.font = font;
69-
onFontLoaded?.Invoke(font);
67+
this.font = wxFont;
68+
OnFontLoaded?.Invoke(wxFont);
7069
}
7170
);
7271

7372
// 获取微信小游戏的系统信息
74-
systemInfo = WX.GetSystemInfoSync();
73+
#if UNITY_WEBGL && !UNITY_EDITOR
74+
WindowInfo = WX.GetWindowInfo();
75+
#else
76+
WindowInfo = new WindowInfo { safeArea = new SafeArea() };
77+
#endif
7578
}
7679
);
7780
}
7881

7982
private void Start()
8083
{
81-
_mainCanvas.SetActive(true);
82-
_detailsCanvas.SetActive(false);
84+
mainCanvas.SetActive(true);
85+
detailsCanvas.SetActive(false);
8386
}
8487

8588
// 切换 MainCanvas 和 DetailsCanvas 的显示状态
8689
public void SwitchCanvas()
8790
{
8891
_isMainCanvasActive = !_isMainCanvasActive;
89-
_mainCanvas.SetActive(_isMainCanvasActive);
90-
_detailsCanvas.SetActive(!_isMainCanvasActive);
92+
mainCanvas.SetActive(_isMainCanvasActive);
93+
detailsCanvas.SetActive(!_isMainCanvasActive);
9194
}
9295

9396
// 加载指定名称的场景
@@ -102,7 +105,7 @@ private IEnumerator LoadSceneAsync(string sceneName)
102105
var asyncOperation = SceneManager.LoadSceneAsync(sceneName);
103106

104107
// 等待场景加载完成
105-
while (!asyncOperation.isDone)
108+
while (asyncOperation != null && !asyncOperation.isDone)
106109
{
107110
yield return null;
108111
}
@@ -117,17 +120,17 @@ private IEnumerator LoadSceneAsync(string sceneName)
117120
// 获取场景中的引用
118121
private void GetReferences()
119122
{
120-
_mainCanvas = GetSceneRootGO("Main Canvas");
121-
_detailsCanvas = GetSceneRootGO("Details Canvas");
122-
detailsController = _detailsCanvas.GetComponent<DetailsController>();
123+
mainCanvas = GetSceneRootGO("Main Canvas");
124+
detailsCanvas = GetSceneRootGO("Details Canvas");
125+
detailsController = detailsCanvas.GetComponent<DetailsController>();
123126
}
124127

125128
// 根据名称获取场景中的根游戏对象
126-
public GameObject GetSceneRootGO(string name)
129+
private GameObject GetSceneRootGO(string goName)
127130
{
128131
// 获取当前场景中的所有根物体
129132
var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects();
130133
// 遍历所有顶层游戏对象,找到名字为name的游戏对象则返回,否则返回null
131-
return rootObjects.FirstOrDefault(obj => obj.name == name);
134+
return rootObjects.FirstOrDefault(obj => obj.name == goName);
132135
}
133136
}

Demo/API_V2/Assets/Scripts/TextInit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ private void Start()
2323
else
2424
{
2525
// 如果字体还未加载,添加字体加载事件监听器
26-
GameManager.Instance.onFontLoaded += OnFontLoaded;
26+
GameManager.Instance.OnFontLoaded += OnFontLoaded;
2727
}
2828
}
2929

3030
private void OnDestroy()
3131
{
3232
// 移除字体加载事件监听器
33-
GameManager.Instance.onFontLoaded -= OnFontLoaded;
33+
GameManager.Instance.OnFontLoaded -= OnFontLoaded;
3434
}
3535

3636
// 当字体加载完成时,设置 Text 的字体

0 commit comments

Comments
 (0)