mirror of
https://github.com/DCFApixels/DragonECS-AutoInjections.git
synced 2026-04-21 23:15:54 +08:00
update readme
This commit is contained in:
parent
1b3c009768
commit
431f0b873c
14
README-RU.md
14
README-RU.md
@ -81,7 +81,7 @@ https://github.com/DCFApixels/DragonECS-AutoInjections.git
|
||||
|
||||
# Интеграция
|
||||
Добавьте вызов метода `AutoInject()` для Builder-а пайплайна. Пример:
|
||||
```csharp
|
||||
```c#
|
||||
_pipeline = EcsPipeline.New()
|
||||
.Inject(world)
|
||||
.Inject(_timeService)
|
||||
@ -99,11 +99,11 @@ _pipeline = EcsPipeline.New()
|
||||
|
||||
# Инъекция зависимостей
|
||||
Атрибут `[DI]` заменяет интерфейс `IEcsInject<T>`, Поля, отмеченные этим атрибутом, автоматически получают зависимости, внедрённые в Pipeline. Пример:
|
||||
```csharp
|
||||
```c#
|
||||
[DI] EcsDefaultWorld _world;
|
||||
```
|
||||
Так же можно делать внедрение через свойство или метод:
|
||||
```csharp
|
||||
```c#
|
||||
EcsDefaultWorld _world;
|
||||
|
||||
//Обязательно наличие set блока.
|
||||
@ -137,7 +137,7 @@ EcsDefaultWorld _world;
|
||||
# Auto Runner-ы
|
||||
Для получения раннеров без добавления, есть атрибут `[BindWithRunner(type)]` и метод `GetRunnerAuto<T>()`.
|
||||
|
||||
``` c#
|
||||
```c#
|
||||
[BindWithRunner(typeof(DoSomethingProcessRunner))]
|
||||
interface IDoSomethingProcess : IEcsProcess
|
||||
{
|
||||
@ -161,7 +161,7 @@ _pipeline.GetRunnerAuto<IDoSomethingProcess>().Do();
|
||||
|
||||
# Пример кода
|
||||
|
||||
```csharp
|
||||
```c#
|
||||
class VelocitySystemDI : IEcsRun
|
||||
{
|
||||
class Aspect : EcsAspectAuto
|
||||
@ -189,7 +189,7 @@ class VelocitySystemDI : IEcsRun
|
||||
<details>
|
||||
<summary>Тот же код но без AutoInjections</summary>
|
||||
|
||||
```csharp
|
||||
```c#
|
||||
class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService>
|
||||
{
|
||||
class Aspect : EcsAspect
|
||||
@ -226,7 +226,7 @@ class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeServ
|
||||
# Не null инъекции
|
||||
|
||||
Чтобы поле, отмеченное атрибутом `[DI]`, было проинициализировано даже в случае отсутствия инъекции, в конструктор атрибута можно передать тип-заглушку. В примере ниже поле `foo` получит экземпляр `Foo` из инъекции или экземпляр `FooDummy : Foo`, если инъекция не была выполнена.
|
||||
``` csharp
|
||||
```c#
|
||||
[DI(typeof(FooDummy))] Foo foo;
|
||||
```
|
||||
> Переданный тип должен иметь конструктор без параметров и быть либо того же типа, что и поле, либо производным от него.
|
||||
|
||||
60
README.md
60
README.md
@ -45,31 +45,71 @@ The extension is designed to reduce the amount of code by simplifying dependency
|
||||
</br>
|
||||
|
||||
# Installation
|
||||
Versioning semantics - [Open](https://gist.github.com/DCFApixels/e53281d4628b19fe5278f3e77a7da9e8#file-dcfapixels_versioning_ru-md)
|
||||
Versioning semantics - [Open](https://gist.github.com/DCFApixels/af79284955bf40e9476cdcac79d7b098#file-dcfapixels_versioning-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.
|
||||
|
||||
* Game engines with C#: Unity, Godot, MonoGame, etc.
|
||||
|
||||
Tested with:
|
||||
+ **Unity:** Minimum version 2020.1.0;
|
||||
* **Unity:** Minimum version 2021.2.0.
|
||||
|
||||
## Unity Installation
|
||||
* ### Unity Package
|
||||
The package 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`:
|
||||
The package supports installation as a Unity package by adding the Git URL [in the PackageManager](https://docs.unity3d.com/2023.2/Documentation/Manual/upm-ui-giturl.html):
|
||||
```
|
||||
https://github.com/DCFApixels/DragonECS-AutoInjections.git
|
||||
```
|
||||
Or add the package entry to `Packages/manifest.json`:
|
||||
```
|
||||
"com.dcfa_pixels.dragonecs-auto_injections": "https://github.com/DCFApixels/DragonECS-AutoInjections.git",
|
||||
```
|
||||
|
||||
* ### Source Code
|
||||
The package can also be added to the project as source code.
|
||||
The package source code can also be copied directly into the project.
|
||||
|
||||
|
||||
</br>
|
||||
|
||||
# Integration
|
||||
Add the AutoInject() call to the pipeline Builder. Example:
|
||||
```c#
|
||||
_pipeline = EcsPipeline.New()
|
||||
.Inject(world)
|
||||
.Inject(_timeService)
|
||||
.Add(new TestSystem())
|
||||
.Add(new VelocitySystem())
|
||||
.Add(new ViewSystem())
|
||||
.AutoInject() // Done — automatic injections enabled
|
||||
.BuildAndInit();
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Ensure AutoInject() is called during initialization; otherwise nothing will work.
|
||||
|
||||
# Dependency Injection
|
||||
The `[DI]` attribute replaces the `IEcsInject<T>` interface. Fields marked with this attribute automatically receive dependencies injected into the pipeline. Example:
|
||||
```c#
|
||||
[DI] EcsDefaultWorld _world;
|
||||
```
|
||||
Injection can also be done via a property or method:
|
||||
```c#
|
||||
EcsDefaultWorld _world;
|
||||
|
||||
//Обязательно наличие set блока.
|
||||
[DI] EcsDefaultWorld World { set => _world = value; }
|
||||
|
||||
//Количество аргументов должно быть равно 1.
|
||||
[DI] void InjectWorld(EcsDefaultWorld world) => _world = world;
|
||||
```
|
||||
|
||||
> Aggressive injection (without the `[DI]` attribute) is enabled by calling `.AutoInject(true)`.
|
||||
|
||||
# Code Example
|
||||
```csharp
|
||||
```c#
|
||||
class VelocitySystemDI : IEcsRun
|
||||
{
|
||||
class Aspect : EcsAspectAuto
|
||||
@ -79,8 +119,8 @@ class VelocitySystemDI : IEcsRun
|
||||
[Inc] public EcsPool<Velocity> velocities;
|
||||
}
|
||||
|
||||
[EcsInject] EcsDefaultWorld _world;
|
||||
[EcsInject] TimeService _time;
|
||||
[DI] EcsDefaultWorld _world;
|
||||
[DI] TimeService _time;
|
||||
|
||||
public void Run()
|
||||
{
|
||||
@ -94,7 +134,7 @@ class VelocitySystemDI : IEcsRun
|
||||
<details>
|
||||
<summary>Same code but without AutoInjections</summary>
|
||||
|
||||
```csharp
|
||||
```c#
|
||||
class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService>
|
||||
{
|
||||
class Aspect : EcsAspect
|
||||
|
||||
Loading…
Reference in New Issue
Block a user