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; | |
using UnityEngine; | |
public class Auger :Enemy,IDisposable | |
{ | |
public Auger(string name,int hp) | |
{ | |
_name = name; | |
_hp = hp; | |
} |
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
private static readonly object Lock = new object(); | |
private static Singleton3 _instance; | |
public static Singleton3 Instance | |
{ | |
get | |
{ | |
lock (Lock) | |
{ | |
return _instance ??= new Singleton3(); | |
} |
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
private static Lazy<Singleton3> _instance = new Lazy<Singleton3>(); | |
public static Singleton3 Instance => _instance.Value; | |
public Singleton3() | |
{ | |
Debug.Log("コンストラクターが呼び出されました"); | |
} |
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
private Subject<Unit> _subject = new Subject<Unit>(); | |
//ボタンに結びつける | |
public void OnClickButton() | |
{ | |
_subject.OnNext(Unit.Default); | |
} | |
void Start() | |
{ |
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
//クリックのイベント | |
void Start() | |
{ | |
this.gameObject.GetComponent<Button>() | |
.OnClickAsObservable() | |
.Subscribe(_=>Debug.Log("OnClick!")) | |
.AddTo(this); | |
} |
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
// 当たり判定 | |
void Start() | |
{ | |
this.gameObject.GetComponent<Collider>().OnCollisionEnterAsObservable() | |
.Subscribe(target => Debug.Log("OnHit!")) | |
.AddTo(this); | |
} |
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; | |
public class Test : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
//複数個値を受け取るクラスを生成 | |
var observerA = new Observer2("A"); | |
var observerB = new Observer2("B"); |
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; | |
using System.Collections.Generic; | |
public class Subject2 :IObservable<int> | |
{ | |
//observerをまとめて管理するリスト | |
private List<IObserver<int>> _observers = new List<IObserver<int>>(); | |
//購読処理 | |
public IDisposable Subscribe(IObserver<int> observer) |
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; | |
public class Observer2 : IObserver<int> | |
{ | |
private string _name; | |
//コンストラクタでインスタンスにお名前を | |
public Observer2(string name) | |
{ | |
_name = name; | |
} |
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
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour | |
{ | |
/// <summary> | |
/// インスタンス | |
/// </summary> | |
private static T _instance; | |
/// <summary> | |
/// インスタンスのゲッター | |
/// </summary> |