Created
June 23, 2018 10:45
-
-
Save Tsumio/e861ab4b15200baf2df2b7e6f1b4da53 to your computer and use it in GitHub Desktop.
ZenjectSample2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Zenject; | |
public class AttackerInstaller : MonoInstaller<AttackerInstaller> { | |
public override void InstallBindings() { | |
Container.Bind<IPlayerAttacker>().To<PlayerAttacker>().AsSingle(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Zenject;//こいつを忘れないで! | |
/// <summary> | |
/// プレイヤーを表すクラス。 | |
/// 今回は攻撃をするだけ。 | |
/// </summary> | |
public class Player : MonoBehaviour { | |
[Inject]//こいつを忘れないで! | |
private IPlayerAttacker _attacker; | |
private void Update() { | |
//マウスクリックとかで攻撃開始すーるよ | |
if(Input.GetMouseButtonDown(0)) { | |
//このクラス内のコードでインスタンスを生成していないが、依存性の注入はZenjectがおこなっているのでnullにならない。 | |
_attacker.Attack(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment