-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathKBEMain.cs
106 lines (87 loc) · 2.91 KB
/
KBEMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using UnityEngine;
using System;
using System.Collections;
using KBEngine;
/*
可以理解为插件的入口模块
在这个入口中安装了需要监听的事件(installEvents),同时初始化KBEngine(initKBEngine)
*/
public class KBEMain : MonoBehaviour
{
public KBEngineApp gameapp = null;
// 在unity3d界面中可见选项
public DEBUGLEVEL debugLevel = DEBUGLEVEL.DEBUG;
public bool isMultiThreads = true;
public string ip = "127.0.0.1";
public int port = 20013;
public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI;
public string persistentDataPath = "Application.persistentDataPath";
public int syncPlayerMS = 100;
public int threadUpdateHZ = 10;
public int serverHeartbeatTick = 15;
public int SEND_BUFFER_MAX = (int)KBEngine.NetworkInterface.TCP_PACKET_MAX;
public int RECV_BUFFER_MAX = (int)KBEngine.NetworkInterface.TCP_PACKET_MAX;
public bool useAliasEntityID = true;
public bool isOnInitCallPropertysSetMethods = true;
protected virtual void Awake()
{
DontDestroyOnLoad(transform.gameObject);
}
// Use this for initialization
protected virtual void Start ()
{
MonoBehaviour.print("clientapp::start()");
installEvents();
initKBEngine();
}
public virtual void installEvents()
{
}
public virtual void initKBEngine()
{
// 如果此处发生错误,请查看 Assets\Scripts\kbe_scripts\if_Entity_error_use______git_submodule_update_____kbengine_plugins_______open_this_file_and_I_will_tell_you.cs
Dbg.debugLevel = debugLevel;
KBEngineArgs args = new KBEngineArgs();
args.ip = ip;
args.port = port;
args.clientType = clientType;
if(persistentDataPath == "Application.persistentDataPath")
args.persistentDataPath = Application.persistentDataPath;
else
args.persistentDataPath = persistentDataPath;
args.syncPlayerMS = syncPlayerMS;
args.threadUpdateHZ = threadUpdateHZ;
args.serverHeartbeatTick = serverHeartbeatTick;
args.useAliasEntityID = useAliasEntityID;
args.isOnInitCallPropertysSetMethods = isOnInitCallPropertysSetMethods;
args.SEND_BUFFER_MAX = (UInt32)SEND_BUFFER_MAX;
args.RECV_BUFFER_MAX = (UInt32)RECV_BUFFER_MAX;
args.isMultiThreads = isMultiThreads;
if(isMultiThreads)
gameapp = new KBEngineAppThread(args);
else
gameapp = new KBEngineApp(args);
}
protected virtual void OnDestroy()
{
MonoBehaviour.print("clientapp::OnDestroy(): begin");
if (KBEngineApp.app != null)
{
KBEngineApp.app.destroy();
KBEngineApp.app = null;
}
KBEngine.Event.clear();
MonoBehaviour.print("clientapp::OnDestroy(): end");
}
protected virtual void FixedUpdate ()
{
KBEUpdate();
}
public virtual void KBEUpdate()
{
// 单线程模式必须自己调用
if(!isMultiThreads)
gameapp.process();
KBEngine.Event.processOutEvents();
}
}