Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
a3d0b31a
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,发现更多精彩内容 >>
提交
a3d0b31a
编写于
9月 09, 2014
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
读取配置模块更新,更加自动化
上级
d2d40eb4
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
73 addition
and
81 deletion
+73
-81
CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs
CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs
+4
-4
CSharp/Game/BehaviorTree/NodeAttribute.cs
CSharp/Game/BehaviorTree/NodeAttribute.cs
+2
-2
CSharp/Game/BehaviorTree/NodeConfig.cs
CSharp/Game/BehaviorTree/NodeConfig.cs
+7
-23
CSharp/Game/BehaviorTree/NodeType.cs
CSharp/Game/BehaviorTree/NodeType.cs
+1
-1
CSharp/Game/BehaviorTree/Selector.cs
CSharp/Game/BehaviorTree/Selector.cs
+1
-1
CSharp/Game/World/Config/GlobalConfig.cs
CSharp/Game/World/Config/GlobalConfig.cs
+6
-4
CSharp/Game/World/World.cs
CSharp/Game/World/World.cs
+4
-2
CSharp/Platform/Common/Common.csproj
CSharp/Platform/Common/Common.csproj
+3
-2
CSharp/Platform/Common/Config/ACategory.cs
CSharp/Platform/Common/Config/ACategory.cs
+13
-17
CSharp/Platform/Common/Config/ConfigAttribute.cs
CSharp/Platform/Common/Config/ConfigAttribute.cs
+1
-1
CSharp/Platform/Common/Config/ConfigManager.cs
CSharp/Platform/Common/Config/ConfigManager.cs
+15
-17
CSharp/Platform/Common/Config/ICategory.cs
CSharp/Platform/Common/Config/ICategory.cs
+9
-0
CSharp/Platform/Common/Config/IConfig.cs
CSharp/Platform/Common/Config/IConfig.cs
+7
-0
CSharp/Platform/Common/Config/IType.cs
CSharp/Platform/Common/Config/IType.cs
+0
-7
未找到文件。
CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs
浏览文件 @
a3d0b31a
...
...
@@ -37,12 +37,12 @@ namespace BehaviorTree
private
Node
CreateNode
(
NodeConfig
config
)
{
if
(!
this
.
dictionary
.
ContainsKey
((
NodeType
)
config
.
Type
))
if
(!
this
.
dictionary
.
ContainsKey
((
NodeType
)
config
.
Id
))
{
throw
new
KeyNotFoundException
(
string
.
Format
(
"CreateNode cannot found: {0}"
,
config
.
Type
));
throw
new
KeyNotFoundException
(
string
.
Format
(
"CreateNode cannot found: {0}"
,
config
.
Id
));
}
return
this
.
dictionary
[(
NodeType
)
config
.
Type
](
config
);
return
this
.
dictionary
[(
NodeType
)
config
.
Id
](
config
);
}
private
Node
CreateTreeNode
(
NodeConfig
config
)
...
...
CSharp/Game/BehaviorTree/NodeAttribute.cs
浏览文件 @
a3d0b31a
...
...
@@ -5,8 +5,8 @@ namespace BehaviorTree
[
AttributeUsage
(
AttributeTargets
.
Class
)]
public
class
NodeAttribute
:
Attribute
{
public
NodeType
NodeType
{
get
;
set
;
}
public
Type
ClassType
{
get
;
set
;
}
public
NodeType
NodeType
{
get
;
private
set
;
}
public
Type
ClassType
{
get
;
private
set
;
}
public
NodeAttribute
(
NodeType
nodeType
,
Type
classType
)
{
...
...
CSharp/Game/BehaviorTree/NodeConfig.cs
浏览文件 @
a3d0b31a
using
System.Collections.Generic
;
using
Common.Config
;
using
MongoDB.Bson.Serialization.Attributes
;
namespace
BehaviorTree
{
public
class
NodeConfig
public
class
NodeConfig
:
IConfig
{
public
uint
Id
{
get
;
set
;
}
public
int
Type
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
[
BsonIgnoreIfNull
]
public
List
<
string
>
Args
{
get
;
set
;
}
[
BsonIgnoreIfNull
]
public
List
<
NodeConfig
>
SubConfigs
{
get
;
set
;
}
}
public
void
AddArgs
(
string
arg
)
{
if
(
this
.
Args
==
null
)
{
this
.
Args
=
new
List
<
string
>();
}
this
.
Args
.
Add
(
arg
);
}
public
void
AddSubConfig
(
NodeConfig
subConfig
)
{
if
(
this
.
SubConfigs
==
null
)
{
this
.
SubConfigs
=
new
List
<
NodeConfig
>();
}
this
.
SubConfigs
.
Add
(
subConfig
);
}
[
Config
]
public
class
NodeCategory
:
ACategory
<
NodeConfig
>
{
}
}
\ No newline at end of file
CSharp/Game/BehaviorTree/NodeType.cs
浏览文件 @
a3d0b31a
...
...
@@ -2,7 +2,7 @@
{
public
enum
NodeType
{
Select
=
1
,
Select
or
=
1
,
Sequence
=
2
,
Not
=
10
,
}
...
...
CSharp/Game/BehaviorTree/Selector.cs
浏览文件 @
a3d0b31a
namespace
BehaviorTree
{
[
NodeAttribute
(
NodeType
.
Select
,
typeof
(
Selector
))]
[
NodeAttribute
(
NodeType
.
Select
or
,
typeof
(
Selector
))]
public
class
Selector
:
Node
{
public
Selector
(
NodeConfig
config
):
base
(
config
)
...
...
CSharp/Game/World/Config/GlobalConfig.cs
浏览文件 @
a3d0b31a
namespace
Model.Config
using
Common.Config
;
namespace
World.Config
{
public
class
GlobalConfig
:
I
Type
public
class
GlobalConfig
:
I
Config
{
public
int
Type
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
}
[
Config
]
public
class
GlobalCategory
:
Config
Category
<
GlobalConfig
>
public
class
GlobalCategory
:
A
Category
<
GlobalConfig
>
{
}
}
\ No newline at end of file
CSharp/Game/World/World.cs
浏览文件 @
a3d0b31a
using
Model
;
using
Common.Config
;
using
Model
;
namespace
World
{
...
...
@@ -6,7 +7,7 @@ namespace World
{
private
static
readonly
World
instance
=
new
World
();
private
readonly
ConfigManager
configManager
=
new
ConfigManager
(
typeof
(
World
).
Assembly
);
private
readonly
ConfigManager
configManager
=
new
ConfigManager
();
private
readonly
GameObjectManager
gameObjectManager
=
new
GameObjectManager
();
...
...
@@ -20,6 +21,7 @@ namespace World
private
World
()
{
configManager
.
Load
(
typeof
(
World
).
Assembly
);
}
public
ConfigManager
ConfigManager
...
...
CSharp/Platform/Common/Common.csproj
浏览文件 @
a3d0b31a
...
...
@@ -58,15 +58,16 @@
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Config\ICategory.cs"
/>
<Compile
Include=
"Event\EventTrigger.cs"
/>
<Compile
Include=
"Event\Env.cs"
/>
<Compile
Include=
"Event\IEventAttribute.cs"
/>
<Compile
Include=
"Event\IEvent.cs"
/>
<Compile
Include=
"Base\Object.cs"
/>
<Compile
Include=
"Config\ConfigAttribute.cs"
/>
<Compile
Include=
"Config\
Config
Category.cs"
/>
<Compile
Include=
"Config\
A
Category.cs"
/>
<Compile
Include=
"Config\ConfigManager.cs"
/>
<Compile
Include=
"Config\I
Type
.cs"
/>
<Compile
Include=
"Config\I
Config
.cs"
/>
<Compile
Include=
"Helper\BigIntegerHelper.cs"
/>
<Compile
Include=
"Helper\ByteHelper.cs"
/>
<Compile
Include=
"Helper\EnumHelper.cs"
/>
...
...
CSharp/Platform/Common/Config/
Config
Category.cs
→
CSharp/Platform/Common/Config/
A
Category.cs
浏览文件 @
a3d0b31a
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.IO
;
using
System.Linq
;
using
Common.Helper
;
namespace
Model
namespace
Common.Config
{
public
abstract
class
ConfigCategory
<
T
>:
ISupportInitialize
where
T
:
IType
public
abstract
class
ACategory
<
T
>:
ICategory
where
T
:
IConfig
{
protected
readonly
Dictionary
<
int
,
T
>
dict
=
new
Dictionary
<
int
,
T
>();
p
rotected
ConfigCategory
()
p
ublic
void
BeginInit
()
{
string
path
=
Path
.
Combine
(
@"./Config/"
,
this
.
Config
Name
);
string
path
=
Path
.
Combine
(
@"./Config/"
,
this
.
Name
);
if
(!
Directory
.
Exists
(
path
))
{
...
...
@@ -22,10 +22,14 @@ namespace Model
foreach
(
var
file
in
Directory
.
GetFiles
(
path
))
{
var
t
=
MongoHelper
.
FromJson
<
T
>(
File
.
ReadAllText
(
file
));
this
.
dict
.
Add
(
t
.
Type
,
t
);
this
.
dict
.
Add
(
t
.
Id
,
t
);
}
}
public
void
EndInit
()
{
}
public
T
this
[
int
type
]
{
get
...
...
@@ -34,7 +38,7 @@ namespace Model
}
}
public
string
Config
Name
public
string
Name
{
get
{
...
...
@@ -42,17 +46,9 @@ namespace Model
}
}
public
Dictionary
<
int
,
T
>
GetAll
()
{
return
this
.
dict
;
}
public
void
BeginInit
()
{
}
public
void
EndInit
()
public
T
[]
GetAll
()
{
return
this
.
dict
.
Values
.
ToArray
();
}
}
}
\ No newline at end of file
CSharp/Platform/Common/Config/ConfigAttribute.cs
浏览文件 @
a3d0b31a
using
System
;
namespace
Model
namespace
Common.Config
{
[
AttributeUsage
(
AttributeTargets
.
Class
)]
public
class
ConfigAttribute
:
Attribute
...
...
CSharp/Platform/Common/Config/ConfigManager.cs
浏览文件 @
a3d0b31a
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Reflection
;
namespace
Model
namespace
Common.Config
{
public
class
ConfigManager
{
public
Dictionary
<
string
,
object
>
allConfig
;
public
ConfigManager
(
Assembly
assembly
)
{
Load
(
assembly
);
}
public
void
Load
(
Assembly
assembly
)
{
var
localAllConfig
=
new
Dictionary
<
string
,
object
>();
...
...
@@ -28,33 +22,37 @@ namespace Model
object
obj
=
(
Activator
.
CreateInstance
(
type
));
var
iSupportInitialize
=
obj
as
ISupportInitialize
;
if
(
iSupportInitialize
!=
null
)
ICategory
iCategory
=
obj
as
ICategory
;
if
(
iCategory
==
null
)
{
iSupportInitialize
.
EndInit
(
);
throw
new
Exception
(
string
.
Format
(
"class: {0} not inherit from ACategory"
,
type
.
Name
)
);
}
iCategory
.
BeginInit
();
iCategory
.
EndInit
();
localAllConfig
[
type
.
Name
]
=
obj
;
}
this
.
allConfig
=
localAllConfig
;
}
public
T
Get
<
T
>(
int
type
)
where
T
:
I
Type
public
T
Get
<
T
>(
int
type
)
where
T
:
I
Config
{
var
configCategory
=
(
Config
Category
<
T
>)
this
.
allConfig
[
typeof
(
T
).
Name
];
var
configCategory
=
(
A
Category
<
T
>)
this
.
allConfig
[
typeof
(
T
).
Name
];
return
configCategory
[
type
];
}
public
Dictionary
<
int
,
T
>
GetAll
<
T
>()
where
T
:
IType
public
T
[]
GetAll
<
T
>()
where
T
:
IConfig
{
var
configCategory
=
(
Config
Category
<
T
>)
this
.
allConfig
[
typeof
(
T
).
Name
];
var
configCategory
=
(
A
Category
<
T
>)
this
.
allConfig
[
typeof
(
T
).
Name
];
return
configCategory
.
GetAll
();
}
public
ConfigCategory
<
T
>
GetConfigCategory
<
T
>()
where
T
:
IType
public
T
GetCategory
<
T
>()
where
T
:
class
,
ICategory
,
new
()
{
return
(
ConfigCategory
<
T
>)
this
.
allConfig
[
typeof
(
T
).
Name
];
T
t
=
new
T
();
object
category
;
bool
ret
=
this
.
allConfig
.
TryGetValue
(
t
.
Name
,
out
category
);
return
ret
?
(
T
)
category
:
null
;
}
}
}
\ No newline at end of file
CSharp/Platform/Common/Config/ICategory.cs
0 → 100644
浏览文件 @
a3d0b31a
using
System.ComponentModel
;
namespace
Common.Config
{
public
interface
ICategory
:
ISupportInitialize
{
string
Name
{
get
;
}
}
}
CSharp/Platform/Common/Config/IConfig.cs
0 → 100644
浏览文件 @
a3d0b31a
namespace
Common.Config
{
public
interface
IConfig
{
int
Id
{
get
;
}
}
}
\ No newline at end of file
CSharp/Platform/Common/Config/IType.cs
已删除
100644 → 0
浏览文件 @
d2d40eb4
namespace
Model
{
public
interface
IType
{
int
Type
{
get
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录