Skip to content

Commit 2ca367b

Browse files
committed
del I18N and add I18NSystem
1 parent 3bffb90 commit 2ca367b

File tree

21 files changed

+89
-125
lines changed

21 files changed

+89
-125
lines changed

CrazyCar/Assets/Scenes/Login.unity

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ Transform:
15631563
m_LocalScale: {x: 1, y: 1, z: 1}
15641564
m_Children: []
15651565
m_Father: {fileID: 0}
1566-
m_RootOrder: 7
1566+
m_RootOrder: 6
15671567
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
15681568
--- !u!1 &679276205
15691569
GameObject:
@@ -1643,51 +1643,6 @@ CanvasRenderer:
16431643
m_PrefabAsset: {fileID: 0}
16441644
m_GameObject: {fileID: 679276205}
16451645
m_CullTransparentMesh: 0
1646-
--- !u!1 &719621118
1647-
GameObject:
1648-
m_ObjectHideFlags: 0
1649-
m_CorrespondingSourceObject: {fileID: 0}
1650-
m_PrefabInstance: {fileID: 0}
1651-
m_PrefabAsset: {fileID: 0}
1652-
serializedVersion: 6
1653-
m_Component:
1654-
- component: {fileID: 719621119}
1655-
- component: {fileID: 719621120}
1656-
m_Layer: 0
1657-
m_Name: I18N
1658-
m_TagString: Untagged
1659-
m_Icon: {fileID: 0}
1660-
m_NavMeshLayer: 0
1661-
m_StaticEditorFlags: 0
1662-
m_IsActive: 1
1663-
--- !u!4 &719621119
1664-
Transform:
1665-
m_ObjectHideFlags: 0
1666-
m_CorrespondingSourceObject: {fileID: 0}
1667-
m_PrefabInstance: {fileID: 0}
1668-
m_PrefabAsset: {fileID: 0}
1669-
m_GameObject: {fileID: 719621118}
1670-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
1671-
m_LocalPosition: {x: 0, y: 0, z: 0}
1672-
m_LocalScale: {x: 1, y: 1, z: 1}
1673-
m_Children: []
1674-
m_Father: {fileID: 0}
1675-
m_RootOrder: 6
1676-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1677-
--- !u!114 &719621120
1678-
MonoBehaviour:
1679-
m_ObjectHideFlags: 0
1680-
m_CorrespondingSourceObject: {fileID: 0}
1681-
m_PrefabInstance: {fileID: 0}
1682-
m_PrefabAsset: {fileID: 0}
1683-
m_GameObject: {fileID: 719621118}
1684-
m_Enabled: 1
1685-
m_EditorHideFlags: 0
1686-
m_Script: {fileID: 11500000, guid: 9803dccc9982ec948b85a6b984b20e47, type: 3}
1687-
m_Name:
1688-
m_EditorClassIdentifier:
1689-
currentLang: en
1690-
initFinish: 0
16911646
--- !u!1 &735918344
16921647
GameObject:
16931648
m_ObjectHideFlags: 0

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ protected override void OnExecute() {
5454
data: bytes, token: this.GetModel<IGameControllerModel>().Token.Value,
5555
succData: (data) => {
5656
this.GetModel<IUserModel>().Aid.Value = (int)data["aid"];
57-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Successfully Set"));
57+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Successfully Set"));
5858
},
5959
code: (code) => {
6060
if (code == 423) {
61-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Did not have"));
61+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Did not have"));
6262
}
6363
}));
6464
}
@@ -81,7 +81,7 @@ protected override void OnExecute() {
8181
Debug.Log("++++++ " + sb.ToString());
8282
byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
8383
if (this.GetModel<IUserModel>().Star.Value > mEquipInfo.star) {
84-
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(content: string.Format(I18N.manager.GetText("Whether to spend {0} star on this equip"),
84+
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(content: string.Format(this.GetSystem<II18NSystem>().GetText("Whether to spend {0} star on this equip"),
8585
mEquipInfo.star),
8686
success: () => {
8787
CoroutineController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl +
@@ -94,10 +94,10 @@ protected override void OnExecute() {
9494
}));
9595
},
9696
fail: () => {
97-
Debug.Log(I18N.manager.GetText("Give up to buy"));
97+
Debug.Log(this.GetSystem<II18NSystem>().GetText("Give up to buy"));
9898
});
9999
} else {
100-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(string.Format(I18N.manager.GetText("This equip requires {0} star"),
100+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(string.Format(this.GetSystem<II18NSystem>().GetText("This equip requires {0} star"),
101101
mEquipInfo.star));
102102
}
103103
}
@@ -124,12 +124,12 @@ protected override void OnExecute() {
124124
data: bytes, token: this.GetModel<IGameControllerModel>().Token.Value,
125125
succData: (data) => {
126126
this.GetModel<IUserModel>().EquipInfo.Value = this.GetModel<IEquipModel>().EquipDic[(int)data["eid"]];
127-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Successfully Set"));
127+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Successfully Set"));
128128
this.SendEvent<ApplyEquipEvent>();
129129
},
130130
code: (code) => {
131131
if (code == 423) {
132-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Did not have"));
132+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Did not have"));
133133
}
134134
}));
135135
}
@@ -168,14 +168,14 @@ protected override void OnExecute() {
168168
CoroutineController.manager.StartCoroutine(Util.POSTHTTP(url: this.GetSystem<INetworkSystem>().HttpBaseUrl + RequestUrl.modifyPersonalInfoUrl,
169169
data: bytes, token: this.GetModel<IGameControllerModel>().Token.Value,
170170
succData: (data) => {
171-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Modify Successfully"));
171+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Modify Successfully"));
172172
this.GetModel<IUserModel>().Password.Value = mPassword;
173173
},
174174
code: (code) => {
175175
if (code == 423) {
176-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Fail To Modify"));
176+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Fail To Modify"));
177177
} else if (code == 404) {
178-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Information Error"));
178+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Information Error"));
179179
}
180180
}));
181181
}
@@ -190,7 +190,7 @@ protected override void OnExecute() {
190190
this.GetModel<IUserModel>().ParseUserInfo(data);
191191

192192
Util.DelayExecuteWithSecond(Util.btnASTime, () => {
193-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(text: I18N.manager.GetText("Login Success"),
193+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(text: this.GetSystem<II18NSystem>().GetText("Login Success"),
194194
callback: () => {
195195
Util.LoadingScene(SceneID.Index);
196196
});
@@ -231,19 +231,19 @@ protected override void OnExecute() {
231231
if (mUserName.ToLower() == "tast") {
232232
this.GetModel<IGameControllerModel>().GameHelper.gameObject.SetActiveFast(true);
233233
}
234-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(text: I18N.manager.GetText("Login Success"),
234+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(text: this.GetSystem<II18NSystem>().GetText("Login Success"),
235235
callback: () => {
236236
this.GetModel<IUserModel>().RememberPassword.Value = mIsRemember ? 1 : 0;
237237
Util.LoadingScene(SceneID.Index);
238238
});
239239
});
240240

241241
} else if (code == 423) {
242-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Password Error"));
242+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Password Error"));
243243
} else if (code == 404) {
244-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("User not registered"));
244+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("User not registered"));
245245
} else {
246-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Unknown Error"));
246+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Unknown Error"));
247247
}
248248
}));
249249
}
@@ -278,15 +278,15 @@ protected override void OnExecute() {
278278
this.GetModel<IUserModel>().Password.Value = mPassword;
279279
}, code: (code) => {
280280
if (code == 200) {
281-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(text: I18N.manager.GetText("Registration Successful"), callback: () => {
281+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(text: this.GetSystem<II18NSystem>().GetText("Registration Successful"), callback: () => {
282282
Util.LoadingScene(SceneID.Index);
283283
});
284284
} else if (code == 423) {
285-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("User registered"));
285+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("User registered"));
286286
} else if (code == 425) {
287-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Incorrect information format"));
287+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Incorrect information format"));
288288
} else {
289-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Unknown Error"));
289+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Unknown Error"));
290290
}
291291
}));
292292
}
@@ -307,7 +307,7 @@ protected override void OnExecute() {
307307
this.GetModel<IGameControllerModel>().CurGameType = GameType.Match;
308308
Util.LoadingScene(SceneID.Game);
309309
} else {
310-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("The game is over"));
310+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("The game is over"));
311311
}
312312
}
313313

