mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
fixes
This commit is contained in:
parent
25fc3318d0
commit
73090da11a
@ -10,7 +10,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
public void Inject(T obj);
|
||||
}
|
||||
public class InjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
|
||||
public sealed class InjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
|
||||
{
|
||||
void IEcsInject<T>.Inject(T obj)
|
||||
{
|
||||
|
@ -40,23 +40,30 @@ namespace DCFApixels.DragonECS
|
||||
private int _id;
|
||||
|
||||
|
||||
private List<IEcsProcessor> _allSystems;
|
||||
private readonly List<IEcsProcessor> _allSystems;
|
||||
private ReadOnlyCollection<IEcsProcessor> _allSystemsSealed;
|
||||
|
||||
private bool _isInit = false;
|
||||
private bool _isDestoryed = false;
|
||||
|
||||
|
||||
private Dictionary<Type, IEcsRunner> _runners;
|
||||
private readonly Dictionary<Type, IEcsRunner> _runners;
|
||||
private IEcsRunSystem _runRunnerCache;
|
||||
|
||||
private EcsWorldMap _worldMap = new EcsWorldMap();
|
||||
private readonly EcsWorldMap _worldMap;
|
||||
|
||||
#region Properties
|
||||
public ReadOnlyCollection<IEcsProcessor> AllProcessors => _allSystemsSealed;
|
||||
|
||||
#endregion
|
||||
|
||||
public EcsSession()
|
||||
{
|
||||
_allSystems = new List<IEcsProcessor>(128);
|
||||
_runners = new Dictionary<Type, IEcsRunner>();
|
||||
_worldMap = new EcsWorldMap();
|
||||
}
|
||||
|
||||
#region React Runners/Messengers
|
||||
public T GetRunner<T>() where T : IEcsProcessor
|
||||
{
|
||||
@ -89,7 +96,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region LifeCycle
|
||||
public void Init()
|
||||
public EcsSession Init()
|
||||
{
|
||||
CheckInitForMethod(nameof(Init));
|
||||
_worldMap.Build();
|
||||
@ -102,6 +109,8 @@ namespace DCFApixels.DragonECS
|
||||
GetRunner<IEcsInitSystem>().Init(this);
|
||||
|
||||
_runRunnerCache = GetRunner<IEcsRunSystem>();
|
||||
|
||||
return this;
|
||||
}
|
||||
public void Run()
|
||||
{
|
||||
@ -111,7 +120,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public void Destroy()
|
||||
{
|
||||
CheckDestroyForMethod(nameof(Run));
|
||||
CheckDestroyForMethod(nameof(Destroy));
|
||||
_isDestoryed = true;
|
||||
|
||||
GetRunner<IEcsDestroySystem>().Destroy(this);
|
||||
@ -126,7 +135,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
private void CheckDestroyForMethod(string methodName)
|
||||
{
|
||||
if (_isInit)
|
||||
if (_isDestoryed)
|
||||
throw new MethodAccessException($"Запрещено вызывать метод {methodName}, после уничтожения {nameof(EcsSession)}");
|
||||
}
|
||||
#endregion
|
||||
|
@ -59,7 +59,7 @@ namespace DCFApixels.DragonECS
|
||||
_runnerTypes = new Dictionary<Guid, Type>();
|
||||
foreach (var item in newRunnerTypes)
|
||||
{
|
||||
Type intrf = item.GetInterfaces()[2]; //TODO доработать это место. Во-первых убрать магическое число 2, во-вторых сделать так чтоб брался только наследованный интерфейс, а не все
|
||||
Type intrf = item.GetInterfaces().Where(o => o != typeof(IEcsRunner) && o != typeof(IEcsProcessor)).First(); //TODO оптимизировать это место
|
||||
_runnerTypes.Add(intrf.GUID, item);
|
||||
}
|
||||
|
||||
@ -87,7 +87,12 @@ namespace DCFApixels.DragonECS
|
||||
public static void InitFor<TInterface>() where TInterface : IEcsProcessor
|
||||
{
|
||||
Type interfaceType = typeof(TInterface);
|
||||
Guid interfaceGuid = interfaceType.GUID;
|
||||
Type nonGenericInterfaceType = interfaceType;
|
||||
if (nonGenericInterfaceType.IsGenericType)
|
||||
{
|
||||
nonGenericInterfaceType = nonGenericInterfaceType.GetGenericTypeDefinition();
|
||||
}
|
||||
Guid interfaceGuid = nonGenericInterfaceType.GUID;
|
||||
|
||||
if (!_runnerTypes.TryGetValue(interfaceGuid, out Type runnerType))
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_ecsSession
|
||||
_ecsSession = new EcsSession()
|
||||
.Add(new TestSystem())
|
||||
.Inject(_data)
|
||||
.Init();
|
||||
|
@ -3,26 +3,26 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public class TestSystem :
|
||||
IEcsInject<SharedData>,
|
||||
IEcsSimpleCycleSystem
|
||||
public class TestSystem : IEcsInject<SharedData>, IEcsSimpleCycleSystem
|
||||
{
|
||||
private SharedData _sharedData;
|
||||
public void Inject(SharedData obj) => _sharedData = obj;
|
||||
|
||||
|
||||
|
||||
public void Init(EcsSession session)
|
||||
{
|
||||
Debug.Log("Init");
|
||||
}
|
||||
public void Run(EcsSession session)
|
||||
{
|
||||
Debug.Log("Run");
|
||||
}
|
||||
public void Destroy(EcsSession session)
|
||||
{
|
||||
Debug.Log("Destroy");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user