Skip to content

Commit eb19c01

Browse files
committed
up
1 parent a34f016 commit eb19c01

17 files changed

+300
-20
lines changed

Assets/Plugins/kbengine/kbengine_unity3d_plugins/AccountBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public AccountBase()
3030
{
3131
}
3232

33+
public override void onComponentsEnterworld()
34+
{
35+
}
36+
37+
public override void onComponentsLeaveworld()
38+
{
39+
}
40+
3341
public override void onGetBase()
3442
{
3543
baseEntityCall = new EntityBaseEntityCall_AccountBase(id, className);

Assets/Plugins/kbengine/kbengine_unity3d_plugins/AvatarBase.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ public AvatarBase()
109109

110110
}
111111

112+
public override void onComponentsEnterworld()
113+
{
114+
component1.onEnterworld();
115+
component2.onEnterworld();
116+
component3.onEnterworld();
117+
}
118+
119+
public override void onComponentsLeaveworld()
120+
{
121+
component1.onLeaveworld();
122+
component2.onLeaveworld();
123+
component3.onLeaveworld();
124+
}
125+
112126
public override void onGetBase()
113127
{
114128
baseEntityCall = new EntityBaseEntityCall_AvatarBase(id, className);
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
namespace KBEngine
2+
{
3+
#if UNITY_EDITOR
4+
using UnityEngine;
5+
using UnityEditor;
6+
using System.Collections;
7+
using System;
8+
using System.IO;
9+
using KBEngine;
10+
11+
public class ClientSDKUpdater : MonoBehaviour
12+
{
13+
string warnUpdateSDK = "";
14+
MemoryStream sdkFileStream = null;
15+
int downloadFiles = 0;
16+
string sdkPath = "";
17+
string sdkTempPath = "";
18+
string sdkBakPath = "";
19+
20+
void Start()
21+
{
22+
string kbengineCoreFile = "KBEngine.cs";
23+
string[] res = System.IO.Directory.GetFiles(Application.dataPath, kbengineCoreFile, SearchOption.AllDirectories);
24+
sdkPath = res[0].Replace(kbengineCoreFile, "").Replace("\\", "/");
25+
sdkPath = sdkPath.Remove(sdkPath.Length - 1, 1);
26+
27+
sdkTempPath = sdkPath + "_temp";
28+
sdkBakPath = sdkPath + "_bak";
29+
30+
warnUpdateSDK = "Version does not match the server.\nClick to update KBEnginePlugin!\nPull from: " + KBEngineApp.app.getInitArgs().ip + ":" + KBEngineApp.app.getInitArgs().port;
31+
installEvents();
32+
33+
GameObject[] objs = FindObjectsOfType(typeof(GameObject)) as GameObject[];
34+
foreach (GameObject child in objs)
35+
{
36+
if (!child.gameObject.GetComponent<Camera>() &&
37+
!child.gameObject.GetComponent<KBEMain>() &&
38+
!child.gameObject.GetComponent<ClientSDKUpdater>())
39+
{
40+
child.gameObject.SetActive(false);
41+
}
42+
}
43+
}
44+
45+
public virtual void installEvents()
46+
{
47+
Event.registerIn("onImportClientSDK", this, "onImportClientSDK");
48+
}
49+
50+
protected virtual void OnDestroy()
51+
{
52+
KBEngine.Event.deregisterOut(this);
53+
}
54+
55+
public void onImportClientSDK(int remainingFiles, string fileName, int fileSize, byte[] fileDatas)
56+
{
57+
if (sdkFileStream == null)
58+
sdkFileStream = MemoryStream.createObject();
59+
60+
sdkFileStream.append(fileDatas, (uint)sdkFileStream.rpos, (uint)fileDatas.Length);
61+
62+
warnUpdateSDK = "Download:" + fileName + " -> " + sdkFileStream.length() + "/" + fileSize + "bytes! " + (int)(((float)downloadFiles / (float)(downloadFiles + remainingFiles)) * 100) + "%";
63+
Debug.Log(warnUpdateSDK);
64+
65+
if (sdkFileStream.length() == fileSize)
66+
{
67+
Debug.Log("onImportClientSDK: " + fileName + "->" + fileSize + "bytes success!");
68+
69+
string path = Path.GetDirectoryName(sdkTempPath + "//" + fileName);
70+
if (!Directory.Exists(path))
71+
Directory.CreateDirectory(path);
72+
73+
StreamWriter sw;
74+
FileInfo t = new FileInfo(sdkTempPath + "//" + fileName);
75+
string data = System.Text.Encoding.UTF8.GetString(sdkFileStream.data(), 0, fileSize);
76+
sw = t.CreateText();
77+
sw.WriteLine(data);
78+
sw.Close();
79+
sw.Dispose();
80+
81+
sdkFileStream.reclaimObject();
82+
sdkFileStream = null;
83+
downloadFiles += 1;
84+
85+
if (remainingFiles == 0)
86+
{
87+
warnUpdateSDK = "";
88+
downloadFiles = 0;
89+
replaceNewSDK();
90+
}
91+
}
92+
}
93+
94+
void downloadSDKFromServer()
95+
{
96+
downloadFiles = 0;
97+
98+
if (Directory.Exists(sdkTempPath))
99+
Directory.Delete(sdkTempPath, true);
100+
101+
Directory.CreateDirectory(sdkTempPath);
102+
103+
if (sdkFileStream != null)
104+
{
105+
sdkFileStream.reclaimObject();
106+
sdkFileStream = null;
107+
}
108+
109+
// kbcmd options
110+
string tool_options = "Unity";
111+
string callbackIP = "";
112+
UInt16 callbackPort = 0;
113+
int clientWindowSize = (int)KBEngineApp.app.getInitArgs().TCP_RECV_BUFFER_MAX;
114+
115+
Bundle bundle = Bundle.createObject();
116+
bundle.newMessage(Messages.messages["Loginapp_importClientSDK"]);
117+
bundle.writeString(tool_options);
118+
bundle.writeInt32(clientWindowSize);
119+
bundle.writeString(callbackIP);
120+
bundle.writeUint16(callbackPort);
121+
bundle.send(KBEngineApp.app.networkInterface());
122+
}
123+
124+
void replaceNewSDK()
125+
{
126+
System.IO.Directory.Move(sdkPath, sdkBakPath);
127+
System.IO.Directory.Move(sdkTempPath, sdkPath);
128+
129+
// 删除旧的SKD文件夹
130+
Directory.Delete(sdkBakPath, true);
131+
132+
EditorApplication.isPlaying = false;
133+
AssetDatabase.Refresh();
134+
}
135+
136+
void OnGUI()
137+
{
138+
if (warnUpdateSDK.Length > 0)
139+
{
140+
GUI.contentColor = Color.red;
141+
GUI.backgroundColor = Color.red;
142+
143+
if (GUI.Button(new Rect(Screen.width * 0.25f, Screen.height * 0.4f, Screen.width * 0.5f, Screen.height * 0.2f), warnUpdateSDK))
144+
{
145+
// 从服务器下载新的SDK
146+
downloadSDKFromServer();
147+
}
148+
}
149+
}
150+
151+
void Update()
152+
{
153+
154+
155+
}
156+
}
157+
#endif
158+
}

Assets/Plugins/kbengine/kbengine_unity3d_plugins/ClientSDKUpdater.cs.meta

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

Assets/Plugins/kbengine/kbengine_unity3d_plugins/Entity.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public virtual void onLoseCell()
8989
// 动态生成
9090
}
9191

