Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
4515a5e3
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,发现更多精彩内容 >>
提交
4515a5e3
编写于
11月 07, 2016
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
简化对象事件系统
上级
a0c38233
变更
16
显示空白变更内容
内联
并排
Showing
16 changed file
with
74 addition
and
151 deletion
+74
-151
Server/App/Program.cs
Server/App/Program.cs
+3
-4
Server/Controller/Message/M2A_ReloadHandler.cs
Server/Controller/Message/M2A_ReloadHandler.cs
+1
-2
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+0
-3
Unity/Assets/Editor/EditorInit.cs
Unity/Assets/Editor/EditorInit.cs
+3
-4
Unity/Assets/Editor/ObjectManagerToolsEditor/ObjectManagerToolsWindow.cs
...itor/ObjectManagerToolsEditor/ObjectManagerToolsWindow.cs
+2
-3
Unity/Assets/Scripts/Component/ConfigComponent.cs
Unity/Assets/Scripts/Component/ConfigComponent.cs
+1
-3
Unity/Assets/Scripts/Component/EventComponent.cs
Unity/Assets/Scripts/Component/EventComponent.cs
+1
-2
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
+1
-1
Unity/Assets/Scripts/Init.cs
Unity/Assets/Scripts/Init.cs
+3
-3
Unity/Assets/Scripts/Object/Component.cs
Unity/Assets/Scripts/Object/Component.cs
+0
-3
Unity/Assets/Scripts/Object/Entity.cs
Unity/Assets/Scripts/Object/Entity.cs
+5
-5
Unity/Assets/Scripts/Object/IStart.cs
Unity/Assets/Scripts/Object/IStart.cs
+0
-10
Unity/Assets/Scripts/Object/IStart.cs.meta
Unity/Assets/Scripts/Object/IStart.cs.meta
+0
-12
Unity/Assets/Scripts/Object/Object.cs
Unity/Assets/Scripts/Object/Object.cs
+3
-6
Unity/Assets/Scripts/Object/ObjectManager.cs
Unity/Assets/Scripts/Object/ObjectManager.cs
+51
-89
Unity/Unity.CSharp.csproj
Unity/Unity.CSharp.csproj
+0
-1
未找到文件。
Server/App/Program.cs
浏览文件 @
4515a5e3
...
...
@@ -2,7 +2,6 @@
using
Base
;
using
Model
;
using
NLog
;
using
Object
=
Model
.
Object
;
namespace
App
{
...
...
@@ -12,8 +11,8 @@ namespace App
{
try
{
Object
.
ObjectManager
.
Register
(
"Model"
,
typeof
(
Game
).
Assembly
);
Object
.
ObjectManager
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
Object
Manager
.
Instance
.
Register
(
"Model"
,
typeof
(
Game
).
Assembly
);
Object
Manager
.
Instance
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
StartConfig
startConfig
=
Game
.
Scene
.
AddComponent
<
StartConfigComponent
,
string
[
]>
(
args
).
MyConfig
;
...
...
@@ -67,7 +66,7 @@ namespace App
while
(
true
)
{
Object
.
ObjectManager
.
Update
();
Object
Manager
.
Instance
.
Update
();
}
}
catch
(
Exception
e
)
...
...
Server/Controller/Message/M2A_ReloadHandler.cs
浏览文件 @
4515a5e3
using
System
;
using
Base
;
using
Model
;
using
Object
=
Model
.
Object
;
namespace
Controller
{
...
...
@@ -13,7 +12,7 @@ namespace Controller
A2M_Reload
a2MReload
=
new
A2M_Reload
();
try
{
Object
.
ObjectManager
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
Object
Manager
.
Instance
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
}
catch
(
Exception
e
)
{
...
...
Server/Model/Server.Model.csproj
浏览文件 @
4515a5e3
...
...
@@ -173,9 +173,6 @@
<Compile
Include=
"..\..\Unity\Assets\Scripts\Object\ILoader.cs"
>
<Link>
Object\ILoader.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Scripts\Object\IStart.cs"
>
<Link>
Object\IStart.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Scripts\Object\IUpdate.cs"
>
<Link>
Object\IUpdate.cs
</Link>
</Compile>
...
...
Unity/Assets/Editor/EditorInit.cs
浏览文件 @
4515a5e3
...
...
@@ -3,7 +3,6 @@ using Base;
using
UnityEditor
;
using
UnityEngine
;
using
Model
;
using
Object
=
Model
.
Object
;
namespace
MyEditor
{
...
...
@@ -12,6 +11,7 @@ namespace MyEditor
{
static
EditorInit
()
{
ObjectManager
.
Instance
.
Register
(
"Editor"
,
typeof
(
EditorInit
).
Assembly
);
EditorApplication
.
update
+=
Update
;
}
...
...
@@ -24,12 +24,11 @@ namespace MyEditor
try
{
Object
.
ObjectManager
.
Update
();
Object
Manager
.
Instance
.
Update
();
}
catch
(
Exception
e
)
{
Object
.
ObjectManager
.
Dispose
();
Object
.
ObjectManager
=
new
ObjectManager
();
ObjectManager
.
Reset
();
Log
.
Error
(
e
.
ToString
());
}
}
...
...
Unity/Assets/Editor/ObjectManagerToolsEditor/ObjectManagerToolsWindow.cs
浏览文件 @
4515a5e3
...
...
@@ -7,14 +7,13 @@ public class ObjectManagerToolsWindow : EditorWindow
[
MenuItem
(
"Tools/ObjectManagerTools/显示未Dispose的对象"
)]
private
static
void
ShowUnDisposeObjects
()
{
Log
.
Info
(
Object
.
ObjectManager
.
ToString
());
Log
.
Info
(
Object
Manager
.
Instance
.
ToString
());
}
[
MenuItem
(
"Tools/ObjectManagerTools/清除所有对象"
)]
private
static
void
ClearAllObjects
()
{
Object
.
ObjectManager
.
Dispose
();
Object
.
ObjectManager
=
new
ObjectManager
();
ObjectManager
.
Reset
();
}
}
\ No newline at end of file
Unity/Assets/Scripts/Component/ConfigComponent.cs
浏览文件 @
4515a5e3
using
System
;
using
System.Collections.Generic
;
using
System.Reflection
;
using
Base
;
using
Object
=
Model
.
Object
;
namespace
Model
{
...
...
@@ -12,7 +10,7 @@ namespace Model
public
void
Load
()
{
Assembly
assembly
=
Object
.
ObjectManager
.
GetAssembly
(
"Base"
);
Assembly
assembly
=
Object
Manager
.
Instance
.
GetAssembly
(
"Base"
);
this
.
allConfig
=
new
Dictionary
<
Type
,
ICategory
>();
Type
[]
types
=
assembly
.
GetTypes
();
...
...
Unity/Assets/Scripts/Component/EventComponent.cs
浏览文件 @
4515a5e3
...
...
@@ -2,7 +2,6 @@
using
System.Collections.Generic
;
using
System.Reflection
;
using
Base
;
using
Object
=
Model
.
Object
;
namespace
Model
{
...
...
@@ -30,7 +29,7 @@ namespace Model
public
void
Load
()
{
this
.
allEvents
=
new
Dictionary
<
EventIdType
,
List
<
object
>>();
Assembly
[]
assemblies
=
Object
.
ObjectManager
.
GetAssemblies
();
Assembly
[]
assemblies
=
Object
Manager
.
Instance
.
GetAssemblies
();
foreach
(
Assembly
assembly
in
assemblies
)
{
Type
[]
types
=
assembly
.
GetTypes
();
...
...
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
浏览文件 @
4515a5e3
...
...
@@ -40,7 +40,7 @@ namespace Model
this
.
handlers
=
new
Dictionary
<
ushort
,
List
<
IMHandler
>>();
this
.
messageOpcode
=
new
Dictionary
<
Type
,
MessageAttribute
>();
Assembly
[]
assemblies
=
Object
.
ObjectManager
.
GetAssemblies
();
Assembly
[]
assemblies
=
Object
Manager
.
Instance
.
GetAssemblies
();
foreach
(
Assembly
assembly
in
assemblies
)
{
...
...
Unity/Assets/Scripts/Init.cs
浏览文件 @
4515a5e3
...
...
@@ -8,8 +8,8 @@ namespace Model
{
private
void
Start
()
{
Object
.
ObjectManager
.
Register
(
"Model"
,
typeof
(
Game
).
Assembly
);
Object
.
ObjectManager
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
Object
Manager
.
Instance
.
Register
(
"Model"
,
typeof
(
Game
).
Assembly
);
Object
Manager
.
Instance
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
Game
.
Scene
.
AddComponent
<
EventComponent
>().
Run
(
EventIdType
.
InitSceneStart
);
}
...
...
@@ -18,7 +18,7 @@ namespace Model
{
try
{
Object
.
ObjectManager
.
Update
();
Object
Manager
.
Instance
.
Update
();
}
catch
(
Exception
e
)
{
...
...
Unity/Assets/Scripts/Object/Component.cs
浏览文件 @
4515a5e3
...
...
@@ -2,9 +2,6 @@
namespace
Model
{
/// <summary>
/// Component的Id与Owner Entity Id一样
/// </summary>
[
BsonKnownTypes
(
typeof
(
AConfigComponent
))]
public
abstract
class
Component
:
Object
{
...
...
Unity/Assets/Scripts/Object/Entity.cs
浏览文件 @
4515a5e3
...
...
@@ -66,7 +66,7 @@ namespace Model
this
.
components
.
Add
(
component
);
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
ObjectManager
.
Awake
(
component
.
Id
);
ObjectManager
.
Instance
.
Awake
(
component
);
return
component
;
}
...
...
@@ -87,7 +87,7 @@ namespace Model
this
.
components
.
Add
(
component
);
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
ObjectManager
.
Awake
(
component
.
Id
,
p1
);
ObjectManager
.
Instance
.
Awake
(
component
,
p1
);
return
component
;
}
...
...
@@ -108,7 +108,7 @@ namespace Model
this
.
components
.
Add
(
component
);
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
ObjectManager
.
Awake
(
component
.
Id
,
p1
,
p2
);
ObjectManager
.
Instance
.
Awake
(
component
,
p1
,
p2
);
return
component
;
}
...
...
@@ -130,7 +130,7 @@ namespace Model
this
.
components
.
Add
(
component
);
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
ObjectManager
.
Awake
(
component
.
Id
,
p1
,
p2
,
p3
);
ObjectManager
.
Instance
.
Awake
(
component
,
p1
,
p2
,
p3
);
return
component
;
}
...
...
@@ -147,7 +147,7 @@ namespace Model
}
this
.
components
.
Add
(
component
);
this
.
componentDict
.
Add
(
component
.
GetType
(),
component
);
ObjectManager
.
Awake
(
component
.
Id
);
ObjectManager
.
Instance
.
Awake
(
component
);
}
public
void
RemoveComponent
<
K
>()
where
K
:
Component
...
...
Unity/Assets/Scripts/Object/IStart.cs
已删除
100644 → 0
浏览文件 @
a0c38233
namespace
Model
{
/// <summary>
/// World的Componet实现该接口后,会在World.Start时调用该Start方法
/// </summary>
public
interface
IStart
{
void
Start
();
}
}
\ No newline at end of file
Unity/Assets/Scripts/Object/IStart.cs.meta
已删除
100644 → 0
浏览文件 @
a0c38233
fileFormatVersion: 2
guid: ee0b99021f2abfb408ca33f2f551a1d8
timeCreated: 1474942922
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Object/Object.cs
浏览文件 @
4515a5e3
...
...
@@ -7,22 +7,19 @@ namespace Model
{
public
abstract
class
Object
:
IDisposable
,
ISupportInitialize
{
[
BsonIgnore
]
public
static
ObjectManager
ObjectManager
=
new
ObjectManager
();
[
BsonId
]
public
long
Id
{
get
;
private
set
;
}
protected
Object
()
{
Id
=
IdGenerater
.
GenerateId
();
ObjectManager
.
Add
(
this
);
ObjectManager
.
Instance
.
Add
(
this
);
}
protected
Object
(
long
id
)
{
this
.
Id
=
id
;
ObjectManager
.
Add
(
this
);
ObjectManager
.
Instance
.
Add
(
this
);
}
public
virtual
void
Dispose
()
...
...
@@ -32,7 +29,7 @@ namespace Model
return
;
}
ObjectManager
.
Remove
(
this
.
Id
);
ObjectManager
.
Instance
.
Remove
(
this
);
this
.
Id
=
0
;
}
...
...
Unity/Assets/Scripts/Object/ObjectManager.cs
浏览文件 @
4515a5e3
...
...
@@ -39,19 +39,33 @@ namespace Model
private
Dictionary
<
Type
,
IObjectEvent
>
objectEvents
;
private
readonly
Dictionary
<
long
,
Object
>
objects
=
new
Dictionary
<
long
,
Object
>();
private
readonly
HashSet
<
Object
>
objects
=
new
HashSet
<
Object
>();
private
readonly
HashSet
<
Object
>
updates
=
new
HashSet
<
Object
>();
private
readonly
HashSet
<
Object
>
loaders
=
new
HashSet
<
Object
>();
private
List
<
long
>
starts
=
new
List
<
long
>();
private
List
<
long
>
newStarts
=
new
List
<
long
>();
private
static
ObjectManager
instance
=
new
ObjectManager
();
private
List
<
long
>
updates
=
new
List
<
long
>(
3000
);
private
List
<
long
>
newUpdates
=
new
List
<
long
>(
3000
);
public
static
ObjectManager
Instance
{
get
{
return
instance
;
}
}
private
readonly
List
<
long
>
loaders
=
new
List
<
long
>();
private
ObjectManager
()
{
}
public
static
void
Reset
()
{
instance
.
Dispose
();
instance
=
new
ObjectManager
();
}
public
void
Dispose
()
{
foreach
(
Object
o
in
this
.
objects
.
Values
.
ToArray
())
foreach
(
Object
o
in
this
.
objects
.
ToArray
())
{
o
.
Dispose
();
}
...
...
@@ -99,13 +113,8 @@ namespace Model
private
void
Load
()
{
foreach
(
long
id
in
this
.
loaders
)
{
Object
obj
;
if
(!
this
.
objects
.
TryGetValue
(
id
,
out
obj
))
foreach
(
Object
obj
in
this
.
loaders
)
{
continue
;
}
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
...
...
@@ -128,44 +137,51 @@ namespace Model
return
;
}
this
.
objects
.
Add
(
obj
.
Id
,
obj
);
this
.
objects
.
Add
(
obj
);
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
return
;
}
IStart
iStart
=
objectEvent
as
IStart
;
if
(
iStart
!=
null
)
{
this
.
newStarts
.
Add
(
obj
.
Id
);
}
IUpdate
iUpdate
=
objectEvent
as
IUpdate
;
if
(
iUpdate
!=
null
)
{
this
.
newUpdates
.
Add
(
obj
.
Id
);
this
.
updates
.
Add
(
obj
);
}
ILoader
iLoader
=
objectEvent
as
ILoader
;
if
(
iLoader
!=
null
)
{
this
.
loaders
.
Add
(
obj
.
Id
);
this
.
loaders
.
Add
(
obj
);
}
}
public
void
Remove
(
long
id
)
public
void
Remove
(
Object
obj
)
{
this
.
objects
.
Remove
(
id
);
this
.
objects
.
Remove
(
obj
);
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
return
;
}
public
void
Awake
(
long
id
)
IUpdate
iUpdate
=
objectEvent
as
IUpdate
;
if
(
iUpdate
!=
null
)
{
Object
obj
;
if
(!
objects
.
TryGetValue
(
id
,
out
obj
))
this
.
updates
.
Remove
(
obj
);
}
ILoader
iLoader
=
objectEvent
as
ILoader
;
if
(
iLoader
!=
null
)
{
return
;
this
.
loaders
.
Remove
(
obj
)
;
}
}
public
void
Awake
(
Object
obj
)
{
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
...
...
@@ -180,13 +196,8 @@ namespace Model
iAwake
.
Awake
();
}
public
void
Awake
<
P1
>(
long
id
,
P1
p1
)
public
void
Awake
<
P1
>(
Object
obj
,
P1
p1
)
{
Object
obj
;
if
(!
objects
.
TryGetValue
(
id
,
out
obj
))
{
return
;
}
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
...
...
@@ -201,13 +212,8 @@ namespace Model
iAwake
.
Awake
(
p1
);
}
public
void
Awake
<
P1
,
P2
>(
long
id
,
P1
p1
,
P2
p2
)
{
Object
obj
;
if
(!
objects
.
TryGetValue
(
id
,
out
obj
))
public
void
Awake
<
P1
,
P2
>(
Object
obj
,
P1
p1
,
P2
p2
)
{
return
;
}
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
...
...
@@ -222,13 +228,8 @@ namespace Model
iAwake
.
Awake
(
p1
,
p2
);
}
public
void
Awake
<
P1
,
P2
,
P3
>(
long
id
,
P1
p1
,
P2
p2
,
P3
p3
)
public
void
Awake
<
P1
,
P2
,
P3
>(
Object
obj
,
P1
p1
,
P2
p2
,
P3
p3
)
{
Object
obj
;
if
(!
objects
.
TryGetValue
(
id
,
out
obj
))
{
return
;
}
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
...
...
@@ -243,48 +244,10 @@ namespace Model
iAwake
.
Awake
(
p1
,
p2
,
p3
);
}
private
void
Start
()
{
starts
=
newStarts
;
newStarts
=
new
List
<
long
>();
foreach
(
long
id
in
starts
)
{
Object
obj
;
if
(!
this
.
objects
.
TryGetValue
(
id
,
out
obj
))
{
continue
;
}
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
continue
;
}
IStart
iStart
=
objectEvent
as
IStart
;
if
(
iStart
==
null
)
{
continue
;
}
objectEvent
.
SetValue
(
obj
);
iStart
.
Start
();
}
}
public
void
Update
()
{
this
.
Start
();
// 交换update
List
<
long
>
tmpUpdate
=
updates
;
updates
=
newUpdates
;
newUpdates
=
tmpUpdate
;
newUpdates
.
Clear
();
foreach
(
long
id
in
updates
)
foreach
(
Object
obj
in
updates
)
{
Object
obj
;
if
(!
objects
.
TryGetValue
(
id
,
out
obj
))
{
continue
;
}
IObjectEvent
objectEvent
;
if
(!
objectEvents
.
TryGetValue
(
obj
.
GetType
(),
out
objectEvent
))
{
...
...
@@ -295,7 +258,6 @@ namespace Model
{
continue
;
}
newUpdates
.
Add
(
id
);
objectEvent
.
SetValue
(
obj
);
try
{
...
...
@@ -311,7 +273,7 @@ namespace Model
public
override
string
ToString
()
{
var
info
=
new
Dictionary
<
string
,
int
>();
foreach
(
Object
obj
in
objects
.
Values
)
foreach
(
Object
obj
in
objects
)
{
if
(
info
.
ContainsKey
(
obj
.
GetType
().
Name
))
{
...
...
@@ -330,7 +292,7 @@ namespace Model
sb
.
Append
(
$"
{
info
[
key
],
10
}
{
key
}
\r\n"
);
}
sb
.
Append
(
$"\r\n
start:
{
newStarts
.
Count
}
, update:
{
newU
pdates
.
Count
}
total:
{
this
.
objects
.
Count
}
"
);
sb
.
Append
(
$"\r\n
update:
{
this
.
u
pdates
.
Count
}
total:
{
this
.
objects
.
Count
}
"
);
return
sb
.
ToString
();
}
}
...
...
Unity/Unity.CSharp.csproj
浏览文件 @
4515a5e3
...
...
@@ -130,7 +130,6 @@
<Compile
Include=
"Assets\Scripts\Object\Entity.cs"
/>
<Compile
Include=
"Assets\Scripts\Object\IAwake.cs"
/>
<Compile
Include=
"Assets\Scripts\Object\ILoader.cs"
/>
<Compile
Include=
"Assets\Scripts\Object\IStart.cs"
/>
<Compile
Include=
"Assets\Scripts\Object\IUpdate.cs"
/>
<Compile
Include=
"Assets\Scripts\Object\Object.cs"
/>
<Compile
Include=
"Assets\Scripts\Object\ObjectEventAttribute.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录