Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
53a7803a
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,发现更多精彩内容 >>
提交
53a7803a
编写于
10月 16, 2014
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Entity和Component继承ISupportInitialize,实现EndInit,反序列化后进行初始化
上级
6dd31f36
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
51 addition
and
48 deletion
+51
-48
CSharp/Game/Model/Buff.cs
CSharp/Game/Model/Buff.cs
+1
-13
CSharp/Game/Model/BuffComponent.cs
CSharp/Game/Model/BuffComponent.cs
+5
-8
CSharp/Game/Model/GameObject.cs
CSharp/Game/Model/GameObject.cs
+1
-13
CSharp/Platform/Common/Base/Component.cs
CSharp/Platform/Common/Base/Component.cs
+10
-4
CSharp/Platform/Common/Base/Entity.cs
CSharp/Platform/Common/Base/Entity.cs
+32
-8
CSharp/Platform/Common/Base/Object.cs
CSharp/Platform/Common/Base/Object.cs
+2
-2
未找到文件。
CSharp/Game/Model/Buff.cs
浏览文件 @
53a7803a
...
...
@@ -4,18 +4,6 @@ namespace Model
{
public
class
Buff
:
Object
{
private
BuffType
type
;
public
BuffType
Type
{
get
{
return
this
.
type
;
}
set
{
this
.
type
=
value
;
}
}
public
BuffType
Type
{
get
;
set
;
}
}
}
\ No newline at end of file
CSharp/Game/Model/BuffComponent.cs
浏览文件 @
53a7803a
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
Common.Base
;
using
MongoDB.Bson
;
using
MongoDB.Bson.Serialization.Attributes
;
using
Component
=
Common
.
Base
.
Component
;
namespace
Model
{
public
class
BuffComponent
:
Component
,
ISupportInitialize
public
class
BuffComponent
:
Component
{
public
HashSet
<
Buff
>
Buffs
{
get
;
set
;
}
[
BsonElement
]
private
HashSet
<
Buff
>
Buffs
{
get
;
set
;
}
private
Dictionary
<
ObjectId
,
Buff
>
buffGuidDict
{
get
;
set
;
}
...
...
@@ -21,11 +22,7 @@ namespace Model
this
.
buffTypeMMap
=
new
MultiMap
<
BuffType
,
Buff
>();
}
void
ISupportInitialize
.
BeginInit
()
{
}
void
ISupportInitialize
.
EndInit
()
public
override
void
EndInit
()
{
foreach
(
var
buff
in
this
.
Buffs
)
{
...
...
CSharp/Game/Model/GameObject.cs
浏览文件 @
53a7803a
...
...
@@ -9,18 +9,6 @@ namespace Model
public
class
GameObject
:
Entity
{
private
GameObjectType
type
;
public
GameObjectType
Type
{
get
{
return
this
.
type
;
}
set
{
this
.
type
=
value
;
}
}
public
GameObjectType
Type
{
get
;
set
;
}
}
}
\ No newline at end of file
CSharp/Platform/Common/Base/Component.cs
浏览文件 @
53a7803a
using
MongoDB.Bson.Serialization.Attributes
;
using
System.ComponentModel
;
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Common.Base
{
public
class
Component
:
Object
public
abstract
class
Component
:
Object
,
ISupportInitialize
{
private
Entity
owner
;
[
BsonIgnore
]
public
Entity
Owner
{
public
Entity
Owner
{
get
{
return
owner
;
...
...
@@ -19,7 +21,11 @@ namespace Common.Base
}
}
protected
Component
()
public
virtual
void
BeginInit
()
{
}
public
virtual
void
EndInit
()
{
}
}
...
...
CSharp/Platform/Common/Base/Entity.cs
浏览文件 @
53a7803a
using
System.Collections.Generic
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Common.Base
{
public
class
Entity
:
Object
public
abstract
class
Entity
:
Object
,
ISupportInitialize
{
public
Dictionary
<
string
,
Component
>
Components
{
get
;
private
set
;
}
[
BsonElement
]
private
HashSet
<
Component
>
Components
{
get
;
set
;
}
private
Dictionary
<
Type
,
Component
>
ComponentDict
{
get
;
set
;
}
protected
Entity
()
{
this
.
Components
=
new
Dictionary
<
string
,
Component
>();
this
.
Components
=
new
HashSet
<
Component
>();
this
.
ComponentDict
=
new
Dictionary
<
Type
,
Component
>();
}
public
void
AddComponent
<
T
>()
where
T
:
Component
,
new
()
{
T
t
=
new
T
{
Owner
=
this
};
this
.
Components
.
Add
(
typeof
(
T
).
Name
,
t
);
this
.
Components
.
Add
(
t
);
this
.
ComponentDict
.
Add
(
typeof
(
T
),
t
);
}
public
void
RemoveComponent
<
T
>()
where
T
:
Component
{
this
.
Components
.
Remove
(
typeof
(
T
).
Name
);
Component
t
;
this
.
ComponentDict
.
TryGetValue
(
typeof
(
T
),
out
t
);
this
.
Components
.
Remove
(
t
);
this
.
ComponentDict
.
Remove
(
typeof
(
T
));
}
public
T
GetComponent
<
T
>()
where
T
:
Component
{
Component
t
;
if
(!
this
.
Component
s
.
TryGetValue
(
typeof
(
T
).
Name
,
out
t
))
if
(!
this
.
Component
Dict
.
TryGetValue
(
typeof
(
T
)
,
out
t
))
{
return
null
;
}
...
...
@@ -35,7 +46,20 @@ namespace Common.Base
public
Component
[]
GetComponents
()
{
return
this
.
Components
.
Values
.
ToArray
();
return
this
.
Components
.
ToArray
();
}
public
virtual
void
BeginInit
()
{
}
public
virtual
void
EndInit
()
{
foreach
(
Component
component
in
this
.
Components
)
{
this
.
ComponentDict
.
Add
(
component
.
GetType
(),
component
);
component
.
Owner
=
this
;
}
}
}
}
\ No newline at end of file
CSharp/Platform/Common/Base/Object.cs
浏览文件 @
53a7803a
...
...
@@ -4,14 +4,14 @@ using MongoDB.Bson.Serialization.Attributes;
namespace
Common.Base
{
public
class
Object
public
abstract
class
Object
{
[
BsonId
]
public
ObjectId
Guid
{
get
;
protected
set
;
}
[
BsonElement
]
[
BsonIgnoreIfNull
]
p
ublic
Dictionary
<
string
,
object
>
Values
;
p
rivate
Dictionary
<
string
,
object
>
Values
;
protected
Object
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录