Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
ef1520c3
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 搜索 >>
提交
ef1520c3
编写于
10月 08, 2016
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
去掉Entity和Component的模板限制
上级
5d98c2cc
变更
39
隐藏空白更改
内联
并排
Showing
39 changed file
with
303 addition
and
111 deletion
+303
-111
Unity/Assets/Scripts/Base/Config/ACategory.cs
Unity/Assets/Scripts/Base/Config/ACategory.cs
+5
-1
Unity/Assets/Scripts/Base/Config/AConfig.cs
Unity/Assets/Scripts/Base/Config/AConfig.cs
+4
-1
Unity/Assets/Scripts/Base/Config/ConfigAttribute.cs
Unity/Assets/Scripts/Base/Config/ConfigAttribute.cs
+9
-0
Unity/Assets/Scripts/Base/Config/ConfigAttribute.cs.meta
Unity/Assets/Scripts/Base/Config/ConfigAttribute.cs.meta
+3
-3
Unity/Assets/Scripts/Base/Config/ICategory.cs
Unity/Assets/Scripts/Base/Config/ICategory.cs
+0
-0
Unity/Assets/Scripts/Base/Config/ICategory.cs.meta
Unity/Assets/Scripts/Base/Config/ICategory.cs.meta
+0
-0
Unity/Assets/Scripts/Base/Helper/FileHelper.cs
Unity/Assets/Scripts/Base/Helper/FileHelper.cs
+0
-0
Unity/Assets/Scripts/Base/Helper/FileHelper.cs.meta
Unity/Assets/Scripts/Base/Helper/FileHelper.cs.meta
+0
-0
Unity/Assets/Scripts/Base/Network/AChannel.cs
Unity/Assets/Scripts/Base/Network/AChannel.cs
+5
-1
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs
+1
-4
Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs
Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs
+1
-1
Unity/Assets/Scripts/Base/Network/TNet/TService.cs
Unity/Assets/Scripts/Base/Network/TNet/TService.cs
+1
-1
Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs
Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs
+2
-2
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs
+1
-5
Unity/Assets/Scripts/Base/Network/UNet/UService.cs
Unity/Assets/Scripts/Base/Network/UNet/UService.cs
+0
-1
Unity/Assets/Scripts/Base/Object/Component.cs
Unity/Assets/Scripts/Base/Object/Component.cs
+9
-12
Unity/Assets/Scripts/Base/Object/Entity.cs
Unity/Assets/Scripts/Base/Object/Entity.cs
+30
-40
Unity/Assets/Scripts/Base/Object/ObjectManager.cs
Unity/Assets/Scripts/Base/Object/ObjectManager.cs
+0
-1
Unity/Assets/Scripts/Component/Game.cs
Unity/Assets/Scripts/Component/Game.cs
+1
-1
Unity/Assets/Scripts/Component/KVComponent.cs
Unity/Assets/Scripts/Component/KVComponent.cs
+10
-10
Unity/Assets/Scripts/Component/KVComponent.cs.meta
Unity/Assets/Scripts/Component/KVComponent.cs.meta
+12
-0
Unity/Assets/Scripts/Component/Scene.cs
Unity/Assets/Scripts/Component/Scene.cs
+5
-6
Unity/Assets/Scripts/Component/Scene/ChildrenComponent.cs
Unity/Assets/Scripts/Component/Scene/ChildrenComponent.cs
+102
-0
Unity/Assets/Scripts/Component/Scene/ChildrenComponent.cs.meta
.../Assets/Scripts/Component/Scene/ChildrenComponent.cs.meta
+12
-0
Unity/Assets/Scripts/Component/Scene/EventComponent.cs
Unity/Assets/Scripts/Component/Scene/EventComponent.cs
+1
-1
Unity/Assets/Scripts/Component/Scene/GlobalConfigComponent.cs
...y/Assets/Scripts/Component/Scene/GlobalConfigComponent.cs
+1
-1
Unity/Assets/Scripts/Component/Scene/LogComponent.cs
Unity/Assets/Scripts/Component/Scene/LogComponent.cs
+1
-1
Unity/Assets/Scripts/Component/Scene/MessageComponent.cs
Unity/Assets/Scripts/Component/Scene/MessageComponent.cs
+44
-6
Unity/Assets/Scripts/Component/Scene/NetworkComponent.cs
Unity/Assets/Scripts/Component/Scene/NetworkComponent.cs
+1
-1
Unity/Assets/Scripts/Component/Scene/TimeComponent.cs
Unity/Assets/Scripts/Component/Scene/TimeComponent.cs
+1
-1
Unity/Assets/Scripts/Component/Scene/TimerComponent.cs
Unity/Assets/Scripts/Component/Scene/TimerComponent.cs
+1
-1
Unity/Assets/Scripts/Component/Share.cs
Unity/Assets/Scripts/Component/Share.cs
+1
-1
Unity/Assets/Scripts/Config/BuffProto.cs
Unity/Assets/Scripts/Config/BuffProto.cs
+16
-0
Unity/Assets/Scripts/Config/BuffProto.cs.meta
Unity/Assets/Scripts/Config/BuffProto.cs.meta
+12
-0
Unity/Assets/Scripts/Message/MessageAttribute.cs
Unity/Assets/Scripts/Message/MessageAttribute.cs
+0
-0
Unity/Assets/Scripts/Message/MessageAttribute.cs.meta
Unity/Assets/Scripts/Message/MessageAttribute.cs.meta
+0
-0
Unity/Controller/Controller.csproj
Unity/Controller/Controller.csproj
+1
-0
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
+1
-0
Unity/Unity.CSharp.csproj
Unity/Unity.CSharp.csproj
+9
-8
未找到文件。
Unity/Assets/Scripts/Base/Config/ACategory.cs
浏览文件 @
ef1520c3
...
...
@@ -5,6 +5,10 @@ using UnityEngine;
namespace
Base
{
/// <summary>
/// 管理该所有的配置
/// </summary>
/// <typeparam name="T"></typeparam>
public
abstract
class
ACategory
<
T
>:
ICategory
where
T
:
AConfig
{
protected
Dictionary
<
long
,
T
>
dict
;
...
...
@@ -34,7 +38,7 @@ namespace Base
continue
;
}
T
t
=
MongoHelper
.
FromJson
<
T
>(
str2
);
this
.
dict
.
Add
(
t
.
i
d
,
t
);
this
.
dict
.
Add
(
t
.
I
d
,
t
);
}
catch
(
Exception
e
)
{
...
...
Unity/Assets/Scripts/Base/Config/AConfig.cs
浏览文件 @
ef1520c3
...
...
@@ -3,10 +3,13 @@ using MongoDB.Bson.Serialization.Attributes;
namespace
Base
{
/// <summary>
/// 每个Config的基类
/// </summary>
public
abstract
class
AConfig
:
ISupportInitialize
{
[
BsonId
]
public
long
i
d
{
get
;
set
;
}
public
long
I
d
{
get
;
set
;
}
public
virtual
void
BeginInit
()
{
...
...
Unity/Assets/Scripts/Base/
Network/TNet/IPoller
.cs
→
Unity/Assets/Scripts/Base/
Config/ConfigAttribute
.cs
浏览文件 @
ef1520c3
...
...
@@ -2,10 +2,8 @@
namespace
Base
{
public
interface
IPoller
[
AttributeUsage
(
AttributeTargets
.
Class
)]
public
class
ConfigAttribute
:
Attribute
{
void
Add
(
Action
action
);
void
Update
();
}
}
\ No newline at end of file
Unity/Assets/Scripts/Base/
Network/TNet/IPoller
.cs.meta
→
Unity/Assets/Scripts/Base/
Config/ConfigAttribute
.cs.meta
浏览文件 @
ef1520c3
fileFormatVersion: 2
guid:
1d609f021d8833b4c8f9cc79d267a1a6
timeCreated: 14
29240758
licenseType:
Free
guid:
f3b8997482f68c0418b3982ed475def2
timeCreated: 14
75898829
licenseType:
Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
...
...
Unity/Assets/Scripts/
Other
/ICategory.cs
→
Unity/Assets/Scripts/
Base/Config
/ICategory.cs
浏览文件 @
ef1520c3
文件已移动
Unity/Assets/Scripts/
Other
/ICategory.cs.meta
→
Unity/Assets/Scripts/
Base/Config
/ICategory.cs.meta
浏览文件 @
ef1520c3
文件已移动
Unity/Assets/Scripts/Base/FileHelper.cs
→
Unity/Assets/Scripts/Base/
Helper/
FileHelper.cs
浏览文件 @
ef1520c3
文件已移动
Unity/Assets/Scripts/Base/FileHelper.cs.meta
→
Unity/Assets/Scripts/Base/
Helper/
FileHelper.cs.meta
浏览文件 @
ef1520c3
文件已移动
Unity/Assets/Scripts/Base/Network/AChannel.cs
浏览文件 @
ef1520c3
...
...
@@ -12,7 +12,7 @@ namespace Base
NoAllocate
=
1
<<
2
}
public
abstract
class
AChannel
:
Entity
<
AChannel
>
public
abstract
class
AChannel
:
Entity
{
protected
AService
service
;
...
...
@@ -42,7 +42,11 @@ namespace Base
return
;
}
long
id
=
this
.
Id
;
base
.
Dispose
();
this
.
service
.
Remove
(
id
);
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs
浏览文件 @
ef1520c3
...
...
@@ -33,13 +33,10 @@ namespace Base
{
return
;
}
long
id
=
this
.
Id
;
base
.
Dispose
();
this
.
socket
.
Dispose
();
this
.
service
.
Remove
(
id
);
}
public
override
void
ConnectAsync
()
...
...
Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs
浏览文件 @
ef1520c3
...
...
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace
Base
{
public
class
TPoller
:
IPoller
public
class
TPoller
{
// 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
private
Queue
<
Action
>
queue
=
new
Queue
<
Action
>();
...
...
Unity/Assets/Scripts/Base/Network/TNet/TService.cs
浏览文件 @
ef1520c3
...
...
@@ -6,7 +6,7 @@ namespace Base
{
public
sealed
class
TService
:
AService
{
private
I
Poller
poller
=
new
TPoller
();
private
T
Poller
poller
=
new
TPoller
();
private
readonly
Dictionary
<
long
,
TChannel
>
idChannels
=
new
Dictionary
<
long
,
TChannel
>();
...
...
Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs
浏览文件 @
ef1520c3
...
...
@@ -9,7 +9,7 @@ namespace Base
/// </summary>
public
class
TSocket
:
IDisposable
{
private
readonly
I
Poller
poller
;
private
readonly
T
Poller
poller
;
private
Socket
socket
;
private
readonly
SocketAsyncEventArgs
innArgs
=
new
SocketAsyncEventArgs
();
private
readonly
SocketAsyncEventArgs
outArgs
=
new
SocketAsyncEventArgs
();
...
...
@@ -20,7 +20,7 @@ namespace Base
public
Action
<
SocketError
>
OnDisconnect
;
private
string
remoteAddress
;
public
TSocket
(
I
Poller
poller
)
public
TSocket
(
T
Poller
poller
)
{
this
.
poller
=
poller
;
this
.
socket
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Stream
,
ProtocolType
.
Tcp
);
...
...
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs
浏览文件 @
ef1520c3
...
...
@@ -22,14 +22,10 @@ namespace Base
{
return
;
}
long
id
=
this
.
Id
;
base
.
Dispose
();
this
.
socket
.
Dispose
();
this
.
service
.
Remove
(
id
);
}
public
override
void
ConnectAsync
()
...
...
Unity/Assets/Scripts/Base/Network/UNet/UService.cs
浏览文件 @
ef1520c3
...
...
@@ -42,7 +42,6 @@ namespace Base
public
override
void
Dispose
()
{
this
.
Dispose
(
true
);
GC
.
SuppressFinalize
(
this
);
}
public
override
void
Add
(
Action
action
)
...
...
Unity/Assets/Scripts/Base/Object/Component.cs
浏览文件 @
ef1520c3
...
...
@@ -5,21 +5,18 @@ namespace Base
/// <summary>
/// Component的Id与Owner Entity Id一样
/// </summary>
public
abstract
class
Component
<
T
>:
Object
where
T
:
Entity
<
T
>
public
abstract
class
Component
:
Object
{
private
T
owner
;
private
Entity
owner
;
public
T
GetOwner
<
T
>()
where
T
:
Entity
{
return
this
.
owner
as
T
;
}
[
BsonIgnore
]
public
T
Owner
public
void
SetOwner
(
Entity
entity
)
{
get
{
return
this
.
owner
;
}
set
{
this
.
owner
=
value
;
}
this
.
owner
=
entity
;
}
protected
Component
()
...
...
Unity/Assets/Scripts/Base/Object/Entity.cs
浏览文件 @
ef1520c3
...
...
@@ -6,33 +6,23 @@ using MongoDB.Bson.Serialization.Attributes;
namespace
Base
{
public
abstract
class
Entity
<
T
>:
Object
where
T
:
Entity
<
T
>
public
abstract
class
Entity
:
Object
{
[
BsonElement
,
BsonIgnoreIfNull
]
private
HashSet
<
Component
<
T
>>
components
=
new
HashSet
<
Component
<
T
>>();
private
Dictionary
<
Type
,
Component
<
T
>>
componentDict
=
new
Dictionary
<
Type
,
Component
<
T
>>();
public
string
Name
{
get
;
}
private
HashSet
<
Component
>
components
=
new
HashSet
<
Component
>();
private
Dictionary
<
Type
,
Component
>
componentDict
=
new
Dictionary
<
Type
,
Component
>();
protected
Entity
()
{
this
.
Name
=
""
;
ObjectManager
.
Add
(
this
);
}
protected
Entity
(
string
name
)
{
this
.
Name
=
name
;
ObjectManager
.
Add
(
this
);
}
protected
Entity
(
long
id
,
string
name
):
base
(
id
)
protected
Entity
(
long
id
):
base
(
id
)
{
this
.
Name
=
name
;
ObjectManager
.
Add
(
this
);
}
public
T
Clone
()
public
T
Clone
<
T
>()
where
T
:
Entity
{
return
MongoHelper
.
FromBson
<
T
>(
MongoHelper
.
ToBson
(
this
));
}
...
...
@@ -46,7 +36,7 @@ namespace Base
base
.
Dispose
();
foreach
(
Component
<
T
>
component
in
this
.
GetComponents
())
foreach
(
Component
component
in
this
.
GetComponents
())
{
try
{
...
...
@@ -60,10 +50,10 @@ namespace Base
ObjectManager
.
Remove
(
this
.
Id
);
}
public
K
AddComponent
<
K
>()
where
K
:
Component
<
T
>
,
new
()
public
K
AddComponent
<
K
>()
where
K
:
Component
,
new
()
{
K
component
=
(
K
)
Activator
.
CreateInstance
(
typeof
(
K
));
component
.
Owner
=
(
T
)
this
;
component
.
SetOwner
(
this
)
;
if
(
this
.
componentDict
.
ContainsKey
(
component
.
GetType
()))
{
...
...
@@ -72,7 +62,7 @@ namespace Base
if
(
this
.
components
==
null
)
{
this
.
components
=
new
HashSet
<
Component
<
T
>
>();
this
.
components
=
new
HashSet
<
Component
>();
}
this
.
components
.
Add
(
component
);
...
...
@@ -81,10 +71,10 @@ namespace Base
return
component
;
}
public
K
AddComponent
<
K
,
P1
>(
P1
p1
)
where
K
:
Component
<
T
>
,
new
()
public
K
AddComponent
<
K
,
P1
>(
P1
p1
)
where
K
:
Component
,
new
()
{
K
component
=
(
K
)
Activator
.
CreateInstance
(
typeof
(
K
));
component
.
Owner
=
(
T
)
this
;
component
.
SetOwner
(
this
)
;
if
(
this
.
componentDict
.
ContainsKey
(
component
.
GetType
()))
{
...
...
@@ -93,7 +83,7 @@ namespace Base
if
(
this
.
components
==
null
)
{
this
.
components
=
new
HashSet
<
Component
<
T
>
>();
this
.
components
=
new
HashSet
<
Component
>();
}
this
.
components
.
Add
(
component
);
...
...
@@ -102,10 +92,10 @@ namespace Base
return
component
;
}
public
K
AddComponent
<
K
,
P1
,
P2
>(
P1
p1
,
P2
p2
)
where
K
:
Component
<
T
>
,
new
()
public
K
AddComponent
<
K
,
P1
,
P2
>(
P1
p1
,
P2
p2
)
where
K
:
Component
,
new
()
{
K
component
=
(
K
)
Activator
.
CreateInstance
(
typeof
(
K
));
component
.
Owner
=
(
T
)
this
;
component
.
SetOwner
(
this
)
;
if
(
this
.
componentDict
.
ContainsKey
(
component
.
GetType
()))
{
...
...
@@ -114,7 +104,7 @@ namespace Base
if
(
this
.
components
==
null
)
{
this
.
components
=
new
HashSet
<
Component
<
T
>
>();
this
.
components
=
new
HashSet
<
Component
>();
}
this
.
components
.
Add
(
component
);
...
...
@@ -124,10 +114,10 @@ namespace Base
}
public
K
AddComponent
<
K
,
P1
,
P2
,
P3
>(
P1
p1
,
P2
p2
,
P3
p3
)
where
K
:
Component
<
T
>
,
new
()
public
K
AddComponent
<
K
,
P1
,
P2
,
P3
>(
P1
p1
,
P2
p2
,
P3
p3
)
where
K
:
Component
,
new
()
{
K
component
=
(
K
)
Activator
.
CreateInstance
(
typeof
(
K
));
component
.
Owner
=
(
T
)
this
;
component
.
SetOwner
(
this
)
;
if
(
this
.
componentDict
.
ContainsKey
(
component
.
GetType
()))
{
...
...
@@ -136,7 +126,7 @@ namespace Base
if
(
this
.
components
==
null
)
{
this
.
components
=
new
HashSet
<
Component
<
T
>
>();
this
.
components
=
new
HashSet
<
Component
>();
}
this
.
components
.
Add
(
component
);
...
...
@@ -145,7 +135,7 @@ namespace Base
return
component
;
}
public
void
AddComponent
(
Component
<
T
>
component
)
public
void
AddComponent
(
Component
component
)
{
if
(
this
.
componentDict
.
ContainsKey
(
component
.
GetType
()))
{
...
...
@@ -154,16 +144,16 @@ namespace Base
if
(
this
.
components
==
null
)
{
this
.
components
=
new
HashSet
<
Component
<
T
>
>();
this
.
components
=
new
HashSet
<
Component
>();
}
this
.
components
.
Add
(
component
);
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
ObjectManager
.
Awake
(
component
.
Id
);
}
public
void
RemoveComponent
<
K
>()
where
K
:
Component
<
T
>
public
void
RemoveComponent
<
K
>()
where
K
:
Component
{
Component
<
T
>
component
;
Component
component
;
if
(!
this
.
componentDict
.
TryGetValue
(
typeof
(
K
),
out
component
))
{
return
;
...
...
@@ -178,9 +168,9 @@ namespace Base
component
.
Dispose
();
}
public
K
GetComponent
<
K
>()
where
K
:
Component
<
T
>
public
K
GetComponent
<
K
>()
where
K
:
Component
{
Component
<
T
>
component
;
Component
component
;
if
(!
this
.
componentDict
.
TryGetValue
(
typeof
(
K
),
out
component
))
{
return
default
(
K
);
...
...
@@ -188,7 +178,7 @@ namespace Base
return
(
K
)
component
;
}
public
Component
<
T
>
[]
GetComponents
()
public
Component
[]
GetComponents
()
{
return
components
.
ToArray
();
}
...
...
@@ -196,8 +186,8 @@ namespace Base
public
override
void
BeginInit
()
{
base
.
BeginInit
();
this
.
components
=
new
HashSet
<
Component
<
T
>
>();
this
.
componentDict
=
new
Dictionary
<
Type
,
Component
<
T
>
>();
this
.
components
=
new
HashSet
<
Component
>();
this
.
componentDict
=
new
Dictionary
<
Type
,
Component
>();
}
public
override
void
EndInit
()
...
...
@@ -208,9 +198,9 @@ namespace Base
this
.
components
=
null
;
return
;
}
foreach
(
Component
<
T
>
component
in
this
.
components
)
foreach
(
Component
component
in
this
.
components
)
{
component
.
Owner
=
(
T
)
this
;
component
.
SetOwner
(
this
)
;
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
}
}
...
...
Unity/Assets/Scripts/Base/Object/ObjectManager.cs
浏览文件 @
ef1520c3
...
...
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
using
Base
;
namespace
Base
{
...
...
Unity/Assets/Scripts/Component/Game.cs
浏览文件 @
ef1520c3
namespace
Base
{
public
sealed
class
Game
:
Entity
<
Game
>
public
sealed
class
Game
:
Entity
{
private
static
Scene
game
;
...
...
Unity/Assets/Scripts/Component/KVComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -7,7 +7,7 @@ namespace Base
/// <summary>
/// Key Value组件用于保存一些数据
/// </summary>
public
class
KVComponent
<
T
>
:
Component
<
T
>
where
T
:
Entity
<
T
>
public
class
KVComponent
:
Component
{
[
BsonElement
]
private
readonly
Dictionary
<
string
,
object
>
kv
=
new
Dictionary
<
string
,
object
>();
...
...
@@ -22,14 +22,14 @@ namespace Base
this
.
kv
.
Remove
(
key
);
}
public
K
Get
<
K
>(
string
key
)
public
T
Get
<
T
>(
string
key
)
{
object
k
;
if
(!
this
.
kv
.
TryGetValue
(
key
,
out
k
))
{
return
default
(
K
);
return
default
(
T
);
}
return
(
K
)
k
;
return
(
T
)
k
;
}
public
override
void
Dispose
()
...
...
@@ -45,19 +45,19 @@ namespace Base
public
static
class
KVHelper
{
public
static
void
Add
<
T
>(
this
Entity
<
T
>
entity
,
string
key
,
T
value
)
where
T
:
Entity
<
T
>
public
static
void
KVAdd
(
this
Entity
entity
,
string
key
,
object
value
)
{
entity
.
GetComponent
<
KVComponent
<
T
>
>().
Add
(
key
,
value
);
entity
.
GetComponent
<
KVComponent
>().
Add
(
key
,
value
);
}
public
static
void
Remove
<
T
>(
this
Entity
<
T
>
entity
,
string
key
)
where
T
:
Entity
<
T
>
public
static
void
KVRemove
(
this
Entity
entity
,
string
key
)
{
entity
.
GetComponent
<
KVComponent
<
T
>
>().
Remove
(
key
);
entity
.
GetComponent
<
KVComponent
>().
Remove
(
key
);
}
public
static
void
Get
<
T
,
K
>(
this
Entity
<
T
>
entity
,
string
key
)
where
T
:
Entity
<
T
>
public
static
void
KVGet
<
T
>(
this
Entity
entity
,
string
key
)
{
entity
.
GetComponent
<
KVComponent
<
T
>>().
Get
<
K
>(
key
);
entity
.
GetComponent
<
KVComponent
>().
Get
<
T
>(
key
);
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Component/KVComponent.cs.meta
0 → 100644
浏览文件 @
ef1520c3
fileFormatVersion: 2
guid: 17265c1c4bf06a94da594ce31869e163
timeCreated: 1475893345
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Component/Scene.cs
浏览文件 @
ef1520c3
...
...
@@ -10,18 +10,17 @@ namespace Base
Login
,
Lobby
,
Map
,
Launcher
,
Robot
,
BehaviorTreeScene
,
RobotClient
,
}
public
sealed
class
Scene
:
Entity
<
Scene
>
public
sealed
class
Scene
:
Entity
{
public
string
Name
{
get
;
}
public
SceneType
SceneType
{
get
;
}
public
Scene
(
string
name
,
SceneType
sceneType
)
:
base
(
name
)
public
Scene
(
string
name
,
SceneType
sceneType
)
{
this
.
Name
=
name
;
this
.
SceneType
=
sceneType
;
}
...
...
Unity/Assets/Scripts/Component/
Level
Component.cs
→
Unity/Assets/Scripts/Component/
Scene/Children
Component.cs
浏览文件 @
ef1520c3
...
...
@@ -7,17 +7,14 @@ namespace Base
/// <summary>
/// 父子层级信息
/// </summary>
public
class
LevelComponent
<
T
>
:
Component
<
T
>
where
T
:
Entity
<
T
>
public
class
ChildrenComponent
:
Component
{
[
BsonIgnore
]
public
T
Parent
{
get
;
private
set
;
}
[
BsonElement
]
private
readonly
List
<
T
>
children
=
new
List
<
T
>();
public
Scene
Parent
{
get
;
private
set
;
}
private
readonly
Dictionary
<
long
,
T
>
idChildren
=
new
Dictionary
<
long
,
T
>();
private
readonly
Dictionary
<
long
,
Scene
>
idChildren
=
new
Dictionary
<
long
,
Scene
>();
private
readonly
Dictionary
<
string
,
T
>
nameChildren
=
new
Dictionary
<
string
,
T
>();
private
readonly
Dictionary
<
string
,
Scene
>
nameChildren
=
new
Dictionary
<
string
,
Scene
>();
[
BsonIgnore
]
public
int
Count
...
...
@@ -28,44 +25,43 @@ namespace Base
}
}
public
void
Add
(
T
t
)
public
void
Add
(
Scene
scene
)
{
t
.
GetComponent
<
LevelComponent
<
T
>>().
Parent
=
this
.
Owner
;
this
.
children
.
Add
(
t
);
this
.
idChildren
.
Add
(
t
.
Id
,
t
);
this
.
nameChildren
.
Add
(
t
.
Name
,
t
);
scene
.
GetComponent
<
ChildrenComponent
>().
Parent
=
this
.
GetOwner
<
Scene
>();
this
.
idChildren
.
Add
(
scene
.
Id
,
scene
);
this
.
nameChildren
.
Add
(
scene
.
Name
,
scene
);
}
public
T
[]
GetChildren
()
public
Scene
[]
GetChildren
()
{
return
this
.
children
.
ToArray
();
return
this
.
idChildren
.
Values
.
ToArray
();
}
private
void
Remove
(
T
t
)
private
void
Remove
(
Scene
scene
)
{
this
.
idChildren
.
Remove
(
t
.
Id
);
this
.
nameChildren
.
Remove
(
t
.
Name
);
t
.
Dispose
();
this
.
idChildren
.
Remove
(
scene
.
Id
);
this
.
nameChildren
.
Remove
(
scene
.
Name
);
scene
.
Dispose
();
}
public
void
Remove
(
long
id
)
{
T
t
;
if
(!
this
.
idChildren
.
TryGetValue
(
id
,
out
t
))
Scene
scene
;
if
(!
this
.
idChildren
.
TryGetValue
(
id
,
out
scene
))
{
return
;
}
this
.
Remove
(
t
);
this
.
Remove
(
scene
);
}
public
void
Remove
(
string
name
)
{
T
t
;
if
(!
this
.
nameChildren
.
TryGetValue
(
name
,
out
t
))
Scene
scene
;
if
(!
this
.
nameChildren
.
TryGetValue
(
name
,
out
scene
))
{
return
;
}
this
.
Remove
(
t
);
this
.
Remove
(
scene
);
}
public
override
void
Dispose
()
...
...
@@ -77,30 +73,30 @@ namespace Base
base
.
Dispose
();
foreach
(
T
t
in
this
.
children
)
foreach
(
Scene
scene
in
this
.
idChildren
.
Values
.
ToArray
()
)
{
t
.
Dispose
();
scene
.
Dispose
();
}
this
.
Parent
?.
GetComponent
<
LevelComponent
<
T
>
>().
Remove
(
this
.
Id
);
this
.
Parent
?.
GetComponent
<
ChildrenComponent
>().
Remove
(
this
.
Id
);
}
}
public
static
class
LevelHelper
{
public
static
void
Add
Child
<
T
>(
this
Entity
<
T
>
entity
,
T
t
)
where
T
:
Entity
<
T
>
public
static
void
Add
(
this
Scene
scene
,
Scene
child
)
{
entity
.
GetComponent
<
LevelComponent
<
T
>>().
Add
(
t
);
scene
.
GetComponent
<
ChildrenComponent
>().
Add
(
child
);
}
public
static
void
Remove
Child
<
T
>(
this
Entity
<
T
>
entity
,
long
id
)
where
T
:
Entity
<
T
>
public
static
void
Remove
(
this
Scene
scene
,
long
id
)
{
entity
.
GetComponent
<
LevelComponent
<
T
>
>().
Remove
(
id
);
scene
.
GetComponent
<
ChildrenComponent
>().
Remove
(
id
);
}
public
static
void
Remove
Child
<
T
>(
this
Entity
<
T
>
entity
,
string
name
)
where
T
:
Entity
<
T
>
public
static
void
Remove
(
this
Scene
scene
,
string
name
)
{
entity
.
GetComponent
<
LevelComponent
<
T
>
>().
Remove
(
name
);
scene
.
GetComponent
<
ChildrenComponent
>().
Remove
(
name
);
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Component/Scene/ChildrenComponent.cs.meta
0 → 100644
浏览文件 @
ef1520c3
fileFormatVersion: 2
guid: 97ef5ac3bc0b59240b674d0385978404
timeCreated: 1475893346
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Component/Scene/EventComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -21,7 +21,7 @@ namespace Base
/// <summary>
/// 事件分发
/// </summary>
public
class
EventComponent
:
Component
<
Scene
>
public
class
EventComponent
:
Component
{
private
Dictionary
<
EventIdType
,
List
<
object
>>
allEvents
;
...
...
Unity/Assets/Scripts/Component/Scene/GlobalConfigComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -14,7 +14,7 @@ namespace Base
/// <summary>
/// 全局配置
/// </summary>
public
class
GlobalConfigComponent
:
Component
<
Scene
>
public
class
GlobalConfigComponent
:
Component
{
public
GlobalProto
GlobalProto
;
...
...
Unity/Assets/Scripts/Component/Scene/LogComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -13,7 +13,7 @@ namespace Base
}
}
public
class
LogComponent
:
Component
<
Scene
>
public
class
LogComponent
:
Component
{
private
StreamWriter
info
;
...
...
Unity/Assets/Scripts/Component/Scene/MessageComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -19,8 +19,7 @@ namespace Base
{
public
void
Load
()
{
MessageComponent
component
=
this
.
GetValue
();
component
.
Load
();
this
.
GetValue
().
Load
();
}
public
void
Awake
()
...
...
@@ -37,7 +36,7 @@ namespace Base
/// <summary>
/// 消息分发组件
/// </summary>
public
class
MessageComponent
:
Component
<
Scene
>
public
class
MessageComponent
:
Component
{
private
uint
RpcId
{
get
;
set
;
}
private
Dictionary
<
Opcode
,
List
<
Action
<
byte
[],
int
,
int
>>>
events
;
...
...
@@ -67,7 +66,7 @@ namespace Base
}
MessageAttribute
messageAttribute
=
(
MessageAttribute
)
attrs
[
0
];
if
(
messageAttribute
.
SceneType
!=
this
.
Owner
.
SceneType
)
if
(
messageAttribute
.
SceneType
!=
this
.
GetOwner
<
Scene
>()
.
SceneType
)
{
continue
;
}
...
...
@@ -109,7 +108,7 @@ namespace Base
Log
.
Debug
(
MongoHelper
.
ToJson
(
t
));
}
action
(
this
.
Owner
,
t
);
action
(
this
.
GetOwner
<
Scene
>()
,
t
);
});
}
...
...
@@ -208,7 +207,7 @@ namespace Base
List
<
Action
<
byte
[],
int
,
int
>>
actions
;
if
(!
this
.
events
.
TryGetValue
(
opcode
,
out
actions
))
{
if
(
this
.
Owner
.
SceneType
==
SceneType
.
Game
)
if
(
this
.
GetOwner
<
Scene
>()
.
SceneType
==
SceneType
.
Game
)
{
Log
.
Error
(
$"消息
{
opcode
}
没有处理"
);
}
...
...
@@ -228,6 +227,41 @@ namespace Base
}
}
public
Task
<
Response
>
CallAsync
<
Response
>(
object
request
,
CancellationToken
cancellationToken
)
where
Response
:
IErrorMessage
{
this
.
Send
(
request
,
++
this
.
RpcId
);
var
tcs
=
new
TaskCompletionSource
<
Response
>();
this
.
requestCallback
[
this
.
RpcId
]
=
(
bytes
,
offset
,
count
)
=>
{
try
{
Response
response
=
MongoHelper
.
FromBson
<
Response
>(
bytes
,
offset
,
count
);
Opcode
opcode
=
EnumHelper
.
FromString
<
Opcode
>(
response
.
GetType
().
Name
);
if
(
OpcodeHelper
.
IsNeedDebugLogMessage
(
opcode
))
{
Log
.
Debug
(
MongoHelper
.
ToJson
(
response
));
}
if
(
response
.
ErrorMessage
.
errno
!=
(
int
)
ErrorCode
.
ERR_Success
)
{
tcs
.
SetException
(
new
RpcException
((
ErrorCode
)
response
.
ErrorMessage
.
errno
,
response
.
ErrorMessage
.
msg
.
Utf8ToStr
()));
return
;
}
tcs
.
SetResult
(
response
);
}
catch
(
Exception
e
)
{
tcs
.
SetException
(
new
GameException
(
$"Rpc Error:
{
typeof
(
Response
).
FullName
}
"
,
e
));
}
};
cancellationToken
.
Register
(()
=>
{
this
.
requestCallback
.
Remove
(
this
.
RpcId
);
});
return
tcs
.
Task
;
}
/// <summary>
/// Rpc调用,发送一个消息,等待返回一个消息
/// </summary>
...
...
@@ -275,6 +309,7 @@ namespace Base
{
var
tcs
=
new
TaskCompletionSource
<
Response
>();
Opcode
opcode
=
EnumHelper
.
FromString
<
Opcode
>(
typeof
(
Response
).
Name
);
this
.
waitCallback
[
opcode
]
=
(
bytes
,
offset
,
count
)
=>
{
try
...
...
@@ -285,6 +320,7 @@ namespace Base
{
Log
.
Debug
(
MongoHelper
.
ToJson
(
response
));
}
tcs
.
SetResult
(
response
);
}
catch
(
Exception
e
)
...
...
@@ -293,6 +329,8 @@ namespace Base
}
};
cancellationToken
.
Register
(()
=>
{
this
.
waitCallback
.
Remove
(
opcode
);
});
return
tcs
.
Task
;
}
...
...
Unity/Assets/Scripts/Component/Scene/NetworkComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -18,7 +18,7 @@ namespace Base
}
}
public
class
NetworkComponent
:
Component
<
Scene
>
public
class
NetworkComponent
:
Component
{
private
AService
service
;
...
...
Unity/Assets/Scripts/Component/Scene/TimeComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -3,7 +3,7 @@
/// <summary>
/// 用于同步服务端和客户端时间
/// </summary>
public
class
TimeComponent
:
Component
<
Scene
>
public
class
TimeComponent
:
Component
{
private
long
syncTime
;
...
...
Unity/Assets/Scripts/Component/Scene/TimerComponent.cs
浏览文件 @
ef1520c3
...
...
@@ -59,7 +59,7 @@ namespace Base
}
}
public
class
TimerComponent
:
Component
<
Scene
>
public
class
TimerComponent
:
Component
{
public
readonly
Dictionary
<
ObjectId
,
Timer
>
timers
=
new
Dictionary
<
ObjectId
,
Timer
>();
...
...
Unity/Assets/Scripts/Component/Share.cs
浏览文件 @
ef1520c3
...
...
@@ -3,7 +3,7 @@
/// <summary>
/// 游戏和扩展编辑器都需要用到的数据放在这个Scene上面
/// </summary>
public
sealed
class
Share
:
Entity
<
Share
>
public
sealed
class
Share
:
Entity
{
private
static
Scene
share
;
...
...
Unity/Assets/Scripts/Config/BuffProto.cs
0 → 100644
浏览文件 @
ef1520c3
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Base
{
[
BsonIgnoreExtraElements
]
public
class
BuffProto
:
AConfig
{
public
string
Name
{
get
;
set
;
}
public
int
Time
{
get
;
set
;
}
}
[
Config
]
public
class
BuffCategory
:
ACategory
<
BuffProto
>
{
}
}
\ No newline at end of file
Unity/Assets/Scripts/Config/BuffProto.cs.meta
0 → 100644
浏览文件 @
ef1520c3
fileFormatVersion: 2
guid: 8433bdafcbe56e140b3fe0c93722e0cf
timeCreated: 1475898829
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/
Other
/MessageAttribute.cs
→
Unity/Assets/Scripts/
Message
/MessageAttribute.cs
浏览文件 @
ef1520c3
文件已移动
Unity/Assets/Scripts/
Other
/MessageAttribute.cs.meta
→
Unity/Assets/Scripts/
Message
/MessageAttribute.cs.meta
浏览文件 @
ef1520c3
文件已移动
Unity/Controller/Controller.csproj
浏览文件 @
ef1520c3
...
...
@@ -72,6 +72,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder
Include=
"Factory\"
/>
<Folder
Include=
"Helper\"
/>
<Folder
Include=
"Logic\"
/>
</ItemGroup>
...
...
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
浏览文件 @
ef1520c3
...
...
@@ -22,6 +22,7 @@ namespace Controller
Object
.
ObjectManager
.
Register
(
"Base"
,
typeof
(
Game
).
Assembly
);
Game
.
Scene
.
AddComponent
<
MessageComponent
>();
Game
.
Scene
.
AddComponent
<
ChildrenComponent
>();
try
{
...
...
Unity/Unity.CSharp.csproj
浏览文件 @
ef1520c3
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
...
...
@@ -81,12 +81,14 @@
<ItemGroup>
<Compile
Include=
"Assets\Scripts\Base\Config\ACategory.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Config\AConfig.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Config\ConfigAttribute.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Config\ICategory.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\DoubleMap.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\FileHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\GameObjectHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\ArrayHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\ByteHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\EnumHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\FileHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\IdGenerater.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\MD5Helper.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Helper\MongoHelper.cs"
/>
...
...
@@ -99,7 +101,6 @@
<Compile
Include=
"Assets\Scripts\Base\MultiMap.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Network\AChannel.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Network\AService.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Network\TNet\IPoller.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Network\TNet\PacketParser.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Network\TNet\TBuffer.cs"
/>
<Compile
Include=
"Assets\Scripts\Base\Network\TNet\TChannel.cs"
/>
...
...
@@ -132,6 +133,7 @@
<Compile
Include=
"Assets\Scripts\Base\TryLocker.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Game.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\KVComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Scene\ChildrenComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Scene.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Scene\EventComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Scene\GlobalConfigComponent.cs"
/>
...
...
@@ -141,16 +143,17 @@
<Compile
Include=
"Assets\Scripts\Component\Scene\TimeComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Scene\TimerComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Share.cs"
/>
<Compile
Include=
"Assets\Scripts\Co
mponent\LevelComponent
.cs"
/>
<Compile
Include=
"Assets\Scripts\Co
nfig\BuffProto
.cs"
/>
<Compile
Include=
"Assets\Scripts\Config\GlobalProto.cs"
/>
<Compile
Include=
"Assets\Scripts\Init.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\AMEvent.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\ErrorCode.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\IErrorMessage.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\IMRegister.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\Message.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\MessageAttribute.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\Opcode.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\OpcodeHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\Message.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\AEventAttribute.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\EntityType.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\Env.cs"
/>
...
...
@@ -158,13 +161,11 @@
<Compile
Include=
"Assets\Scripts\Other\EventAttribute.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\EventIdType.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\GameException.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\ICategory.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\IEvent.cs"
/>
<Compile
Include=
"Assets\Scripts\Other\MessageAttribute.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"Assets\CSharp 6.0 Support\AsyncTools\Plugins\AsyncBridge.Net35.xml"
/>
<None
Include=
"Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets"
/>
</Project>
\ No newline at end of file
</Project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录