Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
48857e7e
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 搜索 >>
提交
48857e7e
编写于
6月 26, 2017
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
加入行为树组件
上级
e83b89d2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
169 addition
and
26 deletion
+169
-26
Unity/Assets/Scripts/Component/BehaviorTreeComponent.cs
Unity/Assets/Scripts/Component/BehaviorTreeComponent.cs
+133
-0
Unity/Assets/Scripts/Component/BehaviorTreeComponent.cs.meta
Unity/Assets/Scripts/Component/BehaviorTreeComponent.cs.meta
+12
-0
Unity/Assets/Scripts/Component/ResourcesComponent.cs
Unity/Assets/Scripts/Component/ResourcesComponent.cs
+20
-24
Unity/Hotfix/Init.cs
Unity/Hotfix/Init.cs
+1
-0
Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs
Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs
+2
-2
Unity/Unity.csproj
Unity/Unity.csproj
+1
-0
未找到文件。
Unity/Assets/Scripts/Component/BehaviorTreeComponent.cs
0 → 100644
浏览文件 @
48857e7e
using
System
;
using
System.Collections.Generic
;
using
System.Reflection
;
using
UnityEngine
;
namespace
Model
{
[
EntityEvent
(
EntityEventId
.
BehaviorTreeComponent
)]
public
class
BehaviorTreeComponent
:
Component
{
private
Dictionary
<
string
,
Func
<
NodeProto
,
Node
>>
dictionary
;
private
Dictionary
<
GameObject
,
BehaviorTree
>
treeCache
;
public
void
Awake
()
{
this
.
Load
();
}
public
void
Load
()
{
this
.
dictionary
=
new
Dictionary
<
string
,
Func
<
NodeProto
,
Node
>>();
this
.
treeCache
=
new
Dictionary
<
GameObject
,
BehaviorTree
>();
Type
[]
types
=
DllHelper
.
GetMonoTypes
();
foreach
(
Type
type
in
types
)
{
object
[]
attrs
=
type
.
GetCustomAttributes
(
typeof
(
NodeAttribute
),
false
);
if
(
attrs
.
Length
==
0
)
{
continue
;
}
Type
classType
=
type
;
if
(
this
.
dictionary
.
ContainsKey
(
type
.
Name
))
{
throw
new
Exception
(
$"已经存在同类节点:
{
classType
.
Name
}
"
);
}
this
.
dictionary
.
Add
(
type
.
Name
,
config
=>
{
Node
node
=
(
Node
)
Activator
.
CreateInstance
(
classType
,
config
);
try
{
InitFieldValue
(
ref
node
,
config
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
$"InitFieldValue error, node:
{
node
.
Id
}
{
node
.
Type
}
"
,
e
);
}
return
node
;
});
}
}
private
static
void
InitFieldValue
(
ref
Node
node
,
NodeProto
nodeProto
)
{
Type
type
=
typeof
(
Game
).
Assembly
.
GetType
(
"Model."
+
nodeProto
.
Name
);
foreach
(
var
args_item
in
nodeProto
.
Args
.
Dict
())
{
FieldInfo
fieldInfo
=
type
.
GetField
(
args_item
.
Key
,
BindingFlags
.
Instance
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Public
);
if
(
fieldInfo
==
null
)
{
continue
;
}
NewSetValue
(
ref
node
,
fieldInfo
,
args_item
.
Value
);
}
}
private
static
void
NewSetValue
(
ref
Node
node
,
FieldInfo
field
,
object
value
)
{
// unity enum无法序列化,保存的string形式
if
(
field
.
FieldType
.
IsEnum
)
{
value
=
Enum
.
Parse
(
field
.
FieldType
,
(
string
)
value
);
}
field
.
SetValue
(
node
,
value
);
}
private
Node
CreateOneNode
(
NodeProto
proto
)
{
if
(!
this
.
dictionary
.
ContainsKey
(
proto
.
Name
))
{
throw
new
KeyNotFoundException
(
$"NodeType没有定义该节点:
{
proto
.
Name
}
"
);
}
return
this
.
dictionary
[
proto
.
Name
](
proto
);
}
private
Node
CreateTreeNode
(
NodeProto
proto
)
{
Node
node
=
this
.
CreateOneNode
(
proto
);
node
.
EndInit
(
this
.
GetOwner
<
Scene
>());
if
(
proto
.
Children
==
null
)
{
return
node
;
}
foreach
(
NodeProto
nodeProto
in
proto
.
Children
)
{
Node
childNode
=
this
.
CreateTreeNode
(
nodeProto
);
node
.
AddChild
(
childNode
);
}
return
node
;
}
public
BehaviorTree
CreateTree
(
Scene
scene
,
GameObject
treeGo
)
{
try
{
BehaviorTree
tree
;
if
(
this
.
treeCache
.
TryGetValue
(
treeGo
,
out
tree
))
{
return
tree
;
}
BehaviorTreeConfig
behaviorTreeConfig
=
treeGo
.
GetComponent
<
BehaviorTreeConfig
>();
Node
node
=
this
.
CreateTreeNode
(
behaviorTreeConfig
.
RootNodeProto
);
tree
=
new
BehaviorTree
(
scene
,
node
);
if
(
Define
.
LoadResourceType
==
LoadResourceType
.
Async
)
{
this
.
treeCache
.
Add
(
treeGo
,
tree
);
}
return
tree
;
}
catch
(
Exception
e
)
{
throw
new
Exception
(
$"行为树配置错误:
{
treeGo
.
name
}
"
,
e
);
}
}
}
}
Unity/Assets/Scripts/Component/BehaviorTreeComponent.cs.meta
0 → 100644
浏览文件 @
48857e7e
fileFormatVersion: 2
guid: 71b098e198f87ba47ba6649596ee01bc
timeCreated: 1498443309
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Component/ResourcesComponent.cs
浏览文件 @
48857e7e
...
...
@@ -64,34 +64,30 @@ namespace Model
TimerComponent
timerComponent
=
Game
.
Scene
.
GetComponent
<
TimerComponent
>();
while
(
true
)
{
WWWAsync
wwwAsync
=
null
;
try
using
(
WWWAsync
wwwAsync
=
new
WWWAsync
())
{
++
count
;
if
(
count
>
1
)
{
await
timerComponent
.
WaitAsync
(
2000
);
try
{
++
count
;
if
(
count
>
1
)
{
await
timerComponent
.
WaitAsync
(
1000
);
}
if
(
this
.
Id
==
0
)
{
return
;
}
await
wwwAsync
.
LoadFromCacheOrDownload
(
url
,
ResourcesComponent
.
AssetBundleManifestObject
.
GetAssetBundleHash
(
assetBundleName
));
assetBundle
=
wwwAsync
.
www
.
assetBundle
;
break
;
}
if
(
this
.
Id
==
0
)
catch
(
Exception
e
)
{
return
;
Log
.
Error
(
e
.
ToString
())
;
}
wwwAsync
=
new
WWWAsync
();
await
wwwAsync
.
LoadFromCacheOrDownload
(
url
,
ResourcesComponent
.
AssetBundleManifestObject
.
GetAssetBundleHash
(
assetBundleName
));
assetBundle
=
wwwAsync
.
www
.
assetBundle
;
break
;
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
ToString
());
}
finally
{
wwwAsync
?.
Dispose
();
}
}
...
...
Unity/Hotfix/Init.cs
浏览文件 @
48857e7e
...
...
@@ -11,6 +11,7 @@ namespace Hotfix
{
Hotfix
.
Scene
.
ModelScene
.
AddComponent
<
NetOuterComponent
>();
Hotfix
.
Scene
.
ModelScene
.
AddComponent
<
ResourcesComponent
>();
Hotfix
.
Scene
.
ModelScene
.
AddComponent
<
BehaviorTreeComponent
>();
Hotfix
.
Scene
.
AddComponent
<
UIComponent
>();
Hotfix
.
Scene
.
AddComponent
<
UnitComponent
>();
Hotfix
.
Scene
.
GetComponent
<
EventComponent
>().
Run
(
EventIdType
.
InitSceneStart
);
...
...
Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs
浏览文件 @
48857e7e
...
...
@@ -22,9 +22,9 @@ namespace Hotfix
Session
session
=
null
;
try
{
session
=
Game
.
Scene
.
GetComponent
<
NetOuterComponent
>().
Create
(
"127.0.0.1:10001"
);
session
=
Hotfix
.
Scene
.
Model
Scene
.
GetComponent
<
NetOuterComponent
>().
Create
(
"127.0.0.1:10001"
);
R2C_Login
r2CLogin
=
await
session
.
Call
<
C2R_Login
,
R2C_Login
>(
new
C2R_Login
()
{
Account
=
"abcdef"
,
Password
=
"111111"
});
Session
gateSession
=
Game
.
Scene
.
GetComponent
<
NetOuterComponent
>().
Create
(
r2CLogin
.
Address
);
Session
gateSession
=
Hotfix
.
Scene
.
Model
Scene
.
GetComponent
<
NetOuterComponent
>().
Create
(
r2CLogin
.
Address
);
G2C_LoginGate
g2CLoginGate
=
await
gateSession
.
Call
<
C2G_LoginGate
,
G2C_LoginGate
>(
new
C2G_LoginGate
(
r2CLogin
.
Key
));
Log
.
Info
(
"登陆gate成功!"
);
...
...
Unity/Unity.csproj
浏览文件 @
48857e7e
...
...
@@ -424,6 +424,7 @@
<Compile
Include=
"Assets\Scripts\BehaviorTree\NodePropAttribute.cs"
/>
<Compile
Include=
"Assets\Scripts\BehaviorTree\NodeProto.cs"
/>
<Compile
Include=
"Assets\Scripts\BehaviorTree\TypeHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\BehaviorTreeComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Config\ClientConfig.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Config\InnerConfig.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\Config\OuterConfig.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录