Skip to content

Commit c7448b7

Browse files
committed
add NetworkSystem
1 parent 75f0b53 commit c7448b7

19 files changed

+88
-53
lines changed

CrazyCar/Assets/Scripts/Common/NetworkController.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

CrazyCar/Assets/Scripts/Framework/Command/CommandHub.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void OnExecute() {
2323
Debug.Log("++++++ " + sb.ToString());
2424
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
2525
GameController.manager.StartCoroutine(Util.POSTHTTP
26-
(url: NetworkController.manager.HttpBaseUrl + RequestUrl.buyAvatarUrl,
26+
(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.buyAvatarUrl,
2727
data: bytes,
2828
token: GameController.manager.token,
2929
succData: (data) => {
@@ -51,7 +51,7 @@ protected override void OnExecute() {
5151
w.WriteObjectEnd();
5252
Debug.Log("++++++ " + sb.ToString());
5353
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
54-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl + RequestUrl.changeAvatarUrl,
54+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.changeAvatarUrl,
5555
data: bytes, token: GameController.manager.token,
5656
succData: (data) => {
5757
this.GetModel<IUserModel>().Aid.Value = (int)data["aid"];
@@ -85,7 +85,7 @@ protected override void OnExecute() {
8585
GameController.manager.infoConfirmAlert.ShowWithText(content: string.Format(I18N.manager.GetText("Whether to spend {0} star on this equip"),
8686
mEquipInfo.star),
8787
success: () => {
88-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl +
88+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl +
8989
RequestUrl.buyEquipUrl,
9090
data: bytes,
9191
token: GameController.manager.token,
@@ -120,7 +120,7 @@ protected override void OnExecute() {
120120
w.WriteObjectEnd();
121121
Debug.Log("++++++ " + sb.ToString());
122122
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
123-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl +
123+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl +
124124
RequestUrl.changeEquipUrl,
125125
data: bytes, token: GameController.manager.token,
126126
succData: (data) => {
@@ -138,7 +138,7 @@ protected override void OnExecute() {
138138

139139
public class CreateMatchCommand : AbstractCommand {
140140
protected override void OnExecute() {
141-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl +
141+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl +
142142
RequestUrl.createMatchUrl,
143143
token: GameController.manager.token,
144144
code: (code) => {
@@ -166,7 +166,7 @@ protected override void OnExecute() {
166166
w.WriteObjectEnd();
167167
Debug.Log("++++++ " + sb.ToString());
168168
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
169-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl + RequestUrl.modifyPersonalInfoUrl,
169+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.modifyPersonalInfoUrl,
170170
data: bytes, token: GameController.manager.token,
171171
succData: (data) => {
172172
GameController.manager.warningAlert.ShowWithText(I18N.manager.GetText("Modify Successfully"));
@@ -222,7 +222,7 @@ protected override void OnExecute() {
222222
w.WriteObjectEnd();
223223
Debug.Log("++++++ " + sb.ToString());
224224
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
225-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl + RequestUrl.loginUrl,
225+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.loginUrl,
226226
data: bytes, succData: (data) => {
227227
GameController.manager.token = (string)data["token"];
228228
this.GetModel<IUserModel>().ParseUserInfo(data);
@@ -273,7 +273,7 @@ protected override void OnExecute() {
273273
w.WriteObjectEnd();
274274
Debug.Log("++++++ " + sb.ToString());
275275
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
276-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl + RequestUrl.registerUrl,
276+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.registerUrl,
277277
data: bytes, succData: (data) => {
278278
GameController.manager.token = (string)data["token"];
279279
this.GetModel<IUserModel>().ParseUserInfo(data);
@@ -351,7 +351,7 @@ protected override void OnExecute() {
351351
w.WriteObjectEnd();
352352
Debug.Log("++++++ " + sb.ToString());
353353
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
354-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl + RequestUrl.buyTimeTrialClassUrl,
354+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.buyTimeTrialClassUrl,
355355
data: bytes,
356356
token: GameController.manager.token,
357357
succData: (data) => {

CrazyCar/Assets/Scripts/Framework/CrazyCar.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ protected override void Init() {
1010
RegisterSystem<IWebSocketSystem>(new WebSocketSystem());
1111
RegisterSystem<IScreenEffectsSystem>(new ScreenEffectsSystem());
1212
RegisterSystem<IIndexCarSystem>(new IndexCarSystem());
13+
RegisterSystem<INetworkSystem>(new NetworkSystem());
1314
RegisterModel<IUserModel>(new UserModel());
1415
RegisterModel<IAvatarModel>(new AvatarModel());
1516
RegisterModel<ITimeTrialModel>(new TimeTrialModel());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Utils;
5+
using TFramework;
6+
7+
public enum ServerType {
8+
Local = 0,
9+
Remote
10+
}
11+
12+
13+
public class NetworkController : MonoBehaviour, IController {
14+
public ServerType serverType;
15+
16+
private void Awake() {
17+
this.GetSystem<INetworkSystem>().ServerType = serverType;
18+
this.GetSystem<INetworkSystem>().HttpBaseUrl = Util.GetServerBaseUrl(serverType);
19+
DontDestroyOnLoad(gameObject);
20+
}
21+
22+
public IArchitecture GetArchitecture() {
23+
return CrazyCar.Interface;
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using TFramework;
5+
using Utils;
6+
7+
public interface INetworkSystem : ISystem {
8+
ServerType ServerType { get; set; }
9+
string HttpBaseUrl { get; set; }
10+
}
11+
12+
public class NetworkSystem : AbstractSystem, INetworkSystem {
13+
private ServerType serverType;
14+
15+
public ServerType ServerType {
16+
get {
17+
return serverType;
18+
}
19+
set {
20+
serverType = value;
21+
} }
22+
public string HttpBaseUrl { get; set; }
23+
24+
protected override void OnInit() {
25+
26+
}
27+
}

CrazyCar/Assets/Scripts/Framework/System/NetworkSystem.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/Framework/System/ResourceSystem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private void CheckCoroutine() {
8181
w.WriteObjectEnd();
8282
Debug.Log("++++++ " + sb.ToString());
8383
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
84-
GameController.manager.StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl +
84+
GameController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl +
8585
RequestUrl.resourceUrl,
8686
data: bytes,
8787
succData: (data) => {
@@ -92,9 +92,9 @@ private void CheckCoroutine() {
9292
if (avatarStr.Contains("http")) {
9393
avatarURL = avatarStr;
9494
} else {
95-
avatarURL = NetworkController.manager.HttpBaseUrl + (string)data["avatar"]["url"];
95+
avatarURL = this.GetSystem<INetworkSystem>().HttpBaseUrl + (string)data["avatar"]["url"];
9696
}
97-
avatarURL = NetworkController.manager.HttpBaseUrl + (string)data["avatar"]["url"];
97+
avatarURL = this.GetSystem<INetworkSystem>().HttpBaseUrl + (string)data["avatar"]["url"];
9898
avatarSize = float.Parse((string)data["avatar"]["size"]);
9999

100100
equipHash = (string)data["equip"]["hash"];
@@ -103,7 +103,7 @@ private void CheckCoroutine() {
103103
if (equipStr.Contains("http")) {
104104
equipURL = equipStr;
105105
} else {
106-
equipURL = NetworkController.manager.HttpBaseUrl + (string)data["equip"]["url"];
106+
equipURL = this.GetSystem<INetworkSystem>().HttpBaseUrl + (string)data["equip"]["url"];
107107
}
108108
equipSize = float.Parse((string)data["equip"]["size"]);
109109

CrazyCar/Assets/Scripts/Framework/UI/Avatar/AvatarUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class AvatarUI : MonoBehaviour, IController {
2020

2121
private void OnEnable() {
2222
avatarModel = this.GetModel<IAvatarModel>();
23-
StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl + RequestUrl.avatarUrl,
23+
StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.avatarUrl,
2424
token: GameController.manager.token,
2525
succData: (data) => {
2626
avatarModel.ParseAvatarRes(data, UpdataUI);

CrazyCar/Assets/Scripts/Framework/UI/Equipment/ChangeCarUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ChangeCarUI : MonoBehaviour, IController {
2424
private List<ChangeCarItem> changeCarItems = new List<ChangeCarItem>();
2525

2626
private void OnEnable() {
27-
StartCoroutine(Util.POSTHTTP(url: NetworkController.manager.HttpBaseUrl +
27+
StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl +
2828
RequestUrl.equipUrl,
2929
token: GameController.manager.token,
3030
succData: (data) => {

0 commit comments

Comments
 (0)