Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
02718b27
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
02718b27
编写于
9月 23, 2017
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
服务端将一些方法拆分出来,做成System,符合ECS设计,并且System是可以hotfix的
上级
66e13b40
变更
29
隐藏空白更改
内联
并排
Showing
29 changed file
with
434 addition
and
287 deletion
+434
-287
Server/Hotfix/Handler/G2M_CreateUnitHandler.cs
Server/Hotfix/Handler/G2M_CreateUnitHandler.cs
+1
-1
Server/Hotfix/Helper/MessageHelper.cs
Server/Hotfix/Helper/MessageHelper.cs
+6
-4
Server/Hotfix/Other/EntityActorHandler.cs
Server/Hotfix/Other/EntityActorHandler.cs
+44
-0
Server/Hotfix/Other/InnerMessageDispatcher.cs
Server/Hotfix/Other/InnerMessageDispatcher.cs
+2
-1
Server/Hotfix/Other/OuterMessageDispatcher.cs
Server/Hotfix/Other/OuterMessageDispatcher.cs
+2
-1
Server/Hotfix/Server.Hotfix.csproj
Server/Hotfix/Server.Hotfix.csproj
+8
-1
Server/Hotfix/System/ActorSystem.cs
Server/Hotfix/System/ActorSystem.cs
+95
-0
Server/Hotfix/System/NetInnerSystem.cs
Server/Hotfix/System/NetInnerSystem.cs
+45
-0
Server/Hotfix/System/NetOuterSystem.cs
Server/Hotfix/System/NetOuterSystem.cs
+45
-0
Server/Hotfix/System/RealmGateAddressSystem.cs
Server/Hotfix/System/RealmGateAddressSystem.cs
+1
-1
Server/Hotfix/System/ServerFrameSystem.cs
Server/Hotfix/System/ServerFrameSystem.cs
+49
-0
Server/Model/Base/Message/AActorMessage.cs
Server/Model/Base/Message/AActorMessage.cs
+5
-0
Server/Model/Base/Message/IEntityActorHandler.cs
Server/Model/Base/Message/IEntityActorHandler.cs
+0
-36
Server/Model/Component/ActorComponent.cs
Server/Model/Component/ActorComponent.cs
+4
-87
Server/Model/Component/NetInnerComponent.cs
Server/Model/Component/NetInnerComponent.cs
+1
-39
Server/Model/Component/NetOuterComponent.cs
Server/Model/Component/NetOuterComponent.cs
+0
-37
Server/Model/Component/ServerFrameComponent.cs
Server/Model/Component/ServerFrameComponent.cs
+0
-42
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+0
-2
Unity/Assets/Resources/UI.prefab
Unity/Assets/Resources/UI.prefab
+60
-0
Unity/Assets/Resources/UI.prefab.meta
Unity/Assets/Resources/UI.prefab.meta
+9
-0
Unity/Assets/Scripts/Base/Message/AActorMessage.cs
Unity/Assets/Scripts/Base/Message/AActorMessage.cs
+4
-1
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
+1
-1
Unity/Assets/Scripts/Component/ClientFrameComponent.cs
Unity/Assets/Scripts/Component/ClientFrameComponent.cs
+40
-17
Unity/Assets/Scripts/Component/NetworkComponent.cs
Unity/Assets/Scripts/Component/NetworkComponent.cs
+4
-4
Unity/Assets/Scripts/Entity/Message/Opcode.cs
Unity/Assets/Scripts/Entity/Message/Opcode.cs
+1
-1
Unity/Assets/Scripts/Entity/Message/OuterMessage.cs
Unity/Assets/Scripts/Entity/Message/OuterMessage.cs
+4
-3
Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs
Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs
+1
-1
Unity/Hotfix/UI/UILogin/Factory/UILoginFactory.cs
Unity/Hotfix/UI/UILogin/Factory/UILoginFactory.cs
+1
-1
Unity/Unity.sln
Unity/Unity.sln
+1
-6
未找到文件。
Server/Hotfix/Handler/G2M_CreateUnitHandler.cs
浏览文件 @
02718b27
...
...
@@ -12,7 +12,7 @@ namespace Hotfix
try
{
Unit
unit
=
EntityFactory
.
Create
<
Unit
,
UnitType
>(
UnitType
.
Hero
);
await
unit
.
AddComponent
<
ActorComponent
>(
).
AddLocation
();
await
unit
.
AddComponent
<
ActorComponent
,
IEntityActorHandler
>(
new
MapUnitEntityActorHandler
()
).
AddLocation
();
unit
.
AddComponent
<
UnitGateComponent
,
long
>(
message
.
GateSessionId
);
Game
.
Scene
.
GetComponent
<
UnitComponent
>().
Add
(
unit
);
response
.
UnitId
=
unit
.
Id
;
...
...
Server/Hotfix/Helper/MessageHelper.cs
浏览文件 @
02718b27
...
...
@@ -4,12 +4,14 @@ namespace Hotfix
{
public
static
class
MessageHelper
{
public
static
void
Broadcast
<
Message
>(
Message
message
)
where
Message
:
AMessage
public
static
void
Broadcast
(
AActorMessage
message
)
{
Player
[]
players
=
Game
.
Scene
.
GetComponent
<
PlayerComponent
>().
GetAll
();
foreach
(
Player
gamer
in
players
)
Unit
[]
units
=
Game
.
Scene
.
GetComponent
<
UnitComponent
>().
GetAll
();
ActorProxyComponent
actorProxyComponent
=
Game
.
Scene
.
GetComponent
<
ActorProxyComponent
>();
foreach
(
Unit
unit
in
units
)
{
gamer
.
GetComponent
<
SessionInfoComponent
>().
Session
.
Send
(
message
);
long
gateSessionId
=
unit
.
GetComponent
<
UnitGateComponent
>().
GateSessionId
;
actorProxyComponent
.
Get
(
gateSessionId
).
Send
(
message
);
}
}
}
...
...
Server/Hotfix/Other/EntityActorHandler.cs
0 → 100644
浏览文件 @
02718b27
using
System.Threading.Tasks
;
using
Model
;
namespace
Hotfix
{
/// <summary>
/// gate session 收到的消息直接转发给客户端
/// </summary>
public
class
GateSessionEntityActorHandler
:
IEntityActorHandler
{
public
async
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
)
{
((
Session
)
entity
).
Send
(
message
.
AMessage
);
ActorResponse
response
=
new
ActorResponse
{
RpcId
=
message
.
RpcId
};
session
.
Reply
(
response
);
}
}
public
class
CommonEntityActorHandler
:
IEntityActorHandler
{
public
async
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
)
{
await
Game
.
Scene
.
GetComponent
<
ActorMessageDispatherComponent
>().
Handle
(
session
,
entity
,
message
);
}
}
/// <summary>
/// 玩家收到帧同步消息交给帧同步组件处理
/// </summary>
public
class
MapUnitEntityActorHandler
:
IEntityActorHandler
{
public
async
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
)
{
if
(
message
.
AMessage
is
AFrameMessage
aFrameMessage
)
{
Game
.
Scene
.
GetComponent
<
ServerFrameComponent
>().
Add
(
aFrameMessage
);
}
await
Game
.
Scene
.
GetComponent
<
ActorMessageDispatherComponent
>().
Handle
(
session
,
entity
,
message
);
}
}
}
\ No newline at end of file
Server/
Model/Base/Message
/InnerMessageDispatcher.cs
→
Server/
Hotfix/Other
/InnerMessageDispatcher.cs
浏览文件 @
02718b27
using
System
;
using
Model
;
namespace
Model
namespace
Hotfix
{
public
class
InnerMessageDispatcher
:
IMessageDispatcher
{
...
...
Server/
Model/Base/Message
/OuterMessageDispatcher.cs
→
Server/
Hotfix/Other
/OuterMessageDispatcher.cs
浏览文件 @
02718b27
using
System
;
using
Model
;
namespace
Model
namespace
Hotfix
{
public
class
OuterMessageDispatcher
:
IMessageDispatcher
{
...
...
Server/Hotfix/Server.Hotfix.csproj
浏览文件 @
02718b27
...
...
@@ -34,7 +34,6 @@
<Reference
Include=
"System.Core"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Component\RealmGateAddressComponentE.cs"
/>
<Compile
Include=
"Handler\M2M_TrasferUnitRequest.cs"
/>
<Compile
Include=
"Handler\Actor_TransferHandler.cs"
/>
<Compile
Include=
"Handler\Actor_TestRequestHandler.cs"
/>
...
...
@@ -58,8 +57,16 @@
<Compile
Include=
"Handler\C2M_ReloadHandler.cs"
/>
<Compile
Include=
"Handler\G2G_LockRequestHandler.cs"
/>
<Compile
Include=
"Handler\R2G_GetLoginKeyHandler.cs"
/>
<Compile
Include=
"Other\EntityActorHandler.cs"
/>
<Compile
Include=
"Other\InnerMessageDispatcher.cs"
/>
<Compile
Include=
"Other\OuterMessageDispatcher.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Handler\C2R_LoginHandler.cs"
/>
<Compile
Include=
"System\ActorSystem.cs"
/>
<Compile
Include=
"System\NetInnerSystem.cs"
/>
<Compile
Include=
"System\NetOuterSystem.cs"
/>
<Compile
Include=
"System\RealmGateAddressSystem.cs"
/>
<Compile
Include=
"System\ServerFrameSystem.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Base\Server.Base.csproj"
>
...
...
Server/Hotfix/System/ActorSystem.cs
0 → 100644
浏览文件 @
02718b27
using
System
;
using
System.Threading.Tasks
;
using
Model
;
namespace
Hotfix
{
[
ObjectEvent
]
public
class
ActorComponentEvent
:
ObjectEvent
<
ActorComponent
>,
IAwake
,
IAwake
<
IEntityActorHandler
>
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Awake
(
IEntityActorHandler
iEntityActorHandler
)
{
this
.
Get
().
Awake
(
iEntityActorHandler
);
}
}
/// <summary>
/// 挂上这个组件表示该Entity是一个Actor, 它会将Entity位置注册到Location Server, 接收的消息将会队列处理
/// </summary>
public
static
class
ActorSystem
{
public
static
void
Awake
(
this
ActorComponent
self
)
{
self
.
entityActorHandler
=
new
CommonEntityActorHandler
();
self
.
queue
=
new
EQueue
<
ActorMessageInfo
>();
self
.
actorId
=
self
.
Entity
.
Id
;
Game
.
Scene
.
GetComponent
<
ActorManagerComponent
>().
Add
(
self
.
Entity
);
self
.
HandleAsync
();
}
public
static
void
Awake
(
this
ActorComponent
self
,
IEntityActorHandler
iEntityActorHandler
)
{
self
.
entityActorHandler
=
iEntityActorHandler
;
self
.
queue
=
new
EQueue
<
ActorMessageInfo
>();
self
.
actorId
=
self
.
Entity
.
Id
;
Game
.
Scene
.
GetComponent
<
ActorManagerComponent
>().
Add
(
self
.
Entity
);
self
.
HandleAsync
();
}
public
static
async
Task
AddLocation
(
this
ActorComponent
self
)
{
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Add
(
self
.
actorId
);
}
public
static
async
Task
RemoveLocation
(
this
ActorComponent
self
)
{
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Remove
(
self
.
actorId
);
}
public
static
void
Add
(
this
ActorComponent
self
,
ActorMessageInfo
info
)
{
self
.
queue
.
Enqueue
(
info
);
if
(
self
.
tcs
==
null
)
{
return
;
}
var
t
=
self
.
tcs
;
self
.
tcs
=
null
;
t
.
SetResult
(
self
.
queue
.
Dequeue
());
}
private
static
Task
<
ActorMessageInfo
>
GetAsync
(
this
ActorComponent
self
)
{
if
(
self
.
queue
.
Count
>
0
)
{
return
Task
.
FromResult
(
self
.
queue
.
Dequeue
());
}
self
.
tcs
=
new
TaskCompletionSource
<
ActorMessageInfo
>();
return
self
.
tcs
.
Task
;
}
private
static
async
void
HandleAsync
(
this
ActorComponent
self
)
{
while
(
true
)
{
try
{
ActorMessageInfo
info
=
await
self
.
GetAsync
();
await
self
.
entityActorHandler
.
Handle
(
info
.
Session
,
self
.
Entity
,
info
.
Message
);
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
ToString
());
}
}
}
}
}
\ No newline at end of file
Server/Hotfix/System/NetInnerSystem.cs
0 → 100644
浏览文件 @
02718b27
using
Model
;
namespace
Hotfix
{
[
ObjectEvent
]
public
class
NetInnerComponentEvent
:
ObjectEvent
<
NetInnerComponent
>,
IAwake
,
IAwake
<
string
,
int
>,
IUpdate
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Awake
(
string
a
,
int
b
)
{
this
.
Get
().
Awake
(
a
,
b
);
}
public
void
Update
()
{
this
.
Get
().
Update
();
}
}
public
static
class
NetInnerSystem
{
public
static
void
Awake
(
this
NetInnerComponent
self
)
{
self
.
Awake
(
NetworkProtocol
.
TCP
);
self
.
MessagePacker
=
new
MongoPacker
();
self
.
MessageDispatcher
=
new
InnerMessageDispatcher
();
}
public
static
void
Awake
(
this
NetInnerComponent
self
,
string
host
,
int
port
)
{
self
.
Awake
(
NetworkProtocol
.
TCP
,
host
,
port
);
self
.
MessagePacker
=
new
MongoPacker
();
self
.
MessageDispatcher
=
new
InnerMessageDispatcher
();
}
public
static
void
Update
(
this
NetInnerComponent
self
)
{
self
.
Update
();
}
}
}
\ No newline at end of file
Server/Hotfix/System/NetOuterSystem.cs
0 → 100644
浏览文件 @
02718b27
using
Model
;
namespace
Hotfix
{
[
ObjectEvent
]
public
class
NetOuterComponentEvent
:
ObjectEvent
<
NetOuterComponent
>,
IAwake
,
IAwake
<
string
,
int
>,
IUpdate
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Awake
(
string
a
,
int
b
)
{
this
.
Get
().
Awake
(
a
,
b
);
}
public
void
Update
()
{
this
.
Get
().
Update
();
}
}
public
static
class
NetOuterSystem
{
public
static
void
Awake
(
this
NetOuterComponent
self
)
{
self
.
Awake
(
NetworkProtocol
.
TCP
);
self
.
MessagePacker
=
new
MongoPacker
();
self
.
MessageDispatcher
=
new
OuterMessageDispatcher
();
}
public
static
void
Awake
(
this
NetOuterComponent
self
,
string
host
,
int
port
)
{
self
.
Awake
(
NetworkProtocol
.
TCP
,
host
,
port
);
self
.
MessagePacker
=
new
MongoPacker
();
self
.
MessageDispatcher
=
new
OuterMessageDispatcher
();
}
public
static
void
Update
(
this
NetOuterComponent
self
)
{
self
.
Update
();
}
}
}
\ No newline at end of file
Server/Hotfix/
Component/RealmGateAddressComponentE
.cs
→
Server/Hotfix/
System/RealmGateAddressSystem
.cs
浏览文件 @
02718b27
...
...
@@ -11,7 +11,7 @@ namespace Hotfix
}
}
public
static
class
RealmGateAddress
ComponentE
public
static
class
RealmGateAddress
System
{
public
static
void
Start
(
this
RealmGateAddressComponent
component
)
{
...
...
Server/Hotfix/System/ServerFrameSystem.cs
0 → 100644
浏览文件 @
02718b27
using
Model
;
namespace
Hotfix
{
[
ObjectEvent
]
public
class
ServerFrameComponentEvent
:
ObjectEvent
<
ServerFrameComponent
>,
IAwake
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
}
public
static
class
ServerFrameSystem
{
public
static
void
Awake
(
this
ServerFrameComponent
self
)
{
self
.
Frame
=
0
;
self
.
FrameMessage
=
new
FrameMessage
()
{
Frame
=
self
.
Frame
};
self
.
UpdateFrameAsync
();
}
public
static
async
void
UpdateFrameAsync
(
this
ServerFrameComponent
self
)
{
TimerComponent
timerComponent
=
Game
.
Scene
.
GetComponent
<
TimerComponent
>();
while
(
true
)
{
if
(
self
.
Id
==
0
)
{
return
;
}
await
timerComponent
.
WaitAsync
(
40
);
MessageHelper
.
Broadcast
(
self
.
FrameMessage
);
++
self
.
Frame
;
self
.
FrameMessage
=
new
FrameMessage
()
{
Frame
=
self
.
Frame
};
}
}
public
static
void
Add
(
this
ServerFrameComponent
self
,
AFrameMessage
message
)
{
self
.
FrameMessage
.
Messages
.
Add
(
message
);
}
}
}
\ No newline at end of file
Server/Model/Base/Message/AActorMessage.cs
浏览文件 @
02718b27
...
...
@@ -3,6 +3,7 @@
namespace
Model
{
[
BsonKnownTypes
(
typeof
(
Actor_Test
))]
[
BsonKnownTypes
(
typeof
(
AFrameMessage
))]
public
abstract
class
AActorMessage
:
AMessage
{
}
...
...
@@ -19,6 +20,10 @@ namespace Model
{
}
/// <summary>
/// 帧消息,继承这个类的消息会经过服务端转发
/// </summary>
[
BsonKnownTypes
(
typeof
(
Frame_ClickMap
))]
public
abstract
class
AFrameMessage
:
AActorMessage
{
public
long
Id
;
...
...
Server/Model/Base/Message/IEntityActorHandler.cs
浏览文件 @
02718b27
...
...
@@ -6,40 +6,4 @@ namespace Model
{
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
);
}
/// <summary>
/// gate session 收到的消息直接转发给客户端
/// </summary>
public
class
GateSessionEntityActorHandler
:
IEntityActorHandler
{
public
async
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
)
{
((
Session
)
entity
).
Send
(
message
.
AMessage
);
ActorResponse
response
=
new
ActorResponse
{
RpcId
=
message
.
RpcId
};
session
.
Reply
(
response
);
}
}
public
class
CommonEntityActorHandler
:
IEntityActorHandler
{
public
async
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
)
{
await
Game
.
Scene
.
GetComponent
<
ActorMessageDispatherComponent
>().
Handle
(
session
,
entity
,
message
);
}
}
public
class
MapUnitEntityActorHandler
:
IEntityActorHandler
{
public
async
Task
Handle
(
Session
session
,
Entity
entity
,
ActorRequest
message
)
{
if
(
message
.
AMessage
is
AFrameMessage
aFrameMessage
)
{
Game
.
Scene
.
GetComponent
<
ServerFrameComponent
>().
Add
(
aFrameMessage
);
}
await
Game
.
Scene
.
GetComponent
<
ActorMessageDispatherComponent
>().
Handle
(
session
,
entity
,
message
);
}
}
}
\ No newline at end of file
Server/Model/Component/ActorComponent.cs
浏览文件 @
02718b27
...
...
@@ -9,102 +9,19 @@ namespace Model
public
ActorRequest
Message
;
}
[
ObjectEvent
]
public
class
ActorComponentEvent
:
ObjectEvent
<
ActorComponent
>,
IAwake
,
IAwake
<
IEntityActorHandler
>
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Awake
(
IEntityActorHandler
iEntityActorHandler
)
{
this
.
Get
().
Awake
(
iEntityActorHandler
);
}
}
/// <summary>
/// 挂上这个组件表示该Entity是一个Actor, 它会将Entity位置注册到Location Server, 接收的消息将会队列处理
/// </summary>
public
class
ActorComponent
:
Component
{
p
rivate
IEntityActorHandler
entityActorHandler
;
p
ublic
IEntityActorHandler
entityActorHandler
;
p
rivate
long
actorId
;
p
ublic
long
actorId
;
// 队列处理消息
private
readonly
EQueue
<
ActorMessageInfo
>
queue
=
new
EQueue
<
ActorMessageInfo
>();
private
TaskCompletionSource
<
ActorMessageInfo
>
tcs
;
public
void
Awake
()
{
this
.
entityActorHandler
=
new
CommonEntityActorHandler
();
public
EQueue
<
ActorMessageInfo
>
queue
;
this
.
actorId
=
this
.
Entity
.
Id
;
Game
.
Scene
.
GetComponent
<
ActorManagerComponent
>().
Add
(
this
.
Entity
);
this
.
HandleAsync
();
}
public
void
Awake
(
IEntityActorHandler
iEntityActorHandler
)
{
this
.
entityActorHandler
=
iEntityActorHandler
;
this
.
actorId
=
this
.
Entity
.
Id
;
Game
.
Scene
.
GetComponent
<
ActorManagerComponent
>().
Add
(
this
.
Entity
);
this
.
HandleAsync
();
}
public
async
Task
AddLocation
()
{
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Add
(
this
.
actorId
);
}
public
async
Task
RemoveLocation
()
{
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Remove
(
this
.
actorId
);
}
public
void
Add
(
ActorMessageInfo
info
)
{
this
.
queue
.
Enqueue
(
info
);
if
(
this
.
tcs
==
null
)
{
return
;
}
var
t
=
this
.
tcs
;
this
.
tcs
=
null
;
t
.
SetResult
(
this
.
queue
.
Dequeue
());
}
private
Task
<
ActorMessageInfo
>
GetAsync
()
{
if
(
this
.
queue
.
Count
>
0
)
{
return
Task
.
FromResult
(
this
.
queue
.
Dequeue
());
}
this
.
tcs
=
new
TaskCompletionSource
<
ActorMessageInfo
>();
return
this
.
tcs
.
Task
;
}
private
async
void
HandleAsync
()
{
while
(
true
)
{
try
{
ActorMessageInfo
info
=
await
this
.
GetAsync
();
await
this
.
entityActorHandler
.
Handle
(
info
.
Session
,
this
.
Entity
,
info
.
Message
);
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
ToString
());
}
}
}
public
TaskCompletionSource
<
ActorMessageInfo
>
tcs
;
public
override
void
Dispose
()
{
...
...
Server/Model/Component/NetInnerComponent.cs
浏览文件 @
02718b27
...
...
@@ -2,47 +2,9 @@
namespace
Model
{
[
ObjectEvent
]
public
class
NetInnerComponentEvent
:
ObjectEvent
<
NetInnerComponent
>,
IAwake
,
IAwake
<
string
,
int
>,
IUpdate
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Awake
(
string
a
,
int
b
)
{
this
.
Get
().
Awake
(
a
,
b
);
}
public
void
Update
()
{
this
.
Get
().
Update
();
}
}
public
class
NetInnerComponent
:
NetworkComponent
{
private
readonly
Dictionary
<
string
,
Session
>
adressSessions
=
new
Dictionary
<
string
,
Session
>();
public
void
Awake
()
{
this
.
Awake
(
NetworkProtocol
.
TCP
);
this
.
MessagePacker
=
new
MongoPacker
();
this
.
MessageDispatcher
=
new
InnerMessageDispatcher
();
}
public
void
Awake
(
string
host
,
int
port
)
{
this
.
Awake
(
NetworkProtocol
.
TCP
,
host
,
port
);
this
.
MessagePacker
=
new
MongoPacker
();
this
.
MessageDispatcher
=
new
InnerMessageDispatcher
();
}
public
new
void
Update
()
{
base
.
Update
();
}
public
readonly
Dictionary
<
string
,
Session
>
adressSessions
=
new
Dictionary
<
string
,
Session
>();
public
override
void
Remove
(
long
id
)
{
...
...
Server/Model/Component/NetOuterComponent.cs
浏览文件 @
02718b27
namespace
Model
{
[
ObjectEvent
]
public
class
NetOuterComponentEvent
:
ObjectEvent
<
NetOuterComponent
>,
IAwake
,
IAwake
<
string
,
int
>,
IUpdate
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Awake
(
string
a
,
int
b
)
{
this
.
Get
().
Awake
(
a
,
b
);
}
public
void
Update
()
{
this
.
Get
().
Update
();
}
}
public
class
NetOuterComponent
:
NetworkComponent
{
public
void
Awake
()
{
this
.
Awake
(
NetworkProtocol
.
TCP
);
this
.
MessagePacker
=
new
MongoPacker
();
this
.
MessageDispatcher
=
new
OuterMessageDispatcher
();
}
public
void
Awake
(
string
host
,
int
port
)
{
this
.
Awake
(
NetworkProtocol
.
TCP
,
host
,
port
);
this
.
MessagePacker
=
new
MongoPacker
();
this
.
MessageDispatcher
=
new
OuterMessageDispatcher
();
}
public
new
void
Update
()
{
base
.
Update
();
}
}
}
\ No newline at end of file
Server/Model/Component/ServerFrameComponent.cs
浏览文件 @
02718b27
namespace
Model
{
[
ObjectEvent
]
public
class
ServerFrameComponentEvent
:
ObjectEvent
<
ServerFrameComponent
>,
IAwake
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
}
public
class
ServerFrameComponent
:
Component
{
public
int
Frame
;
public
FrameMessage
FrameMessage
;
public
void
Awake
()
{
this
.
Frame
=
0
;
this
.
FrameMessage
=
new
FrameMessage
()
{
Frame
=
this
.
Frame
};
this
.
UpdateFrameAsync
();
}
public
async
void
UpdateFrameAsync
()
{
TimerComponent
timerComponent
=
Game
.
Scene
.
GetComponent
<
TimerComponent
>();
while
(
true
)
{
if
(
this
.
Id
==
0
)
{
return
;
}
await
timerComponent
.
WaitAsync
(
30
);
//MessageHelper.Broadcast(this.FrameMessage);
++
this
.
Frame
;
this
.
FrameMessage
=
new
FrameMessage
()
{
Frame
=
this
.
Frame
};
}
}
public
void
Add
(
AFrameMessage
message
)
{
this
.
FrameMessage
.
Messages
.
Add
(
message
);
}
}
}
Server/Model/Server.Model.csproj
浏览文件 @
02718b27
...
...
@@ -208,8 +208,6 @@
<Compile
Include=
"Base\Message\AMActorHandler.cs"
/>
<Compile
Include=
"Base\Message\ErrorCode.cs"
/>
<Compile
Include=
"Base\Message\IMActorHandler.cs"
/>
<Compile
Include=
"Base\Message\OuterMessageDispatcher.cs"
/>
<Compile
Include=
"Base\Message\InnerMessageDispatcher.cs"
/>
<Compile
Include=
"Base\Message\IMHandler.cs"
/>
<Compile
Include=
"Base\Message\ActorMessageAttribute.cs"
/>
<Compile
Include=
"Base\Message\MessageAttribute.cs"
/>
...
...
Unity/Assets/Resources/UI.prefab
0 → 100644
浏览文件 @
02718b27
%YAML
1.1
%TAG
!u!
tag:unity3d.com,2011:
---
!u!1001
&100100000
Prefab
:
m_ObjectHideFlags
:
1
serializedVersion
:
2
m_Modification
:
m_TransformParent
:
{
fileID
:
0
}
m_Modifications
:
[]
m_RemovedComponents
:
[]
m_ParentPrefab
:
{
fileID
:
0
}
m_RootGameObject
:
{
fileID
:
1770158272730698
}
m_IsPrefabParent
:
1
---
!u!1
&1770158272730698
GameObject
:
m_ObjectHideFlags
:
0
m_PrefabParentObject
:
{
fileID
:
0
}
m_PrefabInternal
:
{
fileID
:
100100000
}
serializedVersion
:
5
m_Component
:
-
component
:
{
fileID
:
4092934652491172
}
-
component
:
{
fileID
:
114471626497006264
}
m_Layer
:
0
m_Name
:
UI
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
m_NavMeshLayer
:
0
m_StaticEditorFlags
:
0
m_IsActive
:
1
---
!u!4
&4092934652491172
Transform
:
m_ObjectHideFlags
:
1
m_PrefabParentObject
:
{
fileID
:
0
}
m_PrefabInternal
:
{
fileID
:
100100000
}
m_GameObject
:
{
fileID
:
1770158272730698
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
0
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
---
!u!114
&114471626497006264
MonoBehaviour
:
m_ObjectHideFlags
:
1
m_PrefabParentObject
:
{
fileID
:
0
}
m_PrefabInternal
:
{
fileID
:
100100000
}
m_GameObject
:
{
fileID
:
1770158272730698
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
502d8cafd6a5a0447ab1db9a24cdcb10
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
data
:
-
key
:
UILogin
gameObject
:
{
fileID
:
1386170326414932
,
guid
:
9f6d9adc6f537764fa0fea29671e77bf
,
type
:
2
}
-
key
:
UILobby
gameObject
:
{
fileID
:
1386170326414932
,
guid
:
d8d87e53d93e234448658c9a801a9967
,
type
:
2
}
Unity/Assets/Resources/UI.prefab.meta
0 → 100644
浏览文件 @
02718b27
fileFormatVersion: 2
guid: 5b68b797892145f46a5553c74f060976
timeCreated: 1506131440
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Base/Message/AActorMessage.cs
浏览文件 @
02718b27
namespace
Model
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Model
{
public
abstract
class
AActorMessage
:
AMessage
{
...
...
@@ -12,6 +14,7 @@
{
}
[
BsonKnownTypes
(
typeof
(
Frame_ClickMap
))]
public
abstract
class
AFrameMessage
:
AActorMessage
{
public
long
Id
;
...
...
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
浏览文件 @
02718b27
...
...
@@ -17,7 +17,7 @@ namespace Model
// 普通消息或者是Rpc请求消息
if
(
message
is
AMessage
||
message
is
ARequest
)
{
MessageInfo
messageInfo
=
new
MessageInfo
(
opcode
,
(
AMessage
)
message
);
MessageInfo
messageInfo
=
new
MessageInfo
(
opcode
,
message
);
if
(
opcode
<
2000
)
{
Game
.
Scene
.
GetComponent
<
CrossComponent
>().
Run
(
CrossIdType
.
MessageDeserializeFinish
,
messageInfo
);
...
...
Unity/Assets/Scripts/Component/ClientFrameComponent.cs
浏览文件 @
02718b27
using
System.Collections.Generic
;
namespace
Model
namespace
Model
{
[
ObjectEvent
]
public
class
ClientFrameComponentEvent
:
ObjectEvent
<
ClientFrameComponent
>,
I
Update
public
class
ClientFrameComponentEvent
:
ObjectEvent
<
ClientFrameComponent
>,
I
Start
{
public
void
Update
()
public
void
Start
()
{
this
.
Get
().
Update
();
this
.
Get
().
Start
();
}
}
...
...
@@ -15,31 +13,58 @@ namespace Model
{
public
int
Frame
;
public
Queue
<
FrameMessage
>
Queue
=
new
Queue
<
FrameMessage
>();
public
EQueue
<
FrameMessage
>
Queue
=
new
E
Queue
<
FrameMessage
>();
public
int
count
=
1
;
public
int
waitTime
;
public
const
int
maxWaitTime
=
40
;
public
void
Start
()
{
UpdateAsync
();
}
public
void
Add
(
FrameMessage
frameMessage
)
{
this
.
Queue
.
Enqueue
(
frameMessage
);
}
public
void
Update
()
public
async
void
UpdateAsync
()
{
int
queueCount
=
this
.
Queue
.
Count
;
if
(
queueCount
==
0
)
{
return
;
}
this
.
count
=
1
+
(
queueCount
+
3
)
/
5
;
for
(
int
i
=
0
;
i
<
this
.
count
;
i
++)
TimerComponent
timerComponent
=
Game
.
Scene
.
GetComponent
<
TimerComponent
>();
while
(
true
)
{
// 如果队列中消息多于4个,则加速跑帧
this
.
waitTime
=
maxWaitTime
;
if
(
this
.
Queue
.
Count
>
4
)
{
this
.
waitTime
=
maxWaitTime
-
(
this
.
Queue
.
Count
-
4
)
*
2
;
}
// 最快加速一倍
if
(
this
.
waitTime
<
20
)
{
this
.
waitTime
=
20
;
}
await
timerComponent
.
WaitAsync
(
waitTime
);
if
(
this
.
Id
==
0
)
{
return
;
}
this
.
UpdateFrame
();
}
}
private
void
UpdateFrame
()
{
if
(
this
.
Queue
.
Count
==
0
)
{
return
;
}
FrameMessage
frameMessage
=
this
.
Queue
.
Dequeue
();
this
.
Frame
=
frameMessage
.
Frame
;
...
...
@@ -49,8 +74,6 @@ namespace Model
ushort
opcode
=
Game
.
Scene
.
GetComponent
<
OpcodeTypeComponent
>().
GetOpcode
(
message
.
GetType
());
Game
.
Scene
.
GetComponent
<
MessageDispatherComponent
>().
Handle
(
new
MessageInfo
()
{
Opcode
=
opcode
,
Message
=
message
});
}
Game
.
Scene
.
GetComponent
<
CrossComponent
>().
Run
(
CrossIdType
.
FrameUpdate
);
}
}
}
Unity/Assets/Scripts/Component/NetworkComponent.cs
浏览文件 @
02718b27
...
...
@@ -11,9 +11,9 @@ namespace Model
private
readonly
Dictionary
<
long
,
Session
>
sessions
=
new
Dictionary
<
long
,
Session
>();
public
IMessagePacker
MessagePacker
{
get
;
protected
set
;
}
public
IMessagePacker
MessagePacker
{
get
;
set
;
}
public
IMessageDispatcher
MessageDispatcher
{
get
;
protected
set
;
}
public
IMessageDispatcher
MessageDispatcher
{
get
;
set
;
}
public
void
Awake
(
NetworkProtocol
protocol
)
{
...
...
@@ -30,7 +30,7 @@ namespace Model
}
}
p
rotected
void
Awake
(
NetworkProtocol
protocol
,
string
host
,
int
port
)
p
ublic
void
Awake
(
NetworkProtocol
protocol
,
string
host
,
int
port
)
{
switch
(
protocol
)
{
...
...
@@ -110,7 +110,7 @@ namespace Model
}
}
p
rotected
void
Update
()
p
ublic
void
Update
()
{
if
(
this
.
Service
==
null
)
{
...
...
Unity/Assets/Scripts/Entity/Message/Opcode.cs
浏览文件 @
02718b27
...
...
@@ -17,6 +17,6 @@
public
const
ushort
Actor_TestResponse
=
2003
;
public
const
ushort
Actor_TransferRequest
=
2004
;
public
const
ushort
Actor_TransferResponse
=
2005
;
public
const
ushort
Actor
_ClickMap
=
2006
;
public
const
ushort
Frame
_ClickMap
=
2006
;
}
}
Unity/Assets/Scripts/Entity/Message/OuterMessage.cs
浏览文件 @
02718b27
...
...
@@ -78,14 +78,15 @@ namespace Model
// 服务端发给客户端,每帧一条
[
Message
(
Opcode
.
FrameMessage
)]
public
class
FrameMessage
:
AMessage
public
class
FrameMessage
:
A
Actor
Message
{
public
int
Frame
;
public
List
<
AFrameMessage
>
Messages
=
new
List
<
AFrameMessage
>();
}
[
Message
(
Opcode
.
Actor_ClickMap
)]
public
class
Actor_ClickMap
:
AActorMessage
// 客户端点击地图
[
Message
(
Opcode
.
Frame_ClickMap
)]
public
class
Frame_ClickMap
:
AFrameMessage
{
}
...
...
Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs
浏览文件 @
02718b27
...
...
@@ -11,7 +11,7 @@ namespace Hotfix
{
try
{
GameObject
bundleGameObject
=
scene
.
ModelScene
.
GetComponent
<
ResourcesComponent
>().
GetAsset
<
GameObject
>(
"uilogin"
,
"UILobby"
);
GameObject
bundleGameObject
=
((
GameObject
)
Resources
.
Load
(
"UI"
)).
Get
<
GameObject
>(
"UILobby"
);
GameObject
lobby
=
UnityEngine
.
Object
.
Instantiate
(
bundleGameObject
);
lobby
.
layer
=
LayerMask
.
NameToLayer
(
LayerNames
.
UI
);
UI
ui
=
new
UI
(
scene
,
type
,
null
,
lobby
);
...
...
Unity/Hotfix/UI/UILogin/Factory/UILoginFactory.cs
浏览文件 @
02718b27
...
...
@@ -11,7 +11,7 @@ namespace Hotfix
{
try
{
GameObject
bundleGameObject
=
scene
.
ModelScene
.
GetComponent
<
ResourcesComponent
>().
GetAsset
<
GameObject
>(
"uilogin"
,
"UILogin"
);
GameObject
bundleGameObject
=
((
GameObject
)
Resources
.
Load
(
"UI"
)).
Get
<
GameObject
>(
"UILogin"
);
GameObject
lobby
=
UnityEngine
.
Object
.
Instantiate
(
bundleGameObject
);
lobby
.
layer
=
LayerMask
.
NameToLayer
(
LayerNames
.
UI
);
UI
ui
=
new
UI
(
scene
,
type
,
null
,
lobby
);
...
...
Unity/Unity.sln
浏览文件 @
02718b27
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
# Visual Studio 2017
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity", "Unity.csproj", "{CF118143-7E37-744F-BE45-3F55345FEC40}"
...
...
@@ -43,7 +41,4 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {831A2AF4-3FBE-48B2-8E2B-F2D54966AE04}
EndGlobalSection
EndGlobal
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录