@@ -40,12 +40,25 @@ static ActorManager()
40
40
/// 根据ActorId获取对应的IComponentAgent对象
41
41
/// </summary>
42
42
/// <param name="actorId">ActorId</param>
43
+ /// <param name="isNew">是否当获取为空的时候默认创建,默认值为true</param>
43
44
/// <typeparam name="T">组件代理类型</typeparam>
44
45
/// <returns>组件代理任务</returns>
45
- public static async Task < T > GetComponentAgent < T > ( long actorId ) where T : IComponentAgent
46
+ public static async Task < T > GetComponentAgent < T > ( long actorId , bool isNew = true ) where T : IComponentAgent
46
47
{
47
- var actor = await GetOrNew ( actorId ) ;
48
- return await actor . GetComponentAgent < T > ( ) ;
48
+ Actor actor ;
49
+ if ( isNew )
50
+ {
51
+ actor = await GetOrNew ( actorId ) ;
52
+ return await actor . GetComponentAgent < T > ( ) ;
53
+ }
54
+
55
+ actor = Get ( actorId ) ;
56
+ if ( actor != null )
57
+ {
58
+ return await actor . GetComponentAgent < T > ( ) ;
59
+ }
60
+
61
+ return await Task . FromResult < T > ( default ) ;
49
62
}
50
63
51
64
/// <summary>
@@ -74,24 +87,38 @@ internal static Actor GetActor(long actorId)
74
87
/// </summary>
75
88
/// <param name="actorId">ActorId</param>
76
89
/// <param name="agentType">组件类型</param>
90
+ /// <param name="isNew">是否当获取为空的时候默认创建,默认值为true</param>
77
91
/// <returns>组件代理任务</returns>
78
- internal static async Task < IComponentAgent > GetComponentAgent ( long actorId , Type agentType )
92
+ internal static async Task < IComponentAgent > GetComponentAgent ( long actorId , Type agentType , bool isNew = true )
79
93
{
80
- var actor = await GetOrNew ( actorId ) ;
81
- return await actor . GetComponentAgent ( agentType ) ;
94
+ Actor actor ;
95
+ if ( isNew )
96
+ {
97
+ actor = await GetOrNew ( actorId ) ;
98
+ return await actor . GetComponentAgent ( agentType ) ;
99
+ }
100
+
101
+ actor = Get ( actorId ) ;
102
+ if ( actor != null )
103
+ {
104
+ return await actor . GetComponentAgent ( agentType ) ;
105
+ }
106
+
107
+ return await Task . FromResult < IComponentAgent > ( default ) ;
82
108
}
83
109
84
110
/// <summary>
85
111
/// 根据组件类型获取对应的IComponentAgent数据
86
112
/// </summary>
87
113
/// <typeparam name="T">组件代理类型</typeparam>
114
+ /// <param name="isNew">是否当获取为空的时候默认创建,默认值为true</param>
88
115
/// <returns>组件代理任务</returns>
89
- public static Task < T > GetComponentAgent < T > ( ) where T : IComponentAgent
116
+ public static Task < T > GetComponentAgent < T > ( bool isNew = true ) where T : IComponentAgent
90
117
{
91
118
var compType = HotfixManager . GetCompType ( typeof ( T ) ) ;
92
119
var actorType = ComponentRegister . GetActorType ( compType ) ;
93
120
var actorId = ActorIdGenerator . GetActorId ( actorType ) ;
94
- return GetComponentAgent < T > ( actorId ) ;
121
+ return GetComponentAgent < T > ( actorId , isNew ) ;
95
122
}
96
123
97
124
/// <summary>
@@ -123,6 +150,34 @@ internal static async Task<Actor> GetOrNew(long actorId)
123
150
return ActorMap . GetOrAdd ( actorId , k => new Actor ( k , ActorIdGenerator . GetActorType ( k ) ) ) ;
124
151
}
125
152
153
+ /// <summary>
154
+ /// 根据actorId获取对应的actor实例,不存在则返回空
155
+ /// </summary>
156
+ /// <param name="actorId">actorId</param>
157
+ /// <returns>Actor对象任务</returns>
158
+ private static Actor Get ( long actorId )
159
+ {
160
+ var actorType = ActorIdGenerator . GetActorType ( actorId ) ;
161
+ Actor valueActor ;
162
+ if ( actorType < GlobalConst . ActorTypeSeparator )
163
+ {
164
+ var now = DateTime . Now ;
165
+ if ( ActiveTimeDic . TryGetValue ( actorId , out var activeTime )
166
+ && ( now - activeTime ) . TotalMinutes < 10
167
+ && ActorMap . TryGetValue ( actorId , out var actor ) )
168
+ {
169
+ ActiveTimeDic [ actorId ] = now ;
170
+ return actor ;
171
+ }
172
+
173
+ ActorMap . TryGetValue ( actorId , out valueActor ) ;
174
+ return valueActor ;
175
+ }
176
+
177
+ ActorMap . TryGetValue ( actorId , out valueActor ) ;
178
+ return valueActor ;
179
+ }
180
+
126
181
/// <summary>
127
182
/// 全部完成
128
183
/// </summary>
0 commit comments