mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(ArchEcsModule): 优化系统适配器管理
- 将 _systems 字段类型从 List 改为 IReadOnlyList - 使用 GetAllByPriority 方法按优先级获取适配器 - 移除手动 AddRange 操作,直接赋值适配器列表 - 销毁时将 _systems 设置为空数组而非 Clear() 操作
This commit is contained in:
parent
4257d58f86
commit
ac2a9759e1
@ -8,9 +8,9 @@ namespace GFramework.Ecs.Arch;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ArchEcsModule : IArchEcsModule
|
public sealed class ArchEcsModule : IArchEcsModule
|
||||||
{
|
{
|
||||||
private readonly List<ArchSystemAdapter<float>> _systems = [];
|
|
||||||
private IIocContainer? _container;
|
private IIocContainer? _container;
|
||||||
private bool _isInitialized;
|
private bool _isInitialized;
|
||||||
|
private IReadOnlyList<ArchSystemAdapter<float>> _systems = [];
|
||||||
private World? _world;
|
private World? _world;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -67,17 +67,13 @@ public sealed class ArchEcsModule : IArchEcsModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从容器获取所有适配器
|
// 从容器按优先级获取所有适配器
|
||||||
var adapters = _container.GetAll<ArchSystemAdapter<float>>();
|
_systems = _container.GetAllByPriority<ArchSystemAdapter<float>>();
|
||||||
if (adapters.Count > 0)
|
|
||||||
{
|
|
||||||
_systems.AddRange(adapters);
|
|
||||||
|
|
||||||
// 初始化所有系统(会调用 Arch 系统的 Initialize)
|
// 初始化所有系统(会调用 Arch 系统的 Initialize)
|
||||||
foreach (var system in _systems)
|
foreach (var system in _systems)
|
||||||
{
|
{
|
||||||
system.Initialize();
|
system.Initialize();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_isInitialized = true;
|
_isInitialized = true;
|
||||||
@ -99,7 +95,7 @@ public sealed class ArchEcsModule : IArchEcsModule
|
|||||||
system.Destroy();
|
system.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
_systems.Clear();
|
_systems = [];
|
||||||
|
|
||||||
// 销毁 World
|
// 销毁 World
|
||||||
if (_world != null)
|
if (_world != null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user