Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
a3a8d272
E
et
项目概览
老鱼er
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
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 搜索 >>
提交
a3a8d272
编写于
2月 02, 2018
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.修复ResourcesComponent加载顺序问题,上次漏提交了
2.为了全热更,Opcode改成ushort类型
上级
b69234f8
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
193 addition
and
149 deletion
+193
-149
Client-Server.sln.DotSettings.user
Client-Server.sln.DotSettings.user
+1
-1
Server/Hotfix/Module/Network/InnerMessageDispatcher.cs
Server/Hotfix/Module/Network/InnerMessageDispatcher.cs
+1
-1
Server/Hotfix/Module/Network/OuterMessageDispatcher.cs
Server/Hotfix/Module/Network/OuterMessageDispatcher.cs
+1
-1
Server/Model/Base/Message/MessageAttribute.cs
Server/Model/Base/Message/MessageAttribute.cs
+2
-2
Server/Model/Component/OpcodeTypeComponent.cs
Server/Model/Component/OpcodeTypeComponent.cs
+4
-4
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+1
-0
Unity/Assets/Editor/Proto2CsEditor/Proto2CSEditor.cs
Unity/Assets/Editor/Proto2CsEditor/Proto2CSEditor.cs
+2
-2
Unity/Assets/Scripts/Base/Message/AMessage.cs
Unity/Assets/Scripts/Base/Message/AMessage.cs
+10
-5
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
+1
-1
Unity/Assets/Scripts/Base/Message/IMessageDispatcher.cs
Unity/Assets/Scripts/Base/Message/IMessageDispatcher.cs
+1
-1
Unity/Assets/Scripts/Base/Message/MessageAttribute.cs
Unity/Assets/Scripts/Base/Message/MessageAttribute.cs
+2
-2
Unity/Assets/Scripts/Base/Message/MessageInfo.cs
Unity/Assets/Scripts/Base/Message/MessageInfo.cs
+2
-2
Unity/Assets/Scripts/Base/Message/Opcode.cs
Unity/Assets/Scripts/Base/Message/Opcode.cs
+11
-0
Unity/Assets/Scripts/Base/Message/Opcode.cs.meta
Unity/Assets/Scripts/Base/Message/Opcode.cs.meta
+12
-0
Unity/Assets/Scripts/Component/ClientFrameComponent.cs
Unity/Assets/Scripts/Component/ClientFrameComponent.cs
+1
-1
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
+8
-8
Unity/Assets/Scripts/Component/OpcodeTypeComponent.cs
Unity/Assets/Scripts/Component/OpcodeTypeComponent.cs
+3
-3
Unity/Assets/Scripts/Component/ResourcesComponent.cs
Unity/Assets/Scripts/Component/ResourcesComponent.cs
+57
-43
Unity/Assets/Scripts/Entity/Message/Opcode.cs
Unity/Assets/Scripts/Entity/Message/Opcode.cs
+57
-57
Unity/Assets/Scripts/Entity/Session.cs
Unity/Assets/Scripts/Entity/Session.cs
+5
-8
Unity/Assets/Scripts/Handler/Actor_CreateUnitsHandler.cs
Unity/Assets/Scripts/Handler/Actor_CreateUnitsHandler.cs
+1
-1
Unity/Assets/Scripts/Handler/Actor_TestHandler.cs
Unity/Assets/Scripts/Handler/Actor_TestHandler.cs
+1
-1
Unity/Assets/Scripts/Handler/Frame_ClickMapHandler.cs
Unity/Assets/Scripts/Handler/Frame_ClickMapHandler.cs
+1
-1
Unity/Unity.csproj
Unity/Unity.csproj
+8
-4
未找到文件。
Client-Server.sln.DotSettings.user
浏览文件 @
a3a8d272
...
...
@@ -9,7 +9,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/AnalysisEnabled/@EntryValue">VISIBLE_FILES</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Unity/@EntryIndexedValue"><?xml version="1.0" encoding="utf-16"?><Profile name="Unity"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUseVar><BehavourStyle>DISABLED</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>IMPLICIT_EXCEPT_SIMPLE_TYPES</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSMakeAutoPropertyGetOnly>True</CSMakeAutoPropertyGetOnly><CSUseAutoProperty>True</CSUseAutoProperty><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" /></Profile></s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Unity</s:String>
<s:String x:Key="/Default/Housekeeping/Layout/DialogWindows/RefactoringWizardWindow/Location/@EntryValue">
247,-158
</s:String>
<s:String x:Key="/Default/Housekeeping/Layout/DialogWindows/RefactoringWizardWindow/Location/@EntryValue">
-241,-80
</s:String>
<s:Int64 x:Key="/Default/Environment/SearchAndNavigation/DefaultOccurrencesGroupingIndex/@EntryValue">0</s:Int64>
<s:String x:Key="/Default/Profiling/Configurations/=1/@EntryIndexedValue"><data><HostParameters type="LocalHostParameters" /><Argument type="StandaloneArgument"><Arguments IsNull="False"></Arguments><FileName IsNull="False"></FileName><WorkingDirectory IsNull="False"></WorkingDirectory><Scope><ProcessFilters /></Scope></Argument><Info type="TimelineInfo" /><HostOptions type="HostOptions"><HostTempPath IsNull="False"></HostTempPath></HostOptions></data></s:String>
</wpf:ResourceDictionary>
\ No newline at end of file
Server/Hotfix/Module/Network/InnerMessageDispatcher.cs
浏览文件 @
a3a8d272
...
...
@@ -5,7 +5,7 @@ namespace Hotfix
{
public
class
InnerMessageDispatcher
:
IMessageDispatcher
{
public
void
Dispatch
(
Session
session
,
Opcode
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
)
public
void
Dispatch
(
Session
session
,
ushort
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
)
{
// 收到actor rpc request
if
(
message
is
ActorRpcRequest
actorRpcRequest
)
...
...
Server/Hotfix/Module/Network/OuterMessageDispatcher.cs
浏览文件 @
a3a8d272
...
...
@@ -5,7 +5,7 @@ namespace Hotfix
{
public
class
OuterMessageDispatcher
:
IMessageDispatcher
{
public
async
void
Dispatch
(
Session
session
,
Opcode
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
)
public
async
void
Dispatch
(
Session
session
,
ushort
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
)
{
// gate session收到actor消息直接转发给actor自己去处理
if
(
message
is
AActorMessage
)
...
...
Server/Model/Base/Message/MessageAttribute.cs
浏览文件 @
a3a8d272
...
...
@@ -4,9 +4,9 @@ namespace Model
{
public
class
MessageAttribute
:
Attribute
{
public
Opcode
Opcode
{
get
;
}
public
ushort
Opcode
{
get
;
}
public
MessageAttribute
(
Opcode
opcode
)
public
MessageAttribute
(
ushort
opcode
)
{
this
.
Opcode
=
opcode
;
}
...
...
Server/Model/Component/OpcodeTypeComponent.cs
浏览文件 @
a3a8d272
...
...
@@ -19,7 +19,7 @@ namespace Model
public
class
OpcodeTypeComponent
:
Component
{
private
Dictionary
<
Opcode
,
Type
>
opcodeType
{
get
;
set
;
}
private
Dictionary
<
ushort
,
Type
>
opcodeType
{
get
;
set
;
}
private
Dictionary
<
Type
,
MessageAttribute
>
messageOpcode
{
get
;
set
;
}
public
void
Awake
()
...
...
@@ -29,7 +29,7 @@ namespace Model
public
void
Load
()
{
this
.
opcodeType
=
new
Dictionary
<
Opcode
,
Type
>();
this
.
opcodeType
=
new
Dictionary
<
ushort
,
Type
>();
this
.
messageOpcode
=
new
Dictionary
<
Type
,
MessageAttribute
>();
Type
[]
types
=
DllHelper
.
GetMonoTypes
();
...
...
@@ -47,7 +47,7 @@ namespace Model
}
}
public
Opcode
GetOpcode
(
Type
type
)
public
ushort
GetOpcode
(
Type
type
)
{
if
(!
this
.
messageOpcode
.
TryGetValue
(
type
,
out
MessageAttribute
messageAttribute
))
{
...
...
@@ -56,7 +56,7 @@ namespace Model
return
messageAttribute
.
Opcode
;
}
public
Type
GetType
(
Opcode
opcode
)
public
Type
GetType
(
ushort
opcode
)
{
if
(!
this
.
opcodeType
.
TryGetValue
(
opcode
,
out
Type
messageType
))
{
...
...
Server/Model/Server.Model.csproj
浏览文件 @
a3a8d272
...
...
@@ -44,6 +44,7 @@
<Compile Include="..\..\Unity\Assets\Scripts\Base\Message\IMessagePacker.cs" Link="Module\Network\IMessagePacker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Message\MessageInfo.cs" Link="Base\Message\MessageInfo.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Message\MongoPacker.cs" Link="Module\Network\MongoPacker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Message\Opcode.cs" Link="Base\Message\Opcode.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Message\ProtobufPacker.cs" Link="Module\Network\ProtobufPacker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Message\RpcException.cs" Link="Module\Network\RpcException.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\MultiMap.cs" Link="Base\MultiMap.cs" />
...
...
Unity/Assets/Editor/Proto2CsEditor/Proto2CSEditor.cs
浏览文件 @
a3a8d272
...
...
@@ -163,11 +163,11 @@ namespace MyEditor
StringBuilder
sb
=
new
StringBuilder
();
sb
.
AppendLine
(
"namespace Model"
);
sb
.
AppendLine
(
"{"
);
sb
.
AppendLine
(
"\tpublic
enum Opcode: ushort
"
);
sb
.
AppendLine
(
"\tpublic
static partial class Opcode
"
);
sb
.
AppendLine
(
"\t{"
);
foreach
(
OpcodeInfo
info
in
msgOpcode
)
{
sb
.
AppendLine
(
$"\t\t
{
info
.
Name
}
=
{
info
.
Opcode
}
,
"
);
sb
.
AppendLine
(
$"\t\t
public const ushort
{
info
.
Name
}
=
{
info
.
Opcode
}
;
"
);
}
sb
.
AppendLine
(
"\t}"
);
sb
.
AppendLine
(
"}"
);
...
...
Unity/Assets/Scripts/Base/Message/AMessage.cs
浏览文件 @
a3a8d272
...
...
@@ -5,9 +5,12 @@ using ProtoBuf;
namespace
Model
{
[
ProtoContract
]
[
ProtoInclude
(
Opcode
.
AActorMessage
,
typeof
(
AActorMessage
))]
[
ProtoInclude
(
Opcode
.
ARequest
,
typeof
(
ARequest
))]
[
ProtoInclude
(
Opcode
.
AResponse
,
typeof
(
AResponse
))]
[
BsonKnownTypes
(
typeof
(
AActorMessage
))]
[
BsonKnownTypes
(
typeof
(
ARequest
))]
[
BsonKnownTypes
(
typeof
(
A
Actor
Response
))]
[
BsonKnownTypes
(
typeof
(
AResponse
))]
public
abstract
partial
class
AMessage
{
public
override
string
ToString
()
...
...
@@ -17,10 +20,11 @@ namespace Model
}
[
ProtoContract
]
[
ProtoInclude
(
Opcode
.
AActorRequest
,
typeof
(
AActorRequest
))]
[
BsonKnownTypes
(
typeof
(
AActorRequest
))]
public
abstract
partial
class
ARequest
:
AMessage
{
[
ProtoMember
(
90
)]
[
ProtoMember
(
1
)]
[
BsonIgnoreIfDefault
]
public
uint
RpcId
;
}
...
...
@@ -29,17 +33,18 @@ namespace Model
/// 服务端回的RPC消息需要继承这个抽象类
/// </summary>
[
ProtoContract
]
[
ProtoInclude
(
Opcode
.
AActorResponse
,
typeof
(
AActorResponse
))]
[
BsonKnownTypes
(
typeof
(
AActorResponse
))]
[
BsonKnownTypes
(
typeof
(
ErrorResponse
))]
public
abstract
partial
class
AResponse
:
AMessage
{
[
ProtoMember
(
90
)]
[
ProtoMember
(
1
)]
public
uint
RpcId
;
[
ProtoMember
(
91
)]
[
ProtoMember
(
2
)]
public
int
Error
=
0
;
[
ProtoMember
(
92
)]
[
ProtoMember
(
3
)]
public
string
Message
=
""
;
}
...
...
Unity/Assets/Scripts/Base/Message/ClientDispatcher.cs
浏览文件 @
a3a8d272
...
...
@@ -4,7 +4,7 @@ namespace Model
{
public
class
ClientDispatcher
:
IMessageDispatcher
{
public
void
Dispatch
(
Session
session
,
Opcode
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
)
public
void
Dispatch
(
Session
session
,
ushort
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
)
{
// 如果是帧同步消息,交给ClientFrameComponent处理
FrameMessage
frameMessage
=
message
as
FrameMessage
;
...
...
Unity/Assets/Scripts/Base/Message/IMessageDispatcher.cs
浏览文件 @
a3a8d272
...
...
@@ -2,6 +2,6 @@
{
public
interface
IMessageDispatcher
{
void
Dispatch
(
Session
session
,
Opcode
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
);
void
Dispatch
(
Session
session
,
ushort
opcode
,
int
offset
,
byte
[]
messageBytes
,
AMessage
message
);
}
}
Unity/Assets/Scripts/Base/Message/MessageAttribute.cs
浏览文件 @
a3a8d272
...
...
@@ -4,9 +4,9 @@ namespace Model
{
public
class
MessageAttribute
:
Attribute
{
public
Opcode
Opcode
{
get
;
}
public
ushort
Opcode
{
get
;
}
public
MessageAttribute
(
Opcode
opcode
)
public
MessageAttribute
(
ushort
opcode
)
{
this
.
Opcode
=
opcode
;
}
...
...
Unity/Assets/Scripts/Base/Message/MessageInfo.cs
浏览文件 @
a3a8d272
...
...
@@ -2,10 +2,10 @@
{
public
struct
MessageInfo
{
public
Opcode
Opcode
{
get
;
set
;
}
public
ushort
Opcode
{
get
;
set
;
}
public
AMessage
Message
{
get
;
set
;
}
public
MessageInfo
(
Opcode
opcode
,
AMessage
message
)
public
MessageInfo
(
ushort
opcode
,
AMessage
message
)
{
this
.
Opcode
=
opcode
;
this
.
Message
=
message
;
...
...
Unity/Assets/Scripts/Base/Message/Opcode.cs
0 → 100644
浏览文件 @
a3a8d272
namespace
Model
{
public
static
partial
class
Opcode
{
public
const
ushort
ARequest
=
1
;
public
const
ushort
AResponse
=
2
;
public
const
ushort
AActorMessage
=
3
;
public
const
ushort
AActorRequest
=
4
;
public
const
ushort
AActorResponse
=
5
;
}
}
Unity/Assets/Scripts/Base/Message/Opcode.cs.meta
0 → 100644
浏览文件 @
a3a8d272
fileFormatVersion: 2
guid: 129811e752b0782479b48ee6a12e1f2b
timeCreated: 1517571639
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Component/ClientFrameComponent.cs
浏览文件 @
a3a8d272
...
...
@@ -79,7 +79,7 @@ namespace Model
for
(
int
i
=
0
;
i
<
sessionFrameMessage
.
FrameMessage
.
Messages
.
Count
;
++
i
)
{
AFrameMessage
message
=
sessionFrameMessage
.
FrameMessage
.
Messages
[
i
];
Opcode
opcode
=
Game
.
Scene
.
GetComponent
<
OpcodeTypeComponent
>().
GetOpcode
(
message
.
GetType
());
ushort
opcode
=
Game
.
Scene
.
GetComponent
<
OpcodeTypeComponent
>().
GetOpcode
(
message
.
GetType
());
Game
.
Scene
.
GetComponent
<
MessageDispatherComponent
>().
Handle
(
sessionFrameMessage
.
Session
,
new
MessageInfo
()
{
Opcode
=
opcode
,
Message
=
message
});
}
}
...
...
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
浏览文件 @
a3a8d272
...
...
@@ -72,7 +72,7 @@ namespace Model
/// </summary>
public
class
MessageDispatherComponent
:
Component
{
private
Dictionary
<
Opcode
,
List
<
IMessageMethod
>>
handlers
;
private
Dictionary
<
ushort
,
List
<
IMessageMethod
>>
handlers
;
public
void
Awake
()
...
...
@@ -82,7 +82,7 @@ namespace Model
public
void
Load
()
{
handlers
=
new
Dictionary
<
Opcode
,
List
<
IMessageMethod
>>();
handlers
=
new
Dictionary
<
ushort
,
List
<
IMessageMethod
>>();
Type
[]
types
=
DllHelper
.
GetMonoTypes
();
...
...
@@ -95,11 +95,11 @@ namespace Model
}
MessageHandlerAttribute
messageHandlerAttribute
=
(
MessageHandlerAttribute
)
attrs
[
0
];
IMHandler
iMHandler
=
(
IMHandler
)
Activator
.
CreateInstance
(
type
);
if
(!
this
.
handlers
.
ContainsKey
(
(
Opcode
)
messageHandlerAttribute
.
Opcode
))
if
(!
this
.
handlers
.
ContainsKey
(
messageHandlerAttribute
.
Opcode
))
{
this
.
handlers
.
Add
(
(
Opcode
)
messageHandlerAttribute
.
Opcode
,
new
List
<
IMessageMethod
>());
this
.
handlers
.
Add
(
messageHandlerAttribute
.
Opcode
,
new
List
<
IMessageMethod
>());
}
this
.
handlers
[
(
Opcode
)
messageHandlerAttribute
.
Opcode
].
Add
(
new
IMessageMonoMethod
(
iMHandler
));
this
.
handlers
[
messageHandlerAttribute
.
Opcode
].
Add
(
new
IMessageMonoMethod
(
iMHandler
));
}
// hotfix dll
...
...
@@ -118,11 +118,11 @@ namespace Model
IMHandler
iMHandler
=
(
IMHandler
)
Activator
.
CreateInstance
(
type
);
IMessageMethod
iMessageMethod
=
new
IMessageMonoMethod
(
iMHandler
);
#endif
if
(!
this
.
handlers
.
ContainsKey
(
(
Opcode
)
messageHandlerAttribute
.
Opcode
))
if
(!
this
.
handlers
.
ContainsKey
(
messageHandlerAttribute
.
Opcode
))
{
this
.
handlers
.
Add
(
(
Opcode
)
messageHandlerAttribute
.
Opcode
,
new
List
<
IMessageMethod
>());
this
.
handlers
.
Add
(
messageHandlerAttribute
.
Opcode
,
new
List
<
IMessageMethod
>());
}
this
.
handlers
[
(
Opcode
)
messageHandlerAttribute
.
Opcode
].
Add
(
iMessageMethod
);
this
.
handlers
[
messageHandlerAttribute
.
Opcode
].
Add
(
iMessageMethod
);
}
}
...
...
Unity/Assets/Scripts/Component/OpcodeTypeComponent.cs
浏览文件 @
a3a8d272
...
...
@@ -13,7 +13,7 @@ namespace Model
public
class
OpcodeTypeComponent
:
Component
{
private
readonly
DoubleMap
<
Opcode
,
Type
>
opcodeTypes
=
new
DoubleMap
<
Opcode
,
Type
>();
private
readonly
DoubleMap
<
ushort
,
Type
>
opcodeTypes
=
new
DoubleMap
<
ushort
,
Type
>();
public
void
Awake
()
{
...
...
@@ -36,12 +36,12 @@ namespace Model
}
}
public
Opcode
GetOpcode
(
Type
type
)
public
ushort
GetOpcode
(
Type
type
)
{
return
this
.
opcodeTypes
.
GetKeyByValue
(
type
);
}
public
Type
GetType
(
Opcode
opcode
)
public
Type
GetType
(
ushort
opcode
)
{
return
this
.
opcodeTypes
.
GetValueByKey
(
opcode
);
}
...
...
Unity/Assets/Scripts/Component/ResourcesComponent.cs
浏览文件 @
a3a8d272
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
UnityEngine
;
#if UNITY_EDITOR
...
...
@@ -10,7 +11,7 @@ using UnityEditor;
namespace
Model
{
public
class
ABInfo
:
Disposer
public
class
ABInfo
:
Disposer
{
private
int
refCount
;
public
string
Name
{
get
;
}
...
...
@@ -23,7 +24,7 @@ namespace Model
}
set
{
Log
.
Debug
(
$"
{
this
.
Name
}
refcount:
{
value
}
"
);
//
Log.Debug($"{this.Name} refcount: {value}");
this
.
refCount
=
value
;
}
}
...
...
@@ -35,7 +36,7 @@ namespace Model
this
.
Name
=
name
;
this
.
AssetBundle
=
ab
;
this
.
RefCount
=
1
;
Log
.
Debug
(
$"load assetbundle:
{
this
.
Name
}
"
);
//
Log.Debug($"load assetbundle: {this.Name}");
}
public
override
void
Dispose
()
...
...
@@ -44,11 +45,11 @@ namespace Model
{
return
;
}
base
.
Dispose
();
Log
.
Debug
(
$"desdroy assetbundle:
{
this
.
Name
}
"
);
//
Log.Debug($"desdroy assetbundle: {this.Name}");
this
.
AssetBundle
?.
Unload
(
true
);
}
}
...
...
@@ -60,10 +61,29 @@ namespace Model
private
readonly
Dictionary
<
string
,
UnityEngine
.
Object
>
resourceCache
=
new
Dictionary
<
string
,
UnityEngine
.
Object
>();
private
readonly
Dictionary
<
string
,
ABInfo
>
bundles
=
new
Dictionary
<
string
,
ABInfo
>();
// lru缓存队列
private
readonly
QueueDictionary
<
string
,
ABInfo
>
cacheDictionary
=
new
QueueDictionary
<
string
,
ABInfo
>();
public
override
void
Dispose
()
{
if
(
this
.
Id
==
0
)
{
return
;
}
base
.
Dispose
();
foreach
(
var
abInfo
in
this
.
bundles
)
{
abInfo
.
Value
?.
AssetBundle
?.
Unload
(
true
);
}
this
.
bundles
.
Clear
();
this
.
cacheDictionary
.
Clear
();
this
.
resourceCache
.
Clear
();
}
public
K
GetAsset
<
K
>(
string
bundleName
,
string
prefab
)
where
K
:
class
{
string
path
=
$"
{
bundleName
}
/
{
prefab
}
"
.
ToLower
();
...
...
@@ -73,15 +93,18 @@ namespace Model
{
throw
new
Exception
(
$"not found asset:
{
path
}
"
);
}
return
resource
as
K
;
K
k
=
resource
as
K
;
if
(
k
==
null
)
{
throw
new
Exception
(
$"asset type error, type:
{
k
.
GetType
().
Name
}
, path:
{
path
}
"
);
}
return
k
;
}
public
void
UnloadBundle
(
string
assetBundleName
)
{
assetBundleName
=
assetBundleName
.
ToLower
();
this
.
UnloadOneBundle
(
assetBundleName
);
string
[]
dependencies
=
ResourcesHelper
.
GetSortedDependencies
(
assetBundleName
);
...
...
@@ -90,12 +113,14 @@ namespace Model
{
this
.
UnloadOneBundle
(
dependency
);
}
this
.
UnloadOneBundle
(
assetBundleName
);
}
private
void
UnloadOneBundle
(
string
assetBundleName
)
{
assetBundleName
=
assetBundleName
.
ToLower
();
//Log.Debug($"unload bundle {assetBundleName}");
ABInfo
abInfo
;
if
(!
this
.
bundles
.
TryGetValue
(
assetBundleName
,
out
abInfo
))
...
...
@@ -108,10 +133,10 @@ namespace Model
{
return
;
}
this
.
bundles
.
Remove
(
assetBundleName
);
// 缓存10个包
this
.
cacheDictionary
.
Enqueue
(
assetBundleName
,
abInfo
);
if
(
this
.
cacheDictionary
.
Count
>
10
)
...
...
@@ -120,9 +145,9 @@ namespace Model
this
.
cacheDictionary
.
Dequeue
();
abInfo
.
Dispose
();
}
Log
.
Debug
(
$"cache count:
{
this
.
cacheDictionary
.
Count
}
"
);
//
Log.Debug($"cache count: {this.cacheDictionary.Count}");
}
/// <summary>
/// 同步加载assetbundle
/// </summary>
...
...
@@ -131,8 +156,6 @@ namespace Model
public
void
LoadBundle
(
string
assetBundleName
)
{
assetBundleName
=
assetBundleName
.
ToLower
();
this
.
LoadOneBundle
(
assetBundleName
);
string
[]
dependencies
=
ResourcesHelper
.
GetSortedDependencies
(
assetBundleName
);
Log
.
Debug
(
$"-----------dep load
{
assetBundleName
}
dep:
{
dependencies
.
ToList
().
ListToString
()}
"
);
...
...
@@ -144,8 +167,9 @@ namespace Model
}
this
.
LoadOneBundle
(
dependency
);
}
this
.
LoadOneBundle
(
assetBundleName
);
}
public
void
LoadOneBundle
(
string
assetBundleName
)
{
ABInfo
abInfo
;
...
...
@@ -164,7 +188,7 @@ namespace Model
this
.
cacheDictionary
.
Remove
(
assetBundleName
);
return
;
}
if
(!
Define
.
IsAsync
)
{
...
...
@@ -177,7 +201,7 @@ namespace Model
UnityEngine
.
Object
resource
=
AssetDatabase
.
LoadAssetAtPath
<
UnityEngine
.
Object
>(
s
);
this
.
resourceCache
[
path
]
=
resource
;
}
this
.
bundles
[
assetBundleName
]
=
new
ABInfo
(
assetBundleName
,
null
);
return
;
#endif
...
...
@@ -195,7 +219,7 @@ namespace Model
this
.
resourceCache
[
path
]
=
asset
;
}
}
this
.
bundles
[
assetBundleName
]
=
new
ABInfo
(
assetBundleName
,
assetBundle
);
}
...
...
@@ -207,8 +231,6 @@ namespace Model
public
async
Task
LoadBundleAsync
(
string
assetBundleName
)
{
assetBundleName
=
assetBundleName
.
ToLower
();
await
this
.
LoadOneBundleAsync
(
assetBundleName
);
string
[]
dependencies
=
ResourcesHelper
.
GetSortedDependencies
(
assetBundleName
);
//Log.Debug($"-----------dep load {assetBundleName} dep: {dependencies.ToList().ListToString()}");
...
...
@@ -220,6 +242,7 @@ namespace Model
}
await
this
.
LoadOneBundleAsync
(
dependency
);
}
await
this
.
LoadOneBundleAsync
(
assetBundleName
);
}
public
async
Task
LoadOneBundleAsync
(
string
assetBundleName
)
...
...
@@ -240,7 +263,7 @@ namespace Model
this
.
cacheDictionary
.
Remove
(
assetBundleName
);
return
;
}
if
(!
Define
.
IsAsync
)
{
...
...
@@ -253,7 +276,7 @@ namespace Model
UnityEngine
.
Object
resource
=
AssetDatabase
.
LoadAssetAtPath
<
UnityEngine
.
Object
>(
s
);
this
.
resourceCache
[
path
]
=
resource
;
}
this
.
bundles
[
assetBundleName
]
=
new
ABInfo
(
assetBundleName
,
null
);
return
;
#endif
...
...
@@ -279,27 +302,18 @@ namespace Model
this
.
resourceCache
[
path
]
=
asset
;
}
}
this
.
bundles
[
assetBundleName
]
=
new
ABInfo
(
assetBundleName
,
assetBundle
);
}
public
override
void
Dispose
()
public
string
DebugString
()
{
if
(
this
.
Id
==
0
)
StringBuilder
sb
=
new
StringBuilder
();
foreach
(
ABInfo
abInfo
in
this
.
bundles
.
Values
)
{
return
;
sb
.
Append
(
$"
{
abInfo
.
Name
}
:
{
abInfo
.
RefCount
}
\n"
)
;
}
base
.
Dispose
();
foreach
(
var
abInfo
in
this
.
bundles
)
{
abInfo
.
Value
?.
AssetBundle
?.
Unload
(
true
);
}
this
.
bundles
.
Clear
();
this
.
cacheDictionary
.
Clear
();
this
.
resourceCache
.
Clear
();
return
sb
.
ToString
();
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Entity/Message/Opcode.cs
浏览文件 @
a3a8d272
namespace
Model
{
public
enum
Opcode
:
ushort
public
static
partial
class
Opcode
{
C2R_Login
=
101
,
R2C_Login
=
102
,
C2G_LoginGate
=
103
,
G2C_LoginGate
=
104
,
Actor_Test
=
105
,
Actor_TestRequest
=
106
,
Actor_TestResponse
=
107
,
Actor_TransferRequest
=
108
,
Actor_TransferResponse
=
109
,
C2G_EnterMap
=
110
,
G2C_EnterMap
=
111
,
UnitInfo
=
112
,
Actor_CreateUnits
=
113
,
FrameMessageInfo
=
114
,
FrameMessage
=
115
,
Frame_ClickMap
=
116
,
C2M_Reload
=
117
,
M2C_Reload
=
118
,
C2R_Ping
=
119
,
R2C_Ping
=
120
,
ActorRequest
=
1001
,
ActorResponse
=
1002
,
ActorRpcRequest
=
1003
,
ActorRpcResponse
=
1004
,
M2M_TrasferUnitRequest
=
1005
,
M2M_TrasferUnitResponse
=
1006
,
M2A_Reload
=
1007
,
A2M_Reload
=
1008
,
G2G_LockRequest
=
1009
,
G2G_LockResponse
=
1010
,
G2G_LockReleaseRequest
=
1011
,
G2G_LockReleaseResponse
=
1012
,
DBSaveRequest
=
1013
,
DBSaveBatchResponse
=
1014
,
DBSaveBatchRequest
=
1015
,
DBSaveResponse
=
1016
,
DBQueryRequest
=
1017
,
DBQueryResponse
=
1018
,
DBQueryBatchRequest
=
1019
,
DBQueryBatchResponse
=
1020
,
DBQueryJsonRequest
=
1021
,
DBQueryJsonResponse
=
1022
,
ObjectAddRequest
=
1023
,
ObjectAddResponse
=
1024
,
ObjectRemoveRequest
=
1025
,
ObjectRemoveResponse
=
1026
,
ObjectLockRequest
=
1027
,
ObjectLockResponse
=
1028
,
ObjectUnLockRequest
=
1029
,
ObjectUnLockResponse
=
1030
,
ObjectGetRequest
=
1031
,
ObjectGetResponse
=
1032
,
R2G_GetLoginKey
=
1033
,
G2R_GetLoginKey
=
1034
,
G2M_CreateUnit
=
1035
,
M2G_CreateUnit
=
1036
,
public
const
ushort
C2R_Login
=
101
;
public
const
ushort
R2C_Login
=
102
;
public
const
ushort
C2G_LoginGate
=
103
;
public
const
ushort
G2C_LoginGate
=
104
;
public
const
ushort
Actor_Test
=
105
;
public
const
ushort
Actor_TestRequest
=
106
;
public
const
ushort
Actor_TestResponse
=
107
;
public
const
ushort
Actor_TransferRequest
=
108
;
public
const
ushort
Actor_TransferResponse
=
109
;
public
const
ushort
C2G_EnterMap
=
110
;
public
const
ushort
G2C_EnterMap
=
111
;
public
const
ushort
UnitInfo
=
112
;
public
const
ushort
Actor_CreateUnits
=
113
;
public
const
ushort
FrameMessageInfo
=
114
;
public
const
ushort
FrameMessage
=
115
;
public
const
ushort
Frame_ClickMap
=
116
;
public
const
ushort
C2M_Reload
=
117
;
public
const
ushort
M2C_Reload
=
118
;
public
const
ushort
C2R_Ping
=
119
;
public
const
ushort
R2C_Ping
=
120
;
public
const
ushort
ActorRequest
=
1001
;
public
const
ushort
ActorResponse
=
1002
;
public
const
ushort
ActorRpcRequest
=
1003
;
public
const
ushort
ActorRpcResponse
=
1004
;
public
const
ushort
M2M_TrasferUnitRequest
=
1005
;
public
const
ushort
M2M_TrasferUnitResponse
=
1006
;
public
const
ushort
M2A_Reload
=
1007
;
public
const
ushort
A2M_Reload
=
1008
;
public
const
ushort
G2G_LockRequest
=
1009
;
public
const
ushort
G2G_LockResponse
=
1010
;
public
const
ushort
G2G_LockReleaseRequest
=
1011
;
public
const
ushort
G2G_LockReleaseResponse
=
1012
;
public
const
ushort
DBSaveRequest
=
1013
;
public
const
ushort
DBSaveBatchResponse
=
1014
;
public
const
ushort
DBSaveBatchRequest
=
1015
;
public
const
ushort
DBSaveResponse
=
1016
;
public
const
ushort
DBQueryRequest
=
1017
;
public
const
ushort
DBQueryResponse
=
1018
;
public
const
ushort
DBQueryBatchRequest
=
1019
;
public
const
ushort
DBQueryBatchResponse
=
1020
;
public
const
ushort
DBQueryJsonRequest
=
1021
;
public
const
ushort
DBQueryJsonResponse
=
1022
;
public
const
ushort
ObjectAddRequest
=
1023
;
public
const
ushort
ObjectAddResponse
=
1024
;
public
const
ushort
ObjectRemoveRequest
=
1025
;
public
const
ushort
ObjectRemoveResponse
=
1026
;
public
const
ushort
ObjectLockRequest
=
1027
;
public
const
ushort
ObjectLockResponse
=
1028
;
public
const
ushort
ObjectUnLockRequest
=
1029
;
public
const
ushort
ObjectUnLockResponse
=
1030
;
public
const
ushort
ObjectGetRequest
=
1031
;
public
const
ushort
ObjectGetResponse
=
1032
;
public
const
ushort
R2G_GetLoginKey
=
1033
;
public
const
ushort
G2R_GetLoginKey
=
1034
;
public
const
ushort
G2M_CreateUnit
=
1035
;
public
const
ushort
M2G_CreateUnit
=
1036
;
}
}
Unity/Assets/Scripts/Entity/Session.cs
浏览文件 @
a3a8d272
...
...
@@ -125,12 +125,10 @@ namespace Model
private
void
RunDecompressedBytes
(
ushort
opcode
,
byte
[]
messageBytes
,
int
offset
,
int
count
)
{
object
message
;
Opcode
op
;
try
{
op
=
(
Opcode
)
opcode
;
Type
messageType
=
this
.
network
.
Parent
.
GetComponent
<
OpcodeTypeComponent
>().
GetType
(
op
);
Type
messageType
=
this
.
network
.
Parent
.
GetComponent
<
OpcodeTypeComponent
>().
GetType
(
opcode
);
message
=
this
.
network
.
MessagePacker
.
DeserializeFrom
(
messageType
,
messageBytes
,
offset
,
count
-
offset
);
}
catch
(
Exception
e
)
...
...
@@ -157,7 +155,7 @@ namespace Model
return
;
}
this
.
network
.
MessageDispatcher
.
Dispatch
(
this
,
op
,
offset
,
messageBytes
,
(
AMessage
)
message
);
this
.
network
.
MessageDispatcher
.
Dispatch
(
this
,
op
code
,
offset
,
messageBytes
,
(
AMessage
)
message
);
}
/// <summary>
...
...
@@ -247,8 +245,7 @@ namespace Model
private
void
SendMessage
(
object
message
)
{
//Log.Debug($"send: {MongoHelper.ToJson(message)}");
Opcode
opcode
=
this
.
network
.
Parent
.
GetComponent
<
OpcodeTypeComponent
>().
GetOpcode
(
message
.
GetType
());
ushort
op
=
(
ushort
)
opcode
;
ushort
opcode
=
this
.
network
.
Parent
.
GetComponent
<
OpcodeTypeComponent
>().
GetOpcode
(
message
.
GetType
());
byte
[]
messageBytes
=
this
.
network
.
MessagePacker
.
SerializeToByteArray
(
message
);
#if SERVER
...
...
@@ -256,12 +253,12 @@ namespace Model
if
(
this
.
network
.
AppType
==
AppType
.
AllServer
)
{
Session
session
=
this
.
network
.
Parent
.
GetComponent
<
NetInnerComponent
>().
Get
(
this
.
RemoteAddress
);
session
.
RunDecompressedBytes
(
op
,
messageBytes
,
0
,
messageBytes
.
Length
);
session
.
RunDecompressedBytes
(
op
code
,
messageBytes
,
0
,
messageBytes
.
Length
);
return
;
}
#endif
byte
[]
opcodeBytes
=
BitConverter
.
GetBytes
(
op
);
byte
[]
opcodeBytes
=
BitConverter
.
GetBytes
(
op
code
);
this
.
byteses
[
0
]
=
opcodeBytes
;
this
.
byteses
[
1
]
=
messageBytes
;
...
...
Unity/Assets/Scripts/Handler/Actor_CreateUnitsHandler.cs
浏览文件 @
a3a8d272
...
...
@@ -2,7 +2,7 @@
namespace
Model
{
[
MessageHandler
(
(
int
)
Opcode
.
Actor_CreateUnits
)]
[
MessageHandler
(
Opcode
.
Actor_CreateUnits
)]
public
class
Actor_CreateUnitsHandler
:
AMHandler
<
Actor_CreateUnits
>
{
protected
override
void
Run
(
Session
session
,
Actor_CreateUnits
message
)
...
...
Unity/Assets/Scripts/Handler/Actor_TestHandler.cs
浏览文件 @
a3a8d272
namespace
Model
{
[
MessageHandler
(
(
int
)
Opcode
.
Actor_Test
)]
[
MessageHandler
(
Opcode
.
Actor_Test
)]
public
class
Actor_TestHandler
:
AMHandler
<
Actor_Test
>
{
protected
override
void
Run
(
Session
session
,
Actor_Test
message
)
...
...
Unity/Assets/Scripts/Handler/Frame_ClickMapHandler.cs
浏览文件 @
a3a8d272
...
...
@@ -2,7 +2,7 @@
namespace
Model
{
[
MessageHandler
(
(
int
)
Opcode
.
Frame_ClickMap
)]
[
MessageHandler
(
Opcode
.
Frame_ClickMap
)]
public
class
Frame_ClickMapHandler
:
AMHandler
<
Frame_ClickMap
>
{
protected
override
void
Run
(
Session
session
,
Frame_ClickMap
message
)
...
...
Unity/Unity.csproj
浏览文件 @
a3a8d272
...
...
@@ -12,12 +12,15 @@
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
<TargetFrameworkVersion>
v4.6
</TargetFrameworkVersion>
<TargetFrameworkProfile></TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<UnityProjectType>
Game:1
</UnityProjectType>
<UnityBuildTarget>
StandaloneWindows64:19
</UnityBuildTarget>
<UnityVersion>
2017.1.1p4
</UnityVersion>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
<LangVersion>
6
</LangVersion>
</PropertyGroup>
<PropertyGroup>
...
...
@@ -222,6 +225,7 @@
<Compile
Include=
"Assets\Scripts\Base\Message\MessageInfo.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Message\MongoPacker.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Message\NumericType.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Message\Opcode.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Message\OpcodeHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Message\ProtobufPacker.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Message\RpcException.cs"
/>
...
...
@@ -673,4 +677,4 @@
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
</Project>
</Project>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录