2025-03-14 16:53:25 +08:00
|
|
|
|
#if DISABLE_DEBUG
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
#endif
|
|
|
|
|
|
using DCFApixels.DragonECS.RunnersCore;
|
2023-06-18 00:41:44 +08:00
|
|
|
|
using System;
|
2023-03-30 06:03:05 +08:00
|
|
|
|
|
2023-04-23 17:55:01 +08:00
|
|
|
|
namespace DCFApixels.DragonECS
|
|
|
|
|
|
{
|
2023-12-20 23:16:57 +08:00
|
|
|
|
[MetaName(nameof(PreInit))]
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
|
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Init() is called. Before Init")]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_DE26527C92015AFDD4ECF4D81A4C946B")]
|
2024-02-22 22:16:03 +08:00
|
|
|
|
public interface IEcsPreInit : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void PreInit();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2023-12-20 23:16:57 +08:00
|
|
|
|
[MetaName(nameof(Init))]
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
|
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Init() is called. After PreInit")]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_CC45527C9201DF82DCAAAEF33072F9EF")]
|
2024-02-22 22:16:03 +08:00
|
|
|
|
public interface IEcsInit : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void Init();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2023-12-20 23:16:57 +08:00
|
|
|
|
[MetaName(nameof(Run))]
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
|
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Run() is called.")]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_9654527C9201BE75546322B9BB03C131")]
|
2024-02-22 22:16:03 +08:00
|
|
|
|
public interface IEcsRun : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void Run();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2025-03-10 13:00:30 +08:00
|
|
|
|
[MetaName(nameof(RunFinally))]
|
|
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
|
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
|
|
|
|
|
public interface IEcsRunFinally : IEcsProcess
|
|
|
|
|
|
{
|
|
|
|
|
|
void RunFinally();
|
|
|
|
|
|
}
|
2023-12-20 23:16:57 +08:00
|
|
|
|
[MetaName(nameof(Destroy))]
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
|
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Destroy() is called.")]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_4661527C9201EE669C6EB61B19899AE5")]
|
2024-02-22 22:16:03 +08:00
|
|
|
|
public interface IEcsDestroy : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void Destroy();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
}
|
2023-05-27 23:02:32 +08:00
|
|
|
|
|
2024-02-22 15:39:37 +08:00
|
|
|
|
namespace DCFApixels.DragonECS.Internal
|
|
|
|
|
|
{
|
2024-04-28 19:43:10 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
|
using Unity.IL2CPP.CompilerServices;
|
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
|
#endif
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
2024-06-11 02:30:00 +08:00
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "...")]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaTags(MetaTags.HIDDEN)]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_3273527C9201285BAA0A463F700A50FB")]
|
2024-02-23 18:34:40 +08:00
|
|
|
|
internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2024-10-31 14:54:16 +08:00
|
|
|
|
private RunHelper _helper;
|
2024-02-22 15:39:37 +08:00
|
|
|
|
protected override void OnSetup()
|
|
|
|
|
|
{
|
2024-10-31 15:27:53 +08:00
|
|
|
|
_helper = new RunHelper(this);
|
2024-02-22 15:39:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
public void PreInit()
|
|
|
|
|
|
{
|
2024-10-31 14:54:16 +08:00
|
|
|
|
_helper.Run(p => p.PreInit());
|
2024-02-22 15:39:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-28 19:43:10 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
|
#endif
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
2024-06-11 02:30:00 +08:00
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "...")]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaTags(MetaTags.HIDDEN)]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_ED85527C9201A391AB8EC0B734917859")]
|
2024-02-23 18:34:40 +08:00
|
|
|
|
internal sealed class EcsInitRunner : EcsRunner<IEcsInit>, IEcsInit
|
2024-02-22 15:39:37 +08:00
|
|
|
|
{
|
2024-10-31 14:54:16 +08:00
|
|
|
|
private RunHelper _helper;
|
2024-02-22 15:39:37 +08:00
|
|
|
|
protected override void OnSetup()
|
|
|
|
|
|
{
|
2024-10-31 15:27:53 +08:00
|
|
|
|
_helper = new RunHelper(this);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
public void Init()
|
2023-06-17 19:28:06 +08:00
|
|
|
|
{
|
2024-10-31 14:54:16 +08:00
|
|
|
|
_helper.Run(p => p.Init());
|
2024-02-22 15:39:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-28 19:43:10 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
|
#endif
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
2024-06-11 02:30:00 +08:00
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "...")]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaTags(MetaTags.HIDDEN)]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_2098527C9201F260C840BFD50BC7E0BA")]
|
2024-02-23 18:34:40 +08:00
|
|
|
|
internal sealed class EcsRunRunner : EcsRunner<IEcsRun>, IEcsRun
|
2024-02-22 15:39:37 +08:00
|
|
|
|
{
|
2025-03-10 13:00:30 +08:00
|
|
|
|
private readonly struct Pair
|
|
|
|
|
|
{
|
|
|
|
|
|
public readonly IEcsRun run;
|
|
|
|
|
|
public readonly IEcsRunFinally cleanup;
|
|
|
|
|
|
public Pair(IEcsRun run)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.run = run;
|
|
|
|
|
|
cleanup = run as IEcsRunFinally;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private Pair[] _pairs;
|
2025-03-14 16:53:25 +08:00
|
|
|
|
#if DEBUG
|
2024-02-22 15:39:37 +08:00
|
|
|
|
private EcsProfilerMarker[] _markers;
|
2025-03-10 13:00:30 +08:00
|
|
|
|
#endif
|
2024-02-22 15:39:37 +08:00
|
|
|
|
protected override void OnSetup()
|
|
|
|
|
|
{
|
2025-03-10 13:00:30 +08:00
|
|
|
|
_pairs = new Pair[Process.Length];
|
|
|
|
|
|
for (int i = 0; i < Process.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
_pairs[i] = new Pair(Process[i]);
|
|
|
|
|
|
}
|
2025-03-14 16:53:25 +08:00
|
|
|
|
#if DEBUG
|
2024-02-22 15:39:37 +08:00
|
|
|
|
_markers = new EcsProfilerMarker[Process.Length];
|
|
|
|
|
|
for (int i = 0; i < Process.Length; i++)
|
|
|
|
|
|
{
|
2024-03-13 01:53:23 +08:00
|
|
|
|
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(Run)}");
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
#endif
|
2025-03-10 13:00:30 +08:00
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
public void Run()
|
2023-06-17 19:28:06 +08:00
|
|
|
|
{
|
2025-03-14 16:53:25 +08:00
|
|
|
|
#if DEBUG
|
2025-03-10 13:00:30 +08:00
|
|
|
|
for (int i = 0, n = _pairs.Length < _markers.Length ? _pairs.Length : _markers.Length; i < n; i++)
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
2025-03-10 13:00:30 +08:00
|
|
|
|
var pair = _pairs[i];
|
2024-02-22 15:39:37 +08:00
|
|
|
|
_markers[i].Begin();
|
|
|
|
|
|
try
|
2023-04-23 18:05:27 +08:00
|
|
|
|
{
|
2025-03-10 13:00:30 +08:00
|
|
|
|
pair.run.Run();
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
catch (Exception e)
|
2023-04-23 18:05:27 +08:00
|
|
|
|
{
|
2025-03-15 15:00:07 +08:00
|
|
|
|
#if DRAGONECS_DISABLE_CATH_EXCEPTIONS
|
2025-03-29 15:55:26 +08:00
|
|
|
|
throw e;
|
|
|
|
|
|
#else
|
2024-02-22 15:39:37 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2025-03-29 15:55:26 +08:00
|
|
|
|
#endif
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2025-03-10 13:00:30 +08:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
pair.cleanup?.RunFinally();
|
|
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
_markers[i].End();
|
|
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#else
|
2024-02-22 15:39:37 +08:00
|
|
|
|
foreach (var item in Process)
|
|
|
|
|
|
{
|
|
|
|
|
|
try { item.Run(); }
|
|
|
|
|
|
catch (Exception e)
|
2023-06-17 19:28:06 +08:00
|
|
|
|
{
|
2025-03-15 15:00:07 +08:00
|
|
|
|
#if DRAGONECS_DISABLE_CATH_EXCEPTIONS
|
2025-03-15 16:20:50 +08:00
|
|
|
|
throw e;
|
|
|
|
|
|
#else
|
2024-02-22 15:39:37 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2025-03-15 16:20:50 +08:00
|
|
|
|
#endif
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2024-02-22 15:39:37 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#endif
|
2024-02-22 15:39:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-28 19:43:10 +08:00
|
|
|
|
#if ENABLE_IL2CPP
|
|
|
|
|
|
[Il2CppSetOption(Option.NullChecks, false)]
|
|
|
|
|
|
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
|
|
|
|
|
#endif
|
2024-05-01 13:38:08 +08:00
|
|
|
|
[MetaColor(MetaColor.DragonRose)]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
|
2024-06-11 02:30:00 +08:00
|
|
|
|
[MetaDescription(EcsConsts.AUTHOR, "...")]
|
2024-06-13 18:04:18 +08:00
|
|
|
|
[MetaTags(MetaTags.HIDDEN)]
|
2025-03-19 16:30:20 +08:00
|
|
|
|
[MetaID("DragonECS_06A6527C92010430ACEB3DA520F272CC")]
|
2024-02-23 18:34:40 +08:00
|
|
|
|
internal sealed class EcsDestroyRunner : EcsRunner<IEcsDestroy>, IEcsDestroy
|
2024-02-22 15:39:37 +08:00
|
|
|
|
{
|
2024-10-31 14:54:16 +08:00
|
|
|
|
private RunHelper _helper;
|
2024-02-22 15:39:37 +08:00
|
|
|
|
protected override void OnSetup()
|
|
|
|
|
|
{
|
2024-10-31 15:27:53 +08:00
|
|
|
|
_helper = new RunHelper(this);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2024-02-23 18:34:40 +08:00
|
|
|
|
public void Destroy()
|
2023-06-17 19:28:06 +08:00
|
|
|
|
{
|
2024-10-31 14:54:16 +08:00
|
|
|
|
_helper.Run(p => p.Destroy());
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2024-10-31 14:54:16 +08:00
|
|
|
|
}
|