Skip to content

Commit 955c86a

Browse files
committed
在需要加载的地方插入加载ui
1 parent 1807a30 commit 955c86a

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

Assets/Script/Handler.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ private struct Message
1717
[JsonProperty("data")] public JToken Data; // 用 string 来接收原始 JSON
1818
}
1919

20+
private struct Error
21+
{
22+
[JsonProperty("message")] public string Msg;
23+
}
24+
2025
private static readonly Dictionary<string, Action<int, JToken>> Actions = new()
2126
{
2227
{ "LoginResp", _loginResp },
2328
{ "LobbyListResp", _lobbyListResp },
29+
{"JoinRoomResp", _joinRoomResp},
2430
{ "RoomInfo", _roomInfo },
2531
{ "PlayerReady", _playerReady },
2632
{ "PlayerLeave", _playerLeave },
@@ -71,6 +77,13 @@ private static void _lobbyListResp(int code, JToken obj)
7177
UIManager.Instance.ChangePanel("Lobby");
7278
}
7379

80+
private static void _joinRoomResp(int code, JToken obj)
81+
{
82+
if (code != 1) return;
83+
var data = obj.ToObject<Error>();
84+
UIManager.Instance.ChangeLoadingText(data.Msg);
85+
}
86+
7487
private static void _roomInfo(int code, JToken obj)
7588
{
7689
if (code == 0)

Assets/Script/UI/CreateRoomPanel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void OnConfirmButtonClicked()
3838
GameMode = "Classic",
3939
MaxPlayer = _playerCount
4040
};
41+
UIManager.Instance.ChangePanel("Loading");
4142
NetworkManager.Instance.Send("CreateRoom", JToken.FromObject(data));
4243
//UIManager.Instance.ChangePanel("Room");
4344
}

Assets/Script/UI/RoomButton.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void Init(RoomLobbyView roomInfo)
2323
public void OnRoomButtonClicked()
2424
{
2525
var data = new JoinRoom { RoomId = _roomId };
26+
UIManager.Instance.ChangePanel("Loading");
2627
NetworkManager.Instance.Send("JoinRoom",JToken.FromObject(data));
2728
// UIManager.Instance.ChangePanel("Room");
2829
}

Assets/Script/UI/UIManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public void ChangePanel(string panelName)
3030
// Debug.Log($"Change to {currentPanel}");
3131
}
3232

33+
public void ChangeLoadingText(string text)
34+
{
35+
Instance.loadingPanel.tmpText.text = text;
36+
}
37+
3338
private void Awake()
3439
{
3540
_panels = new Dictionary<string, GameObject>

0 commit comments

Comments
 (0)