DragonECS-Unity/src/Templates/Startup.cs.txt
2023-03-30 05:40:48 +08:00

66 lines
1.6 KiB
Plaintext

using UnityEngine;
using DCFApixels.DragonECS;
namespace #NAMESPACE#
{
sealed class #SCRIPTNAME# : MonoBehaviour
{
private EcsDefaultWrold _world;
private EcsPipeline _pipeline;
private void Start()
{
// is needed to integrate the internal debugging tool with the unity environment
UnityDebugService.Init();
_world = new EcsDefaultWrold();
_pipeline = EcsPipeline.New()
// register your systems here, for example:
// .Add (new TestSystem1 ())
// .Add (new TestSystem2 ())
// inject worlds here, for example:
.Inject(_world)
//.Inject(new EcsWorld<EventWorld>())
// with Inject you can also inject other data, for example:
//.Inject(new SharedData())
#if UNITY_EDITOR
// add debug system for this EcsPipeline here
.Add(new PipelineDebugSystem())
#endif
.BuildAndInit();
}
private void Update()
{
_pipeline?.Run();
}
private void LateUpdate()
{
_pipeline?.LateRun();
}
private void FixedUpdate()
{
_pipeline?.FixedRun();
}
private void OnDestroy()
{
// don't forget to clear data
if (_pipeline != null)
{
_pipeline.Destroy();
_pipeline = null;
}
if (_world != null)
{
_world.Destroy();
_world = null;
}
}
}
}