Skip to content

Commit 6d6bfaa

Browse files
committed
[增加]1. 增加资源释放的接口
1 parent 6128c3f commit 6d6bfaa

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

GameFrameX.Core/Abstractions/IActor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,14 @@ public interface IActor : IWorker
128128
/// 如果键不存在,则不会产生任何效果。
129129
/// </remarks>
130130
bool RemoveData(string key);
131+
132+
/// <summary>
133+
/// 清除Actor中存储的所有数据
134+
/// </summary>
135+
/// <remarks>
136+
/// 该方法会清空Actor中所有通过SetData方法存储的数据。
137+
/// 清除后所有数据将无法恢复,请谨慎使用。
138+
/// 通常在Actor被回收或重置时调用此方法。
139+
/// </remarks>
140+
void ClearData();
131141
}

GameFrameX.Core/Actors/Actor.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace GameFrameX.Core.Actors;
1212
/// <summary>
1313
/// Actor类,用于管理和协调组件的生命周期、消息传递等核心功能
1414
/// </summary>
15-
public sealed class Actor : IActor
15+
public sealed class Actor : IActor, IDisposable
1616
{
1717
/// <summary>
1818
/// 默认超时时长,使用int最大值表示无限等待
@@ -279,6 +279,19 @@ public bool RemoveData(string key)
279279
return _data.TryRemove(key, out _);
280280
}
281281

282+
/// <summary>
283+
/// 清除Actor中存储的所有数据
284+
/// </summary>
285+
/// <remarks>
286+
/// 该方法会清空Actor中所有通过SetData方法存储的数据。
287+
/// 清除后所有数据将无法恢复,请谨慎使用。
288+
/// 通常在Actor被回收或重置时调用此方法。
289+
/// </remarks>
290+
public void ClearData()
291+
{
292+
_data.Clear();
293+
}
294+
282295
/// <summary>
283296
/// 反激活所有组件,使其进入非活动状态
284297
/// </summary>
@@ -429,4 +442,13 @@ public Task<T> SendAsync<T>(Func<Task<T>> work, int timeout = TimeOut, Cancellat
429442
}
430443

431444
#endregion
445+
446+
/// <summary>
447+
/// 释放资源
448+
/// </summary>
449+
public void Dispose()
450+
{
451+
ClearAgent();
452+
ClearData();
453+
}
432454
}

0 commit comments

Comments
 (0)