Skip to content

Commit ae04d68

Browse files
committed
修复比赛退出异常问题
1 parent 7d3eb31 commit ae04d68

File tree

10 files changed

+95
-20
lines changed

10 files changed

+95
-20
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using LitJson;
2+
using System.Text;
3+
using UnityEngine;
4+
using QFramework;
5+
using Utils;
6+
7+
public class ExitGameSceneCommand : AbstractCommand
8+
{
9+
protected override void OnExecute()
10+
{
11+
if (this.GetModel<IGameControllerModel>().CurGameType == GameType.Match)
12+
{
13+
Time.timeScale = 0;
14+
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(
15+
content: this.GetSystem<II18NSystem>().GetText("Quit the game?"),
16+
success: () => {
17+
this.SendEvent<ExitGameSceneEvent>();
18+
this.GetSystem<IPlayerManagerSystem>().peers.Clear();
19+
Time.timeScale = 1;
20+
Util.LoadingScene(SceneID.Index);
21+
},
22+
fail: () => {
23+
Time.timeScale = 1;
24+
});
25+
26+
}
27+
}
28+
}

CrazyCar/Assets/Scripts/Command/ExitGameSceneCommand.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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class ExitGameSceneEvent {
2+
3+
}

CrazyCar/Assets/Scripts/Event/ExitGameSceneEvent.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.

