クリア判定処理を追加
This commit is contained in:
parent
40643b711a
commit
c866583f4a
|
|
@ -1,7 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UniRx;
|
using UniRx;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
public enum CornResult
|
||||||
|
{
|
||||||
|
Perfect,
|
||||||
|
Good,
|
||||||
|
Failure
|
||||||
|
}
|
||||||
|
|
||||||
public class CornManager : MonoBehaviour
|
public class CornManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private Transform cornSpawnTarget;
|
[SerializeField] private Transform cornSpawnTarget;
|
||||||
|
|
@ -12,9 +21,14 @@ public class CornManager : MonoBehaviour
|
||||||
[SerializeField] private float baseCornPopTime = 5f;
|
[SerializeField] private float baseCornPopTime = 5f;
|
||||||
[SerializeField] private float cornBurntDuration = 5f;
|
[SerializeField] private float cornBurntDuration = 5f;
|
||||||
|
|
||||||
|
public IReadOnlyReactiveProperty<CornResult> Result => result;
|
||||||
|
private readonly ReactiveProperty<CornResult> result = new ReactiveProperty<CornResult>();
|
||||||
|
|
||||||
private Corn[] cornArray;
|
private Corn[] cornArray;
|
||||||
private readonly ReactiveProperty<float> cornGrowSpeed = new FloatReactiveProperty(0f);
|
|
||||||
private bool isHot;
|
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()
|
private void Awake()
|
||||||
{
|
{
|
||||||
cornArray = new Corn[cornSpawnCount];
|
cornArray = new Corn[cornSpawnCount];
|
||||||
|
result.AddTo(this);
|
||||||
|
cornGrowSpeed.AddTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RespawnCorn()
|
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++)
|
for (int i = 0; i < cornSpawnCount; i++)
|
||||||
{
|
{
|
||||||
var corn = Instantiate(cornPrefab, cornSpawnTarget);
|
var corn = Instantiate(cornPrefab, cornSpawnTarget);
|
||||||
|
|
@ -42,7 +69,7 @@ public class CornManager : MonoBehaviour
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
corn.ChangeGrowSpeed(x);
|
corn.ChangeGrowSpeed(x);
|
||||||
}).AddTo(this);
|
}).AddTo(compositeDisposable);
|
||||||
|
|
||||||
// コーンが弾けたとき、GrowSpeedを再設定する
|
// コーンが弾けたとき、GrowSpeedを再設定する
|
||||||
corn.Condition
|
corn.Condition
|
||||||
|
|
@ -54,8 +81,29 @@ public class CornManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
corn.ChangeGrowSpeed(0f);
|
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)
|
public void ChangeGrowSpeed(ThermalCondition condition)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue