Skip to content

Commit 7006c9d

Browse files
committed
插件notifyPropertysSetMethods加入标签控制初始化时默认是否触发set_*事件
kbengine/kbengine#293
1 parent 15bf999 commit 7006c9d

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

Entity.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public class Entity
2929

3030
// __init__调用之后设置为true
3131
public bool inited = false;
32-
32+
3333
// entityDef属性,服务端同步过来后存储在这里
3434
private Dictionary<string, Property> defpropertys_ =
3535
new Dictionary<string, Property>();
36-
36+
3737
private Dictionary<UInt16, Property> iddefpropertys_ =
3838
new Dictionary<UInt16, Property>();
39-
39+
4040
public static void clear()
4141
{
4242
}
43-
43+
4444
public Entity()
4545
{
4646
foreach(Property e in EntityDef.moduledefs[GetType().Name].propertys.Values)
@@ -117,7 +117,7 @@ public virtual void __init__()
117117
{
118118
}
119119

120-
public void notifyPropertysSetMethods()
120+
public virtual void callPropertysSetMethods()
121121
{
122122
foreach(Property prop in iddefpropertys_.Values)
123123
{
@@ -130,22 +130,22 @@ public void notifyPropertysSetMethods()
130130
{
131131
if(inited && !inWorld)
132132
{
133-
//Dbg.DEBUG_MSG(className + "::notifyPropertysSetBasePropertyMethods(" + prop.name + ")");
133+
//Dbg.DEBUG_MSG(className + "::callPropertysSetMethods(" + prop.name + ")");
134134
setmethod.Invoke(this, new object[]{oldval});
135135
}
136136
}
137137
else
138138
{
139139
if(inWorld)
140140
{
141-
//Dbg.DEBUG_MSG(className + "::notifyPropertysSetCellPropertyMethods(" + prop.name + ")");
141+
//Dbg.DEBUG_MSG(className + "::callPropertysSetMethods(" + prop.name + ")");
142142
setmethod.Invoke(this, new object[]{oldval});
143143
}
144144
}
145145
}
146146
else
147147
{
148-
//Dbg.DEBUG_MSG(className + "::notifyPropertysSetCellPropertyMethods(" + prop.name + ") not found set_*");
148+
//Dbg.DEBUG_MSG(className + "::callPropertysSetMethods(" + prop.name + ") not found set_*");
149149
}
150150
}
151151
}

KBEMain.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class KBEMain : MonoBehaviour
2424
public int SEND_BUFFER_MAX = (int)KBEngine.NetworkInterface.TCP_PACKET_MAX;
2525
public int RECV_BUFFER_MAX = (int)KBEngine.NetworkInterface.TCP_PACKET_MAX;
2626
public bool useAliasEntityID = true;
27-
27+
public bool isOnInitCallPropertysSetMethods = true;
28+
2829
void Awake()
2930
{
3031
DontDestroyOnLoad(transform.gameObject);
@@ -62,7 +63,8 @@ public virtual void initKBEngine()
6263
args.syncPlayer = syncPlayer;
6364
args.threadUpdateHZ = threadUpdateHZ;
6465
args.useAliasEntityID = useAliasEntityID;
65-
66+
args.isOnInitCallPropertysSetMethods = isOnInitCallPropertysSetMethods;
67+
6668
args.SEND_BUFFER_MAX = (UInt32)SEND_BUFFER_MAX;
6769
args.RECV_BUFFER_MAX = (UInt32)RECV_BUFFER_MAX;
6870

KBEngine.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,9 @@ public void Client_onCreatedProxies(UInt64 rndUUID, Int32 eid, string entityType
14161416

14171417
entity.__init__();
14181418
entity.inited = true;
1419-
entity.notifyPropertysSetMethods();
1419+
1420+
if(_args.isOnInitCallPropertysSetMethods)
1421+
entity.callPropertysSetMethods();
14201422
}
14211423

14221424
public Entity findEntity(Int32 entityID)
@@ -1677,7 +1679,9 @@ public void Client_onEntityEnterWorld(MemoryStream stream)
16771679
entity.inited = true;
16781680
entity.inWorld = true;
16791681
entity.enterWorld();
1680-
entity.notifyPropertysSetMethods();
1682+
1683+
if(_args.isOnInitCallPropertysSetMethods)
1684+
entity.callPropertysSetMethods();
16811685
}
16821686
else
16831687
{
@@ -1702,7 +1706,9 @@ public void Client_onEntityEnterWorld(MemoryStream stream)
17021706
entity.isOnGround = isOnGround > 0;
17031707
entity.inWorld = true;
17041708
entity.enterWorld();
1705-
entity.notifyPropertysSetMethods();
1709+
1710+
if(_args.isOnInitCallPropertysSetMethods)
1711+
entity.callPropertysSetMethods();
17061712
}
17071713
}
17081714
}

KBEngineArgs.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ public class KBEngineArgs
1313
public string ip = "127.0.0.1";
1414
public int port = 20013;
1515

16-
1716
// 客户端类型
1817
// Reference: http://www.kbengine.org/docs/programming/clientsdkprogramming.html, client types
1918
public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI;
2019

2120
// 持久化插件信息, 例如:从服务端导入的协议可以持久化到本地,下次登录版本不发生改变
2221
// 可以直接从本地加载来提供登录速度
2322
public string persistentDataPath = "";
24-
25-
23+
2624
// Allow synchronization role position information to the server
2725
// 是否开启自动同步玩家信息到服务端,信息包括位置与方向
2826
// 非高实时类游戏不需要开放这个选项
@@ -31,25 +29,28 @@ public class KBEngineArgs
3129
// 是否使用别名机制
3230
// 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致
3331
public bool useAliasEntityID = true;
34-
32+
33+
// 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods)
34+
public bool isOnInitCallPropertysSetMethods = true;
35+
3536
// 发送缓冲大小
3637
public MessageLengthEx SEND_BUFFER_MAX = NetworkInterface.TCP_PACKET_MAX;
37-
38+
3839
// 接收缓冲区大小
3940
public MessageLengthEx RECV_BUFFER_MAX = NetworkInterface.TCP_PACKET_MAX;
40-
41+
4142
// 是否多线程启动
4243
public bool isMultiThreads = false;
43-
44+
4445
// 只在多线程模式启用
4546
// 线程主循环处理频率
4647
public int threadUpdateHZ = 10;
47-
48+
4849
public int getRecvBufferSize()
4950
{
5051
return (int)RECV_BUFFER_MAX;
5152
}
52-
53+
5354
public int getSendBufferSize()
5455
{
5556
return (int)SEND_BUFFER_MAX;

0 commit comments

Comments
 (0)