92+
public virtual void onComponentsEnterworld()
93+
{
94+
// 动态生成, 通知组件onEnterworld
95+
}
96+
97+
public virtual void onComponentsLeaveworld()
98+
{
99+
// 动态生成, 通知组件onLeaveworld
100+
}
101+
92102
public virtual EntityCall getBaseEntityCall()
93103
{
94104
// 动态生成
@@ -257,6 +267,7 @@ public void enterWorld()
257267

258268
try{
259269
onEnterWorld();
270+
onComponentsEnterworld();
260271
}
261272
catch (Exception e)
262273
{
@@ -277,6 +288,7 @@ public void leaveWorld()
277288

278289
try{
279290
onLeaveWorld();
291+
onComponentsLeaveworld();
280292
}
281293
catch (Exception e)
282294
{

Assets/Plugins/kbengine/kbengine_unity3d_plugins/EntityComponent.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public virtual void onDetached(Entity ownerEntity)
2626

2727
}
2828

29+
public virtual void onEnterworld()
30+
{
31+
}
32+
33+
public virtual void onLeaveworld()
34+
{
35+
}
36+
2937
public virtual ScriptModule getScriptModule()
3038
{
3139
// 动态生成

Assets/Plugins/kbengine/kbengine_unity3d_plugins/GateBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public GateBase()
3737
{
3838
}
3939

40+
public override void onComponentsEnterworld()
41+
{
42+
}
43+
44+
public override void onComponentsLeaveworld()
45+
{
46+
}
47+
4048
public override void onGetBase()
4149
{
4250
baseEntityCall = new EntityBaseEntityCall_GateBase(id, className);

Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEngine.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ public enum NETWORK_ENCRYPT_TYPE
8888

8989
// 服务端与客户端的版本号以及协议MD5
9090
public string serverVersion = "";
91-
public string clientVersion = "2.4.2";
91+
public string clientVersion = "2.4.4";
9292
public string serverScriptVersion = "";
9393
public string clientScriptVersion = "0.1.0";
94-
public string serverProtocolMD5 = "78D6E7A3B539900D86F0C2145E44AEB3";
94+
public string serverProtocolMD5 = "0CDB82520874ED30FA3D6BFE658116D0";
9595
public string serverEntitydefMD5 = "90AA620FCF194B85FBE7A8E4F4F8F938";
9696

9797
// 当前玩家的实体id与实体类别
@@ -327,7 +327,7 @@ public void sendTick()
327327
// 更新玩家的位置与朝向到服务端
328328
updatePlayerToServer();
329329

330-
if(span.Seconds > _args.serverHeartbeatTick)
330+
if(_args.serverHeartbeatTick > 0 && span.Seconds > _args.serverHeartbeatTick)
331331
{
332332
span = _lastTickCBTime - _lastTickTime;
333333

Assets/Plugins/kbengine/kbengine_unity3d_plugins/MessageReaderTCP.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public override void process(byte[] datas, MessageLengthEx offset, MessageLength
162162
#endif
163163

164164
msg.handleMessage(stream);
165+
165166
#if UNITY_EDITOR
166167
Dbg.profileEnd(msg.name);
167168
#endif

Assets/Plugins/kbengine/kbengine_unity3d_plugins/MonsterBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public MonsterBase()
5454
{
5555
}
5656

57+
public override void onComponentsEnterworld()
58+
{
59+
}
60+
61+
public override void onComponentsLeaveworld()
62+
{
63+
}
64+
5765
public override void onGetBase()
5866
{
5967
baseEntityCall = new EntityBaseEntityCall_MonsterBase(id, className);

0 commit comments

Comments
 (0)