4

私はZenjectフレームワークを使用していますが、私はクラスに複数のGameObjectを使用していますが、私はZenject Containerを使用してそれを行うことは知らないです。ここに私のコード:Zenject GameObject Injection

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

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

これらのオブジェクトをZenject Containerから注入することは可能ですか?もしそうなら、どうしたらいいですか? Zenjectを使用して

答えて

3

、これらのクラスは次のように注入されます:あなたはDIを使用しているとき

[Inject] 
GameObject _canvas; 

[Inject] 
GameObject _mainWindow; 

[Inject] 
GameObject _createAccountWindow; 

はしかし、それは通常ので、それらすべてが、型である、タイプに基づいて注入「ゲームオブジェクト」になりますこれは難しい。

しかし、あなたはそれをこのようなものにする場合:

[Inject] 
Canvas _canvas; 

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

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

をその後も、これらのそれぞれにZenjectBindingコンポーネントを追加し、それが動作するはずです、ZenjectBindingの識別子プロパティの値を追加します。 (私は彼らがすでにスタートアップ時のシーンにいると仮定しています)