失敗時の条件修正
This commit is contained in:
parent
5b4aa17d44
commit
9bdb0e20db
|
|
@ -16,6 +16,7 @@ public class CornManager : MonoBehaviour
|
||||||
[SerializeField] private Transform cornSpawnTarget;
|
[SerializeField] private Transform cornSpawnTarget;
|
||||||
[SerializeField] private Corn cornPrefab;
|
[SerializeField] private Corn cornPrefab;
|
||||||
[SerializeField] private int cornSpawnCount = 20;
|
[SerializeField] private int cornSpawnCount = 20;
|
||||||
|
[SerializeField] private int maxFailedCornCount = 10;
|
||||||
[SerializeField, ReadOnly] private float baseGrowSpeed = 1f;
|
[SerializeField, ReadOnly] private float baseGrowSpeed = 1f;
|
||||||
[SerializeField] private float hotGrowSpeed;
|
[SerializeField] private float hotGrowSpeed;
|
||||||
[SerializeField] private float baseCornPopTime = 5f;
|
[SerializeField] private float baseCornPopTime = 5f;
|
||||||
|
|
@ -88,24 +89,35 @@ public class CornManager : MonoBehaviour
|
||||||
cornConditions.Add(corn.Condition);
|
cornConditions.Add(corn.Condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// すべてのコーンがSeedではなくなったら通知
|
var cornConditionsObservable = Observable.CombineLatest(cornConditions).Publish().RefCount();
|
||||||
Observable.CombineLatest(cornConditions)
|
|
||||||
|
// 焦げたコーンorフライパンを飛び出したコーンが設定値を超えるとFailure
|
||||||
|
cornConditionsObservable
|
||||||
|
.FirstOrDefault(x => x.Count(c => c == CornCondition.Burnt || c == CornCondition.Spilled) >= maxFailedCornCount)
|
||||||
|
.Subscribe(x =>
|
||||||
|
{
|
||||||
|
if (x == null) return;
|
||||||
|
SetResult(CornResult.Failure);
|
||||||
|
})
|
||||||
|
.AddTo(compositeDisposable);
|
||||||
|
|
||||||
|
// すべてのコーンがSeedではなくなった場合
|
||||||
|
cornConditionsObservable
|
||||||
.FirstOrDefault(x => !x.Contains(CornCondition.Seed))
|
.FirstOrDefault(x => !x.Contains(CornCondition.Seed))
|
||||||
.Subscribe(x =>
|
.Subscribe(x =>
|
||||||
{
|
{
|
||||||
cornGrowSpeed.Value = 0f;
|
if (x == null) return;
|
||||||
isCompleted = true;
|
|
||||||
if (x.Count(c => c == CornCondition.Simple) == x.Count) // すべてのコーンがPopped
|
if (x.Count(c => c == CornCondition.Simple) == x.Count) // すべてのコーンがPopped
|
||||||
{
|
{
|
||||||
result.SetValueAndForceNotify(CornResult.Perfect);
|
SetResult(CornResult.Perfect);
|
||||||
}
|
}
|
||||||
else if (x.Count(c => c == CornCondition.Simple) == 0) // すべてのコーンが飛び出した OR すべて焦げた
|
else if (x.Count(c => c == CornCondition.Simple) == 0) // すべてのコーンが飛び出した OR すべて焦げた
|
||||||
{
|
{
|
||||||
result.SetValueAndForceNotify(CornResult.Failure);
|
SetResult(CornResult.Failure);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.SetValueAndForceNotify(CornResult.Good);
|
SetResult(CornResult.Good);
|
||||||
}
|
}
|
||||||
}).AddTo(compositeDisposable);
|
}).AddTo(compositeDisposable);
|
||||||
}
|
}
|
||||||
|
|
@ -130,4 +142,11 @@ public class CornManager : MonoBehaviour
|
||||||
throw new ArgumentOutOfRangeException(nameof(condition), condition, null);
|
throw new ArgumentOutOfRangeException(nameof(condition), condition, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetResult(CornResult resultValue)
|
||||||
|
{
|
||||||
|
cornGrowSpeed.Value = 0f;
|
||||||
|
isCompleted = true;
|
||||||
|
result.SetValueAndForceNotify(resultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue