Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
kebiao committed Apr 1, 2019
1 parent a34f016 commit eb19c01
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public AccountBase()
{
}

public override void onComponentsEnterworld()
{
}

public override void onComponentsLeaveworld()
{
}

public override void onGetBase()
{
baseEntityCall = new EntityBaseEntityCall_AccountBase(id, className);
Expand Down
14 changes: 14 additions & 0 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/AvatarBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ public AvatarBase()

}

public override void onComponentsEnterworld()
{
component1.onEnterworld();
component2.onEnterworld();
component3.onEnterworld();
}

public override void onComponentsLeaveworld()
{
component1.onLeaveworld();
component2.onLeaveworld();
component3.onLeaveworld();
}

public override void onGetBase()
{
baseEntityCall = new EntityBaseEntityCall_AvatarBase(id, className);
Expand Down
158 changes: 158 additions & 0 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/ClientSDKUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
namespace KBEngine
{
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
using System.IO;
using KBEngine;

public class ClientSDKUpdater : MonoBehaviour
{
string warnUpdateSDK = "";
MemoryStream sdkFileStream = null;
int downloadFiles = 0;
string sdkPath = "";
string sdkTempPath = "";
string sdkBakPath = "";

void Start()
{
string kbengineCoreFile = "KBEngine.cs";
string[] res = System.IO.Directory.GetFiles(Application.dataPath, kbengineCoreFile, SearchOption.AllDirectories);
sdkPath = res[0].Replace(kbengineCoreFile, "").Replace("\\", "/");
sdkPath = sdkPath.Remove(sdkPath.Length - 1, 1);

sdkTempPath = sdkPath + "_temp";
sdkBakPath = sdkPath + "_bak";

warnUpdateSDK = "Version does not match the server.\nClick to update KBEnginePlugin!\nPull from: " + KBEngineApp.app.getInitArgs().ip + ":" + KBEngineApp.app.getInitArgs().port;
installEvents();

GameObject[] objs = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach (GameObject child in objs)
{
if (!child.gameObject.GetComponent<Camera>() &&
!child.gameObject.GetComponent<KBEMain>() &&
!child.gameObject.GetComponent<ClientSDKUpdater>())
{
child.gameObject.SetActive(false);
}
}
}

public virtual void installEvents()
{
Event.registerIn("onImportClientSDK", this, "onImportClientSDK");
}

protected virtual void OnDestroy()
{
KBEngine.Event.deregisterOut(this);
}

public void onImportClientSDK(int remainingFiles, string fileName, int fileSize, byte[] fileDatas)
{
if (sdkFileStream == null)
sdkFileStream = MemoryStream.createObject();

sdkFileStream.append(fileDatas, (uint)sdkFileStream.rpos, (uint)fileDatas.Length);

warnUpdateSDK = "Download:" + fileName + " -> " + sdkFileStream.length() + "/" + fileSize + "bytes! " + (int)(((float)downloadFiles / (float)(downloadFiles + remainingFiles)) * 100) + "%";
Debug.Log(warnUpdateSDK);

if (sdkFileStream.length() == fileSize)
{
Debug.Log("onImportClientSDK: " + fileName + "->" + fileSize + "bytes success!");

string path = Path.GetDirectoryName(sdkTempPath + "//" + fileName);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);

StreamWriter sw;
FileInfo t = new FileInfo(sdkTempPath + "//" + fileName);
string data = System.Text.Encoding.UTF8.GetString(sdkFileStream.data(), 0, fileSize);
sw = t.CreateText();
sw.WriteLine(data);
sw.Close();
sw.Dispose();

sdkFileStream.reclaimObject();
sdkFileStream = null;
downloadFiles += 1;

if (remainingFiles == 0)
{
warnUpdateSDK = "";
downloadFiles = 0;
replaceNewSDK();
}
}
}

void downloadSDKFromServer()
{
downloadFiles = 0;

if (Directory.Exists(sdkTempPath))
Directory.Delete(sdkTempPath, true);

Directory.CreateDirectory(sdkTempPath);

if (sdkFileStream != null)
{
sdkFileStream.reclaimObject();
sdkFileStream = null;
}

// kbcmd options
string tool_options = "Unity";
string callbackIP = "";
UInt16 callbackPort = 0;
int clientWindowSize = (int)KBEngineApp.app.getInitArgs().TCP_RECV_BUFFER_MAX;

Bundle bundle = Bundle.createObject();
bundle.newMessage(Messages.messages["Loginapp_importClientSDK"]);
bundle.writeString(tool_options);
bundle.writeInt32(clientWindowSize);
bundle.writeString(callbackIP);
bundle.writeUint16(callbackPort);
bundle.send(KBEngineApp.app.networkInterface());
}

void replaceNewSDK()
{
System.IO.Directory.Move(sdkPath, sdkBakPath);
System.IO.Directory.Move(sdkTempPath, sdkPath);

// 删除旧的SKD文件夹
Directory.Delete(sdkBakPath, true);

EditorApplication.isPlaying = false;
AssetDatabase.Refresh();
}

void OnGUI()
{
if (warnUpdateSDK.Length > 0)
{
GUI.contentColor = Color.red;
GUI.backgroundColor = Color.red;

if (GUI.Button(new Rect(Screen.width * 0.25f, Screen.height * 0.4f, Screen.width * 0.5f, Screen.height * 0.2f), warnUpdateSDK))
{
// 从服务器下载新的SDK
downloadSDKFromServer();
}
}
}

void Update()
{


}
}
#endif
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public virtual void onLoseCell()
// 动态生成
}

