Skip to content

Instantly share code, notes, and snippets.

@Tsumio
Created June 23, 2018 10:45
Show Gist options
  • Save Tsumio/e861ab4b15200baf2df2b7e6f1b4da53 to your computer and use it in GitHub Desktop.
Save Tsumio/e861ab4b15200baf2df2b7e6f1b4da53 to your computer and use it in GitHub Desktop.
ZenjectSample2
using UnityEngine;
using Zenject;
public class AttackerInstaller : MonoInstaller<AttackerInstaller> {
public override void InstallBindings() {
Container.Bind<IPlayerAttacker>().To<PlayerAttacker>().AsSingle();
}
}
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