2023-05-28 19:41:33 +08:00
< p align = "center" >
2024-03-11 01:50:41 +08:00
< img width = "400" src = "https://github.com/DCFApixels/DragonECS-AutoInjections/assets/99481254/11868b2e-21f7-4f47-8970-03ad6329cf0e" >
2023-05-28 19:41:33 +08:00
< / p >
2023-05-29 04:07:37 +08:00
< p align = "center" >
< img alt = "Version" src = "https://img.shields.io/github/package-json/v/DCFApixels/DragonECS-AutoInjections?color=%23ff4e85&style=for-the-badge" >
2023-05-31 04:50:35 +08:00
< img alt = "License" src = "https://img.shields.io/github/license/DCFApixels/DragonECS-AutoInjections?color=ff4e85&style=for-the-badge" >
2024-06-16 01:10:11 +08:00
< a href = "https://discord.gg/kqmJjExuCf" > < img alt = "Discord" src = "https://img.shields.io/badge/Discord-JOIN-00b269?logo=discord&logoColor=%23ffffff&style=for-the-badge" > < / a >
< a href = "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=IbDcH43vhfArb30luGMP1TMXB3GCHzxm&authKey=s%2FJfqvv46PswFq68irnGhkLrMR6y9tf%2FUn2mogYizSOGiS%2BmB%2B8Ar9I%2Fnr%2Bs4oS%2B&noverify=0&group_code=949562781" > < img alt = "QQ" src = "https://img.shields.io/badge/QQ-JOIN-00b269?logo=tencentqq&logoColor=%23ffffff&style=for-the-badge" > < / a >
2023-05-29 04:07:37 +08:00
< / p >
2023-05-29 22:41:26 +08:00
# Auto Injections for [DragonECS](https://github.com/DCFApixels/DragonECS)
2023-05-28 20:45:07 +08:00
2023-05-31 04:20:54 +08:00
| Languages: | [Русский ](https://github.com/DCFApixels/DragonECS-AutoInjections/blob/main/README-RU.md ) | [English(WIP) ](https://github.com/DCFApixels/DragonECS-AutoInjections ) |
| :--- | :--- | :--- |
2023-05-28 20:45:07 +08:00
2023-05-31 04:20:54 +08:00
The extension is designed to reduce the amount of code by simplifying dependency injection by doing injections automatically.
> **NOTICE:** The project is a work in progress, API may change.
2023-06-12 15:08:11 +08:00
> While the English version of the README is incomplete, you can view the [Russian version](https://github.com/DCFApixels/DragonECS-AutoInjections/blob/main/README-RU.md).
2023-05-28 20:29:42 +08:00
2024-03-11 00:37:32 +08:00
< / br >
# Installation
Versioning semantics - [Open ](https://gist.github.com/DCFApixels/e53281d4628b19fe5278f3e77a7da9e8#file-dcfapixels_versioning_ru-md )
## Environment
Requirements:
+ Dependency: [DragonECS ](https://github.com/DCFApixels/DragonECS )
+ Minimum version of C# 7.3;
Optional:
+ Game engines with C#: Unity, Godot, MonoGame, etc.
Tested with:
+ **Unity:** Minimum version 2020.1.0;
## Unity Installation
* ### Unity Package
The framework can be installed as a Unity package by adding the Git URL [in the PackageManager ](https://docs.unity3d.com/2023.2/Documentation/Manual/upm-ui-giturl.html ) or manually adding it to `Packages/manifest.json` :
```
https://github.com/DCFApixels/DragonECS-AutoInjections.git
```
* ### Source Code
The framework can also be added to the project as source code.
< / br >
2023-05-31 04:23:11 +08:00
2023-05-31 04:20:54 +08:00
# Code Example
2023-05-28 15:44:29 +08:00
```csharp
2024-04-11 01:20:09 +08:00
class VelocitySystemDI : IEcsRun
2023-05-28 15:44:29 +08:00
{
2023-06-22 23:20:13 +08:00
class Aspect : EcsAspectAuto
2023-05-28 15:44:29 +08:00
{
2023-05-28 22:10:54 +08:00
[ExcImplicit(typeof(FreezedTag))]
2023-05-28 15:44:29 +08:00
[Inc] public EcsPool< Pose > poses;
[Inc] public EcsPool< Velocity > velocities;
}
[EcsInject] EcsDefaultWorld _world;
[EcsInject] TimeService _time;
2023-12-31 23:55:42 +08:00
public void Run()
2023-05-28 15:44:29 +08:00
{
2024-04-11 01:20:09 +08:00
foreach (var e in _world.Where(out Aspect a))
2023-05-28 15:44:29 +08:00
{
2024-04-11 01:20:09 +08:00
a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
2023-05-28 15:44:29 +08:00
}
}
}
```
2023-05-28 20:45:07 +08:00
< details >
2023-05-31 04:20:54 +08:00
< summary > Same code but without AutoInjections< / summary >
2023-05-28 20:45:07 +08:00
2023-05-28 15:44:29 +08:00
```csharp
2024-04-11 01:20:09 +08:00
class VelocitySystem : IEcsRun, IEcsInject< EcsDefaultWorld > , IEcsInject< TimeService >
2023-05-28 15:44:29 +08:00
{
2023-06-22 23:20:13 +08:00
class Aspect : EcsAspect
2023-05-28 15:44:29 +08:00
{
public EcsPool< Pose > poses;
public EcsPool< Velocity > velocities;
2023-06-22 23:20:13 +08:00
public Aspect(Builder b)
2023-05-28 15:44:29 +08:00
{
2023-05-28 22:10:54 +08:00
b.Exclude< FreezedTag > ();
2023-05-28 15:44:29 +08:00
poses = b.Include< Pose > ();
velocities = b.Include< Velocity > ();
}
}
EcsDefaultWorld _world;
TimeService _time;
public void Inject(EcsDefaultWorld obj) => _world = obj;
public void Inject(TimeService obj) => _time = obj;
2023-12-31 23:55:42 +08:00
public void Run()
2023-05-28 15:44:29 +08:00
{
2024-04-11 01:20:09 +08:00
foreach (var e in _world.Where(out Aspect a))
2023-05-28 15:44:29 +08:00
{
2024-04-11 01:20:09 +08:00
a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
2023-05-28 15:44:29 +08:00
}
}
}
```
2023-05-28 20:45:07 +08:00
< / details >