public virtual void onComponentsEnterworld()
{
// 动态生成, 通知组件onEnterworld
}

public virtual void onComponentsLeaveworld()
{
// 动态生成, 通知组件onLeaveworld
}

public virtual EntityCall getBaseEntityCall()
{
// 动态生成
Expand Down Expand Up @@ -257,6 +267,7 @@ public void enterWorld()

try{
onEnterWorld();
onComponentsEnterworld();
}
catch (Exception e)
{
Expand All @@ -277,6 +288,7 @@ public void leaveWorld()

try{
onLeaveWorld();
onComponentsLeaveworld();
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public virtual void onDetached(Entity ownerEntity)

}

public virtual void onEnterworld()
{
}

public virtual void onLeaveworld()
{
}

public virtual ScriptModule getScriptModule()
{
// 动态生成
Expand Down
8 changes: 8 additions & 0 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/GateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public GateBase()
{
}

public override void onComponentsEnterworld()
{
}

public override void onComponentsLeaveworld()
{
}

public override void onGetBase()
{
baseEntityCall = new EntityBaseEntityCall_GateBase(id, className);
Expand Down
6 changes: 3 additions & 3 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public enum NETWORK_ENCRYPT_TYPE

// 服务端与客户端的版本号以及协议MD5
public string serverVersion = "";
public string clientVersion = "2.4.2";
public string clientVersion = "2.4.4";
public string serverScriptVersion = "";
public string clientScriptVersion = "0.1.0";
public string serverProtocolMD5 = "78D6E7A3B539900D86F0C2145E44AEB3";
public string serverProtocolMD5 = "0CDB82520874ED30FA3D6BFE658116D0";
public string serverEntitydefMD5 = "90AA620FCF194B85FBE7A8E4F4F8F938";

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

if(span.Seconds > _args.serverHeartbeatTick)
if(_args.serverHeartbeatTick > 0 && span.Seconds > _args.serverHeartbeatTick)
{
span = _lastTickCBTime - _lastTickTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public override void process(byte[] datas, MessageLengthEx offset, MessageLength
#endif

msg.handleMessage(stream);

#if UNITY_EDITOR
Dbg.profileEnd(msg.name);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public MonsterBase()
{
}

public override void onComponentsEnterworld()
{
}

public override void onComponentsLeaveworld()
{
}

public override void onGetBase()
{
baseEntityCall = new EntityBaseEntityCall_MonsterBase(id, className);
Expand Down
8 changes: 8 additions & 0 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/NPCBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public NPCBase()
{
}

public override void onComponentsEnterworld()
{
}

public override void onComponentsLeaveworld()
{
}

public override void onGetBase()
{
baseEntityCall = new EntityBaseEntityCall_NPCBase(id, className);
Expand Down
Loading

0 comments on commit eb19c01

Please sign in to comment.