CrazyCar/Assets/Scripts/Framework/CrazyCar.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ protected override void Init() {
1111
RegisterSystem<IScreenEffectsSystem>(new ScreenEffectsSystem());
1212
RegisterSystem<IIndexCarSystem>(new IndexCarSystem());
1313
RegisterSystem<INetworkSystem>(new NetworkSystem());
14+
RegisterSystem<II18NSystem>(new I18NSystem());
1415
RegisterModel<IGameControllerModel>(new GameControllerModel());
1516
RegisterModel<IUserModel>(new UserModel());
1617
RegisterModel<IAvatarModel>(new AvatarModel());

CrazyCar/Assets/Scripts/Framework/Game/ControlPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private void OnEnable() {
2323
private void Start() {
2424
exitBtn.onClick.AddListener(() => {
2525
Time.timeScale = 0;
26-
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(content: I18N.manager.GetText("Quit the game?"),
26+
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(content: this.GetSystem<II18NSystem>().GetText("Quit the game?"),
2727
success: () => {
2828
Time.timeScale = 1;
2929
Util.LoadingScene(SceneID.Index);

CrazyCar/Assets/Scripts/Framework/Game/GameController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private void Start() {
2424
this.GetModel<IGameControllerModel>().WarningAlert.gameObject.SetActiveFast(false);
2525
this.GetModel<IGameControllerModel>().InfoConfirmAlert.gameObject.SetActiveFast(false);
2626
InitSettingsInfo();
27-
I18N.manager.InitTranslation();
27+
this.GetSystem<II18NSystem>().InitTranslation();
2828
}
2929

3030
public void InitSettingsInfo() {

CrazyCar/Assets/Scripts/Framework/Game/GameUIControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private void OnSelectGameUI(SelectGameUIEvent e) {
2828

2929
private void OnShowResultUI(ShowResultUIEvent e) {
3030
if (this.GetModel<IGameControllerModel>().StandAlone.Value) {
31-
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(I18N.manager.GetText("Game Over"), 2.0f);
31+
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText(this.GetSystem<II18NSystem>().GetText("Game Over"), 2.0f);
3232
Util.DelayExecuteWithSecond(2.0f, () => {
3333
Util.LoadingScene(SceneID.Index);
3434
});

CrazyCar/Assets/Scripts/Common/I18N/I18N.cs renamed to CrazyCar/Assets/Scripts/Framework/System/I18NSystem.cs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
using LitJson;
2-
using System;
1+
using System.Collections;
32
using System.Collections.Generic;
4-
using System.IO;
5-
using UnityEditor;
63
using UnityEngine;
7-
using Utils;
84
using TFramework;
5+
using LitJson;
6+
using Utils;
7+
using System;
98

10-
public class I18N : MonoBehaviour, IController {
9+
public interface II18NSystem : ISystem {
10+
string CurrentLang { get; set; }
11+
bool InitFinish { get; set; }
1112

12-
public static I18N manager = null;
13-
public string currentLang = "zh-cn";
13+
void InitTranslation();
14+
string GetText(string key);
15+
void RegisterText(I18NText t);
16+
void UnregisterText(I18NText t);
17+
void ChangeLang(string id);
18+
}
19+
20+
public class I18NSystem : AbstractSystem, II18NSystem {
21+
public string CurrentLang { get; set; }
22+
public bool InitFinish { get; set; }
1423

1524
private Dictionary<string, JsonData> trans = new Dictionary<string, JsonData>();
1625
private Dictionary<string, string> langMap = new Dictionary<string, string>();
1726
private List<I18NText> allTexts = new List<I18NText>();
1827
private JsonData current_dict;
1928
private string defaultLang = "zh-cn";
20-
public bool initFinish = false;
21-
22-
private void Awake() {
23-
if (manager == null) {
24-
DontDestroyOnLoad(gameObject);
25-
manager = this;
26-
} else if (manager != this) {
27-
Destroy(gameObject);
28-
}
29-
}
3029

31-
// 读取本地语言 如果读取不到设置中的语言设置 就设置默认语言
3230
public void InitTranslation() {
33-
TextAsset[] tas = Resources.LoadAll<TextAsset>(Util.baseLanguagePath);
31+
TextAsset[] tas = Resources.LoadAll<TextAsset>(Util.baseLanguagePath);
3432
foreach (var t in tas) {
3533
JsonData d = JsonMapper.ToObject(t.text);
3634
langMap[(string)d["languageName"]] = (string)d["id"];
3735
trans[(string)d["id"]] = d;
3836
}
39-
initFinish = true;
37+
InitFinish = true;
4038

4139
try {
4240
ChangeLang(string.IsNullOrEmpty(this.GetModel<ISettingsModel>().Language)
@@ -69,7 +67,7 @@ public void UnregisterText(I18NText t) {
6967
public void ChangeLang(string id) {
7068
Debug.Log("ChangeLang = " + id);
7169
current_dict = trans[id];
72-
currentLang = id;
70+
CurrentLang = id;
7371
RefreshAllText();
7472
}
7573

@@ -84,7 +82,7 @@ private void RefreshAllText() {
8482
}
8583
}
8684

87-
public IArchitecture GetArchitecture() {
88-
return CrazyCar.Interface;
85+
protected override void OnInit() {
86+
8987
}
90-
}
88+
}

CrazyCar/Assets/Scripts/Common/I18N/I18N.cs.meta renamed to CrazyCar/Assets/Scripts/Framework/System/I18NSystem.cs.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void OnPointerClick(PointerEventData eventData) {
2121
} else {
2222
if (this.GetModel<IUserModel>().Star.Value > avatarInfo.star) {
2323
this.GetModel<IGameControllerModel>().InfoConfirmAlert.ShowWithText(content:
24-
string.Format(I18N.manager.GetText("Does it cost {0} star to buy this avatar"), avatarInfo.star),
24+
string.Format(this.GetSystem<II18NSystem>().GetText("Does it cost {0} star to buy this avatar"), avatarInfo.star),
2525
success: () => {
2626
this.SendCommand(new BuyAvatarCommand(avatarInfo));
2727
},
@@ -30,7 +30,7 @@ public void OnPointerClick(PointerEventData eventData) {
3030
});
3131
} else {
3232
this.GetModel<IGameControllerModel>().WarningAlert.ShowWithText
33-
(string.Format(I18N.manager.GetText("This head needs {0} star"), avatarInfo.star));
33+
(string.Format(this.GetSystem<II18NSystem>().GetText("This head needs {0} star"), avatarInfo.star));
3434
}
3535
}
3636
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ private void OnChangeCarEvent(ChangeCarEvent e) {
8787
applyBtn.interactable = true;
8888
}
8989
if (curEquipInfo.isHas) {
90-
applyBtnText.text = I18N.manager.GetText("Apply");
90+
applyBtnText.text = this.GetSystem<II18NSystem>().GetText("Apply");
9191
} else {
92-
applyBtnText.text = I18N.manager.GetText("Buy");
92+
applyBtnText.text = this.GetSystem<II18NSystem>().GetText("Buy");
9393
}
9494
}
9595

9696
private void OnBuyEquip(BuyEquipEvent e) {
97-
applyBtnText.text = I18N.manager.GetText("Apply");
97+
applyBtnText.text = this.GetSystem<II18NSystem>().GetText("Apply");
9898
curEquipInfo.isHas = true;
9999
for (int i = 0; i < changeCarItems.Count; i++) {
100100
changeCarItems[i].SetUnlockState();

0 commit comments

Comments
 (0)