Skip to content

Instantly share code, notes, and snippets.

View saitocastel1900's full-sized avatar
🎮
Game Dev

まかろに saitocastel1900

🎮
Game Dev
  • Individual
  • Kanagawa, Japan
View GitHub Profile
using System;
using UnityEngine;
public class Auger :Enemy,IDisposable
{
public Auger(string name,int hp)
{
_name = name;
_hp = hp;
}
private static readonly object Lock = new object();
private static Singleton3 _instance;
public static Singleton3 Instance
{
get
{
lock (Lock)
{
return _instance ??= new Singleton3();
}
private static Lazy<Singleton3> _instance = new Lazy<Singleton3>();
public static Singleton3 Instance => _instance.Value;
public Singleton3()
{
Debug.Log("コンストラクターが呼び出されました");
}
private Subject<Unit> _subject = new Subject<Unit>();
//ボタンに結びつける
public void OnClickButton()
{
_subject.OnNext(Unit.Default);
}
void Start()
{
//クリックのイベント
void Start()
{
this.gameObject.GetComponent<Button>()
.OnClickAsObservable()
.Subscribe(_=>Debug.Log("OnClick!"))
.AddTo(this);
}
// 当たり判定
void Start()
{
this.gameObject.GetComponent<Collider>().OnCollisionEnterAsObservable()
.Subscribe(target => Debug.Log("OnHit!"))
.AddTo(this);
}
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");
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)
using System;
public class Observer2 : IObserver<int>
{
private string _name;
//コンストラクタでインスタンスにお名前を
public Observer2(string name)
{
_name = name;
}
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour
{
/// <summary>
/// インスタンス
/// </summary>
private static T _instance;
/// <summary>
/// インスタンスのゲッター
/// </summary>