Zenject GameObject Injection

I am using the Zenject framework and I am using a few GameObjectfor the class, but I do not know what to do using the Zenject Container. Here is my code:

private GameObject _canvas;
private GameObject _mainWindow;
private GameObject _createAccountWindow;

void Awake()
{
    _mainWindow = GameObject.FindGameObjectWithTag("MainWindow");
    _canvas = GameObject.FindGameObjectWithTag("Canvas");
    _createAccountWindow = GameObjectExtensions.FindObject(_canvas, "CreateAccountWindow");
}

Can I enter these objects from the Zenject container? If so, how can I do this?

+4
source share
1 answer

Using Zenject, these classes will be introduced as follows:

[Inject]
GameObject _canvas;

[Inject]
GameObject _mainWindow;

[Inject]
GameObject _createAccountWindow;

However, when you use DI, it usually types-based input, so including all GameObject types will be difficult.

But if you do it something like this:

[Inject]
Canvas _canvas;

[Inject(Id = "MainWindow")]
RectTransform _mainWindow;

[Inject(Id = "CreateAccountWindow")]
RectTransform _createAccountWindow;

ZenjectBinding Identifier ZenjectBinding, . ( , )

+3

Source: https://habr.com/ru/post/1655690/


All Articles