Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
1d01430f
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 搜索 >>
提交
1d01430f
编写于
10月 27, 2017
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
抹平了hotfix层跟mono层消息分发,hotfix跟mono层可以同时订阅同一个消息
上级
75d55186
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
129 addition
and
124 deletion
+129
-124
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
+1
-8
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
+111
-9
Unity/Hotfix/Base/Message/AMHandler.cs
Unity/Hotfix/Base/Message/AMHandler.cs
+1
-1
Unity/Hotfix/Base/Message/IMHandler.cs
Unity/Hotfix/Base/Message/IMHandler.cs
+7
-1
Unity/Hotfix/Component/MessageDispatherComponent.cs
Unity/Hotfix/Component/MessageDispatherComponent.cs
+0
-89
Unity/Hotfix/Event/SessionRecvMessage_Dispatch.cs
Unity/Hotfix/Event/SessionRecvMessage_Dispatch.cs
+0
-14
Unity/Hotfix/Unity.Hotfix.csproj
Unity/Hotfix/Unity.Hotfix.csproj
+1
-2
Unity/Unity.Editor.Plugins.csproj
Unity/Unity.Editor.Plugins.csproj
+2
-0
Unity/Unity.Editor.csproj
Unity/Unity.Editor.csproj
+2
-0
Unity/Unity.Plugins.csproj
Unity/Unity.Plugins.csproj
+2
-0
Unity/Unity.csproj
Unity/Unity.csproj
+2
-0
未找到文件。
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
浏览文件 @
1d01430f
...
...
@@ -18,14 +18,7 @@ namespace Model
if
(
message
is
AMessage
||
message
is
ARequest
)
{
MessageInfo
messageInfo
=
new
MessageInfo
(
opcode
,
message
);
if
(
opcode
<
2000
)
{
Game
.
Scene
.
GetComponent
<
EventComponent
>().
Run
(
EventIdType
.
MessageDeserializeFinish
,
messageInfo
);
}
else
{
Game
.
Scene
.
GetComponent
<
MessageDispatherComponent
>().
Handle
(
messageInfo
);
}
Game
.
Scene
.
GetComponent
<
MessageDispatherComponent
>().
Handle
(
messageInfo
);
return
;
}
...
...
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
浏览文件 @
1d01430f
using
System
;
using
System.Collections.Generic
;
using
System.Reflection
;
using
ILRuntime.CLR.Method
;
using
ILRuntime.Runtime.Intepreter
;
namespace
Model
{
/// <summary>
/// 用来抹平ILRuntime跟mono层差异
/// </summary>
public
interface
IMessageMethod
{
void
Run
(
AMessage
a
);
}
public
class
IMessageMonoMethod
:
IMessageMethod
{
private
readonly
IMHandler
iMHandler
;
public
IMessageMonoMethod
(
IMHandler
iMHandler
)
{
this
.
iMHandler
=
iMHandler
;
}
public
void
Run
(
AMessage
a
)
{
this
.
iMHandler
.
Handle
(
a
);
}
}
public
class
IMessageILMethod
:
IMessageMethod
{
private
readonly
ILRuntime
.
Runtime
.
Enviorment
.
AppDomain
appDomain
;
private
readonly
ILTypeInstance
instance
;
private
readonly
IMethod
method
;
private
readonly
object
[]
param
;
public
IMessageILMethod
(
Type
type
,
string
methodName
)
{
appDomain
=
Init
.
Instance
.
AppDomain
;
this
.
instance
=
this
.
appDomain
.
Instantiate
(
type
.
FullName
);
this
.
method
=
this
.
instance
.
Type
.
GetMethod
(
methodName
);
int
n
=
this
.
method
.
ParameterCount
;
this
.
param
=
new
object
[
n
];
}
public
void
Run
(
AMessage
a
)
{
this
.
param
[
0
]
=
a
;
this
.
appDomain
.
Invoke
(
this
.
method
,
this
.
instance
,
param
);
}
}
[
ObjectEvent
]
public
class
MessageDispatherComponentEvent
:
ObjectEvent
<
MessageDispatherComponent
>,
IAwake
,
ILoad
{
...
...
@@ -17,12 +67,41 @@ namespace Model
}
}
public
static
class
Opcode2Name
{
private
static
Dictionary
<
int
,
string
>
_init
=
new
Dictionary
<
int
,
string
>();
public
static
string
GetName
(
int
code
)
{
if
(
_init
.
Count
==
0
)
{
Type
type
=
typeof
(
Opcode
);
FieldInfo
[]
fields
=
type
.
GetFields
(
BindingFlags
.
NonPublic
|
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
Static
);
foreach
(
FieldInfo
field
in
fields
)
{
if
(!
field
.
IsStatic
)
{
continue
;
}
int
codeID
=
(
ushort
)
field
.
GetValue
(
null
);
if
(
_init
.
ContainsKey
(
codeID
))
{
Log
.
Warning
(
$"重复的Opcode:
{
codeID
}
"
);
continue
;
}
_init
.
Add
(
codeID
,
field
.
Name
);
}
}
return
_init
[
code
];
}
}
/// <summary>
/// 消息分发组件
/// </summary>
public
class
MessageDispatherComponent
:
Component
{
private
Dictionary
<
ushort
,
List
<
IMHandler
>>
handlers
;
private
Dictionary
<
ushort
,
List
<
IMessageMethod
>>
handlers
;
public
void
Awake
()
{
...
...
@@ -31,7 +110,7 @@ namespace Model
public
void
Load
()
{
handlers
=
new
Dictionary
<
ushort
,
List
<
IM
Handler
>>();
handlers
=
new
Dictionary
<
ushort
,
List
<
IM
essageMethod
>>();
Type
[]
types
=
DllHelper
.
GetMonoTypes
();
...
...
@@ -46,26 +125,49 @@ namespace Model
IMHandler
iMHandler
=
(
IMHandler
)
Activator
.
CreateInstance
(
type
);
if
(!
this
.
handlers
.
ContainsKey
(
messageHandlerAttribute
.
Opcode
))
{
this
.
handlers
.
Add
(
messageHandlerAttribute
.
Opcode
,
new
List
<
IMHandler
>());
this
.
handlers
.
Add
(
messageHandlerAttribute
.
Opcode
,
new
List
<
IMessageMethod
>());
}
this
.
handlers
[
messageHandlerAttribute
.
Opcode
].
Add
(
new
IMessageMonoMethod
(
iMHandler
));
}
// hotfix dll
Type
[]
hotfixTypes
=
DllHelper
.
GetHotfixTypes
();
foreach
(
Type
type
in
hotfixTypes
)
{
object
[]
attrs
=
type
.
GetCustomAttributes
(
typeof
(
MessageHandlerAttribute
),
false
);
if
(
attrs
.
Length
==
0
)
{
continue
;
}
MessageHandlerAttribute
messageHandlerAttribute
=
(
MessageHandlerAttribute
)
attrs
[
0
];
#if ILRuntime
IMessageMethod
iMessageMethod
=
new
IMessageILMethod
(
type
,
"Run"
);
#else
IMHandler
iMHandler
=
(
IMHandler
)
Activator
.
CreateInstance
(
type
);
IMessageMethod
iMessageMethod
=
new
IMessageMonoMethod
(
iMHandler
);
#endif
if
(!
this
.
handlers
.
ContainsKey
(
messageHandlerAttribute
.
Opcode
))
{
this
.
handlers
.
Add
(
messageHandlerAttribute
.
Opcode
,
new
List
<
IMessageMethod
>());
}
this
.
handlers
[
messageHandlerAttribute
.
Opcode
].
Add
(
iM
Handler
);
this
.
handlers
[
messageHandlerAttribute
.
Opcode
].
Add
(
iM
essageMethod
);
}
}
public
void
Handle
(
MessageInfo
messageInfo
)
{
List
<
IM
Handler
>
actions
;
List
<
IM
essageMethod
>
actions
;
if
(!
this
.
handlers
.
TryGetValue
(
messageInfo
.
Opcode
,
out
actions
))
{
Log
.
Error
(
$"消息
{
messageInfo
.
Opcode
}
没有处理"
);
Log
.
Error
(
$"消息
{
Opcode2Name
.
GetName
(
messageInfo
.
Opcode
)}
(
{
messageInfo
.
Opcode
}
)
没有处理"
);
return
;
}
foreach
(
IM
Handler
ev
in
actions
)
foreach
(
IM
essageMethod
ev
in
actions
)
{
try
{
ev
.
Handle
(
messageInfo
.
Message
);
ev
.
Run
(
messageInfo
.
Message
);
}
catch
(
Exception
e
)
{
...
...
@@ -76,7 +178,7 @@ namespace Model
public
override
void
Dispose
()
{
if
(
this
.
Id
==
0
)
if
(
Id
==
0
)
{
return
;
}
...
...
Unity/Hotfix/Base/Message/AMHandler.cs
浏览文件 @
1d01430f
...
...
@@ -7,7 +7,7 @@ namespace Hotfix
{
protected
abstract
void
Run
(
Message
message
);
public
void
Handle
(
object
msg
)
public
void
Handle
(
AMessage
msg
)
{
Message
message
=
msg
as
Message
;
if
(
message
==
null
)
...
...
Unity/Hotfix/Base/Message/IMHandler.cs
浏览文件 @
1d01430f
...
...
@@ -2,9 +2,15 @@
namespace
Hotfix
{
#if ILRuntime
public
interface
IMHandler
{
void
Handle
(
object
message
);
void
Handle
(
AMessage
message
);
Type
GetMessageType
();
}
#else
public
interface
IMHandler
:
Model
.
IMHandler
{
}
#endif
}
\ No newline at end of file
Unity/Hotfix/Component/MessageDispatherComponent.cs
已删除
100644 → 0
浏览文件 @
75d55186
using
System
;
using
System.Collections.Generic
;
using
Model
;
namespace
Hotfix
{
[
ObjectEvent
]
public
class
MessageDispatherComponentEvent
:
ObjectEvent
<
MessageDispatherComponent
>,
IAwake
,
ILoad
{
public
void
Awake
()
{
this
.
Get
().
Awake
();
}
public
void
Load
()
{
this
.
Get
().
Load
();
}
}
/// <summary>
/// 消息分发组件
/// </summary>
public
class
MessageDispatherComponent
:
Component
,
IAwake
,
ILoad
{
private
Dictionary
<
ushort
,
List
<
IMHandler
>>
handlers
;
public
void
Awake
()
{
this
.
Load
();
}
public
void
Load
()
{
handlers
=
new
Dictionary
<
ushort
,
List
<
IMHandler
>>();
Type
[]
types
=
DllHelper
.
GetHotfixTypes
();
foreach
(
Type
type
in
types
)
{
object
[]
attrs
=
type
.
GetCustomAttributes
(
typeof
(
MessageHandlerAttribute
),
false
);
if
(
attrs
.
Length
==
0
)
{
continue
;
}
MessageHandlerAttribute
messageHandlerAttribute
=
(
MessageHandlerAttribute
)
attrs
[
0
];
IMHandler
iMHandler
=
(
IMHandler
)
Activator
.
CreateInstance
(
type
);
if
(!
this
.
handlers
.
ContainsKey
(
messageHandlerAttribute
.
Opcode
))
{
this
.
handlers
.
Add
(
messageHandlerAttribute
.
Opcode
,
new
List
<
IMHandler
>());
}
this
.
handlers
[
messageHandlerAttribute
.
Opcode
].
Add
(
iMHandler
);
}
}
public
void
Handle
(
MessageInfo
messageInfo
)
{
List
<
IMHandler
>
actions
;
if
(!
this
.
handlers
.
TryGetValue
(
messageInfo
.
Opcode
,
out
actions
))
{
Log
.
Error
(
$"消息
{
messageInfo
.
Opcode
}
没有处理"
);
return
;
}
foreach
(
IMHandler
ev
in
actions
)
{
try
{
ev
.
Handle
(
messageInfo
.
Message
);
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
ToStr
());
}
}
}
public
override
void
Dispose
()
{
if
(
this
.
Id
==
0
)
{
return
;
}
base
.
Dispose
();
}
}
}
\ No newline at end of file
Unity/Hotfix/Event/SessionRecvMessage_Dispatch.cs
已删除
100644 → 0
浏览文件 @
75d55186
using
Model
;
namespace
Hotfix
{
// 订阅mono层的Session发出的事件
[
Event
((
int
)
EventIdType
.
MessageDeserializeFinish
)]
public
class
MessageDeserializeFinish_Dispatch
:
IEvent
<
MessageInfo
>
{
public
void
Run
(
MessageInfo
messageInfo
)
{
Hotfix
.
Scene
.
GetComponent
<
MessageDispatherComponent
>().
Handle
(
messageInfo
);
}
}
}
Unity/Hotfix/Unity.Hotfix.csproj
浏览文件 @
1d01430f
...
...
@@ -80,14 +80,12 @@
<Compile
Include=
"Base\Other\IUIFactory.cs"
/>
<Compile
Include=
"Component\GameObjectComponent.cs"
/>
<Compile
Include=
"Component\KVComponent.cs"
/>
<Compile
Include=
"Component\MessageDispatherComponent.cs"
/>
<Compile
Include=
"Component\TimeComponent.cs"
/>
<Compile
Include=
"Component\TimerComponent.cs"
/>
<Compile
Include=
"Component\UIComponent.cs"
/>
<Compile
Include=
"Entity\Hotfix.cs"
/>
<Compile
Include=
"Entity\Scene.cs"
/>
<Compile
Include=
"Entity\UI.cs"
/>
<Compile
Include=
"Event\SessionRecvMessage_Dispatch.cs"
/>
<Compile
Include=
"Init.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"UI\UILobby\Component\UILobbyComponent.cs"
/>
...
...
@@ -97,6 +95,7 @@
<Compile
Include=
"UI\UILogin\Factory\UILoginFactory.cs"
/>
</ItemGroup>
<ItemGroup>
<Folder
Include=
"Event\"
/>
<Folder
Include=
"Handler\"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
...
...
Unity/Unity.Editor.Plugins.csproj
浏览文件 @
1d01430f
...
...
@@ -164,6 +164,8 @@
<ItemGroup>
<None
Include=
"Assets\Res\Config\BuffConfig.txt"
/>
<None
Include=
"Assets\Res\Config\UnitConfig.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Error.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Info.txt"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
...
...
Unity/Unity.Editor.csproj
浏览文件 @
1d01430f
...
...
@@ -214,6 +214,8 @@
<ItemGroup>
<None
Include=
"Assets\Res\Config\BuffConfig.txt"
/>
<None
Include=
"Assets\Res\Config\UnitConfig.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Error.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Info.txt"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
...
...
Unity/Unity.Plugins.csproj
浏览文件 @
1d01430f
...
...
@@ -516,6 +516,8 @@
<ItemGroup>
<None
Include=
"Assets\Res\Config\BuffConfig.txt"
/>
<None
Include=
"Assets\Res\Config\UnitConfig.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Error.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Info.txt"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
...
...
Unity/Unity.csproj
浏览文件 @
1d01430f
...
...
@@ -581,6 +581,8 @@
<ItemGroup>
<None
Include=
"Assets\Res\Config\BuffConfig.txt"
/>
<None
Include=
"Assets\Res\Config\UnitConfig.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Error.txt"
/>
<None
Include=
"Assets\StreamingAssets\Logs\Log-Client-Info.txt"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录