クリア判定処理を追加
This commit is contained in:
parent
40643b711a
commit
c866583f4a
|
|
@ -1,7 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public enum CornResult
|
||||
{
|
||||
Perfect,
|
||||
Good,
|
||||
Failure
|
||||
}
|
||||
|
||||
public class CornManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform cornSpawnTarget;
|
||||
|
|
@ -12,10 +21,15 @@ public class CornManager : MonoBehaviour
|
|||
[SerializeField] private float baseCornPopTime = 5f;
|
||||
[SerializeField] private float cornBurntDuration = 5f;
|
||||
|
||||
private Corn[] cornArray;
|
||||
private readonly ReactiveProperty<float> cornGrowSpeed = new FloatReactiveProperty(0f);
|
||||
private bool isHot;
|
||||
public IReadOnlyReactiveProperty<CornResult> Result => result;
|
||||
private readonly ReactiveProperty<CornResult> result = new ReactiveProperty<CornResult>();
|
||||
|
||||
private Corn[] cornArray;
|
||||
private bool isHot;
|
||||
private List<IObservable<CornCondition>> cornConditions = new List<IObservable<CornCondition>>();
|
||||
private readonly ReactiveProperty<float> cornGrowSpeed = new FloatReactiveProperty(0f);
|
||||
private readonly CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
// クリア判定を通知
|
||||
|
||||
// コーンの状態を取得する
|
||||
|
|
@ -23,10 +37,23 @@ public class CornManager : MonoBehaviour
|
|||
private void Awake()
|
||||
{
|
||||
cornArray = new Corn[cornSpawnCount];
|
||||
result.AddTo(this);
|
||||
cornGrowSpeed.AddTo(this);
|
||||
}
|
||||
|
||||
public void RespawnCorn()
|
||||
{
|
||||
compositeDisposable.Clear();
|
||||
cornConditions.Clear();
|
||||
for (int i = 0; i < cornArray.Length; i++)
|
||||
{
|
||||
if (cornArray[i] != null)
|
||||
{
|
||||
Destroy(cornArray[i].gameObject);
|
||||
}
|
||||
}
|
||||
cornArray = new Corn[cornSpawnCount];
|
||||
|
||||
for (int i = 0; i < cornSpawnCount; i++)
|
||||
{
|
||||
var corn = Instantiate(cornPrefab, cornSpawnTarget);
|
||||
|
|
@ -42,7 +69,7 @@ public class CornManager : MonoBehaviour
|
|||
return;
|
||||
}
|
||||
corn.ChangeGrowSpeed(x);
|
||||
}).AddTo(this);
|
||||
}).AddTo(compositeDisposable);
|
||||
|
||||
// コーンが弾けたとき、GrowSpeedを再設定する
|
||||
corn.Condition
|
||||
|
|
@ -54,8 +81,29 @@ public class CornManager : MonoBehaviour
|
|||
{
|
||||
corn.ChangeGrowSpeed(0f);
|
||||
}
|
||||
}).AddTo(this);
|
||||
}).AddTo(compositeDisposable);
|
||||
|
||||
cornConditions.Add(corn.Condition);
|
||||
}
|
||||
|
||||
// すべてのコーンがSeedではなくなったら通知
|
||||
Observable.CombineLatest(cornConditions)
|
||||
.FirstOrDefault(x => !x.Contains(CornCondition.Seed))
|
||||
.Subscribe(x =>
|
||||
{
|
||||
if (x.Count(c => c == CornCondition.Simple) == x.Count) // すべてのコーンがPopped
|
||||
{
|
||||
result.SetValueAndForceNotify(CornResult.Perfect);
|
||||
}
|
||||
else if (x.Count(c => c == CornCondition.Spilled) == x.Count) // すべてのコーンが飛び出した
|
||||
{
|
||||
result.SetValueAndForceNotify(CornResult.Failure);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.SetValueAndForceNotify(CornResult.Good);
|
||||
}
|
||||
}).AddTo(compositeDisposable);
|
||||
}
|
||||
|
||||
public void ChangeGrowSpeed(ThermalCondition condition)
|
||||
|
|
|
|||
Loading…
Reference in New Issue