CrazyCar/Assets/Scripts/Game/CommonGameUI.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@ public class CommonGameUI : MonoBehaviour, IController {
1515

1616
private void Start() {
1717
exitBtn.onClick.AddListener(() => {
18-
Time.timeScale = 0;
19-
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(
20-
content: this.GetSystem<II18NSystem>().GetText("Quit the game?"),
21-
success: () => {
22-
Time.timeScale = 1;
23-
Util.LoadingScene(SceneID.Index);
24-
},
25-
fail: () => {
26-
Time.timeScale = 1;
27-
});
18+
this.SendCommand<ExitGameSceneCommand>();
2819
});
2920

3021
angleViewBtn.onClick.AddListener(() => {

CrazyCar/Assets/Scripts/Game/MPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class MPlayer : MonoBehaviour, IController {
4545
private Vector3 peerTargetPos = new Vector3();
4646

4747
private MPlayerStyle mPlayerStyle;
48-
private int destroyTimeLimit = 10000; // micro seconds
48+
private int destroyTimeLimit = 3000; // micro seconds
4949
// 出界 翻车判断
5050
private PathCreator pathCreator;
5151
private float playerHigh = 2f;

CrazyCar/Assets/Scripts/System/NetworkSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public IEnumerator POSTHTTP(string url, byte[] data = null, string token = null,
8484
}
8585

8686
private PlayerCreateMsg ParsePlayerCreateMsg(JsonData jsonData, Action success = null) {
87-
Debug.Log("Rec = " + jsonData.ToJson());
87+
Debug.LogWarning("Rec = " + jsonData.ToJson());
8888
PlayerCreateMsg playerCreateMsg = new PlayerCreateMsg();
8989
playerCreateMsg.cid = (int)jsonData["cid"];
9090
playerCreateMsg.pos = new Vector3((float)Math.Round((float)jsonData["pos_x"], 2), (float)Math.Round((float)jsonData["pos_y"], 2), (float)Math.Round((float)jsonData["pos_z"], 2));
@@ -103,7 +103,7 @@ private PlayerCreateMsg ParsePlayerCreateMsg(JsonData jsonData, Action success =
103103
}
104104

105105
private PlayerStateMsg ParsePlayerStateMsg(JsonData jsonData, Action success = null) {
106-
Debug.Log("Rec = " + jsonData.ToJson());
106+
Debug.LogWarning("Rec = " + jsonData.ToJson());
107107
PlayerStateMsg playerStateMsg = new PlayerStateMsg();
108108
playerStateMsg.cid = (int)jsonData["cid"];
109109
playerStateMsg.pos = new Vector3((float)Math.Round((float)jsonData["pos_x"], 2), (float)Math.Round((float)jsonData["pos_y"], 2), (float)Math.Round((float)jsonData["pos_z"], 2));

CrazyCar/Assets/Scripts/UI/Match/MatchNet.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using Utils;
77
using QFramework;
88

9-
public class MatchNet : MonoBehaviour,IController {
9+
public class MatchNet : MonoBehaviour, IController {
10+
private Coroutine matchNerCor;
11+
1012
private void Start() {
1113
if (this.GetModel<IGameControllerModel>().CurGameType == GameType.Match) {
1214
string ws = "ws" + this.GetSystem<INetworkSystem>().HttpBaseUrl.Substring(4) +
@@ -21,8 +23,18 @@ private void Start() {
2123
}
2224

2325
Util.DelayExecuteWithSecond(3, () => { this.SendCommand<PostCreatePlayerMsgCommand>(); });
24-
Util.DelayExecuteWithSecond(4.5f, () => { CoroutineController.manager.StartCoroutine(SendMsg()); });
25-
}
26+
Util.DelayExecuteWithSecond(4.5f, () => { matchNerCor = CoroutineController.manager.StartCoroutine(SendMsg()); });
27+
}
28+
29+
this.RegisterEvent<ExitGameSceneEvent>(OnExitGameScene).UnRegisterWhenGameObjectDestroyed(gameObject);
30+
}
31+
32+
private void OnExitGameScene(ExitGameSceneEvent e)
33+
{
34+
if (matchNerCor != null)
35+
{
36+
CoroutineController.manager.StopCoroutine(matchNerCor);
37+
}
2638
}
2739

2840
private IEnumerator SendMsg() {

CrazyCar/Assets/Scripts/UI/TimeTrial/TimeTrialNet.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,37 @@
77
using QFramework;
88

99
public class TimeTrialNet : MonoBehaviour, IController {
10+
private Coroutine timeTrialNetCor;
11+
1012
private void Start() {
11-
//if (this.GetModel<IGameControllerModel>().CurGameType == GameType.TimeTrial) {
13+
//if (this.GetModel<IGameControllerModel>().CurGameType == GameType.TimeTrial)
14+
//{
1215
// string ws = "ws" + this.GetSystem<INetworkSystem>().HttpBaseUrl.Substring(4) +
1316
// "websocket/TimeTrialWebSocket/" +
1417
// this.GetModel<IUserModel>().Uid.Value + "," + this.GetModel<ITimeTrialModel>().SelectInfo.Value.cid;
1518
// Debug.Log("+++ " + ws);
16-
// if (this.GetSystem<INetworkSystem>().NetType == NetType.WebSocket) {
19+
// if (this.GetSystem<INetworkSystem>().NetType == NetType.WebSocket)
20+
// {
1721
// this.GetSystem<INetworkSystem>().Connect(ws);
18-
// } else if (this.GetSystem<INetworkSystem>().NetType == NetType.KCP) {
22+
// }
23+
// else if (this.GetSystem<INetworkSystem>().NetType == NetType.KCP)
24+
// {
1925
// this.GetSystem<INetworkSystem>().Connect(Util.GetServerHost(this.GetSystem<INetworkSystem>().ServerType));
2026
// }
21-
// Util.DelayExecuteWithSecond(3, () => { CoroutineController.manager.StartCoroutine(SendMsg()); });
27+
28+
// Util.DelayExecuteWithSecond(3, () => { this.SendCommand<PostCreatePlayerMsgCommand>(); });
29+
// Util.DelayExecuteWithSecond(4.5f, () => { timeTrialNetCor = CoroutineController.manager.StartCoroutine(SendMsg()); });
2230
//}
31+
32+
//this.RegisterEvent<ExitGameSceneEvent>(OnExitGameScene).UnRegisterWhenGameObjectDestroyed(gameObject);
33+
}
34+
35+
private void OnExitGameScene(ExitGameSceneEvent e)
36+
{
37+
if (timeTrialNetCor != null)
38+
{
39+
CoroutineController.manager.StopCoroutine(timeTrialNetCor);
40+
}
2341
}
2442

2543
private IEnumerator SendMsg() {

CrazyCar/Assets/Scripts/Utility/Util.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ public static SceneID LoadingTargetSceneID {
339339
return loadingTargetSceneID;
340340
}
341341
}
342+
342343
public static void LoadingScene(SceneID sceneID) {
343344
loadingTargetSceneID = sceneID;
344345
SceneManager.LoadScene((int)SceneID.Loading);

0 commit comments

Comments
 (0)