Merge branch 'develop' of bitbucket.org:usaya/popcorn into develop

This commit is contained in:
koya_15 2021-07-09 11:01:17 +09:00
commit af0ff65153
2 changed files with 92 additions and 44 deletions

View File

@ -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;
@ -40,6 +41,7 @@ public class CornManager : MonoBehaviour
cornArray = new Corn[cornSpawnCount]; cornArray = new Corn[cornSpawnCount];
result.AddTo(this); result.AddTo(this);
cornGrowSpeed.AddTo(this); cornGrowSpeed.AddTo(this);
compositeDisposable.AddTo(this);
} }
public void RespawnCorn() public void RespawnCorn()
@ -62,6 +64,7 @@ public class CornManager : MonoBehaviour
cornArray[i] = corn; cornArray[i] = corn;
corn.SetCornProperty(baseCornPopTime, cornBurntDuration); corn.SetCornProperty(baseCornPopTime, cornBurntDuration);
// 進行速度の変更時、コーン速度変更
cornGrowSpeed.TakeWhile(_ => !isCompleted).Subscribe(x => cornGrowSpeed.TakeWhile(_ => !isCompleted).Subscribe(x =>
{ {
// コーンが弾けた後はRedの場合のみ焦げ進行する // コーンが弾けた後はRedの場合のみ焦げ進行する
@ -79,6 +82,7 @@ public class CornManager : MonoBehaviour
.FirstOrDefault() .FirstOrDefault()
.Subscribe(_ => .Subscribe(_ =>
{ {
// ThermalCondition.Hot以外では焦げ進行なし
if (!isHot) if (!isHot)
{ {
corn.ChangeGrowSpeed(0f); corn.ChangeGrowSpeed(0f);
@ -88,24 +92,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.Spilled) == x.Count) // すべてのコーンが飛び出した 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 +145,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);
}
} }

View File

@ -4,7 +4,6 @@ using UniRx;
using UniRx.Triggers; using UniRx.Triggers;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
public enum GameState public enum GameState
@ -31,10 +30,11 @@ public class PopcornGameManager : MonoBehaviour
private readonly ReactiveProperty<GameState> state = new ReactiveProperty<GameState>(GameState.Guide); private readonly ReactiveProperty<GameState> state = new ReactiveProperty<GameState>(GameState.Guide);
private readonly CompositeDisposable compositeDisposable = new CompositeDisposable(); private readonly CompositeDisposable compositeDisposable = new CompositeDisposable();
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
compositeDisposable.AddTo(this);
thermalControl.Condition.Subscribe(x => thermalControl.Condition.Subscribe(x =>
{ {
cornManager.ChangeGrowSpeed(x); cornManager.ChangeGrowSpeed(x);
@ -57,41 +57,23 @@ public class PopcornGameManager : MonoBehaviour
} }
}).AddTo(this); }).AddTo(this);
cornManager.Result.SkipLatestValueOnSubscribe().Subscribe(x =>
{
state.Value = GameState.Result;
thermalControl.StopMeter();
characterFlower.gameObject.SetActive(false);
characterSweat.gameObject.SetActive(false);
switch (x)
{
case CornResult.Perfect:
perfectResultObject.SetActive(true);
break;
case CornResult.Good:
goodResultObject.SetActive(true);
break;
case CornResult.Failure:
failureResultObject.SetActive(true);
break;
default:
throw new ArgumentOutOfRangeException(nameof(x), x, null);
}
// 再度画面タップでリセット
this.UpdateAsObservable()
.Select(_ => Input.GetMouseButton(0))
.DistinctUntilChanged()
.Skip(1)
.FirstOrDefault(b => b)
.Subscribe(_ =>
{
ResetGame();
}).AddTo(this);
}).AddTo(this);
ResetGame(); ResetGame();
#if UNITY_EDITOR
this.UpdateAsObservable()
.Where(_ => Input.GetKeyDown(KeyCode.R))
// 連打防止
.ThrottleFirst(TimeSpan.FromSeconds(0.1f))
.Subscribe(_ => UnityEngine.SceneManagement.SceneManager.LoadScene("Cooking"))
.AddTo(this);
this.UpdateAsObservable()
.Where(_ => Input.GetKeyDown(KeyCode.E))
// 連打防止
.ThrottleFirst(TimeSpan.FromSeconds(0.1f))
.Subscribe(_ => ResetGame())
.AddTo(this);
#endif
} }
private void ResetUI() private void ResetUI()
@ -110,6 +92,49 @@ public class PopcornGameManager : MonoBehaviour
private void ResetGame() private void ResetGame()
{ {
compositeDisposable.Clear(); compositeDisposable.Clear();
cornManager.Result.SkipLatestValueOnSubscribe()
.FirstOrDefault()
.DelayFrame(1)
.Subscribe(x =>
{
state.Value = GameState.Result;
thermalControl.StopMeter();
characterFlower.gameObject.SetActive(false);
characterSweat.gameObject.SetActive(false);
this.CallWaitForSeconds(1f, () =>
{
});
// リザルト表示遅延
Observable.Timer(TimeSpan.FromMilliseconds(1000)).Subscribe(a =>
{
switch (x)
{
case CornResult.Perfect:
perfectResultObject.SetActive(true);
break;
case CornResult.Good:
goodResultObject.SetActive(true);
break;
case CornResult.Failure:
failureResultObject.SetActive(true);
break;
default:
throw new ArgumentOutOfRangeException(nameof(x), x, null);
}
// 再度画面タップでリセット
this.UpdateAsObservable()
.Select(_ => Input.GetMouseButton(0))
.DistinctUntilChanged()
.Skip(1)
.FirstOrDefault(b => b)
.Subscribe(_ =>
{
ResetGame();
}).AddTo(compositeDisposable);
}).AddTo(compositeDisposable);
}).AddTo(compositeDisposable);
this.UpdateAsObservable() this.UpdateAsObservable()
.Select(_ => Input.GetMouseButton(0)) .Select(_ => Input.GetMouseButton(0))
.DistinctUntilChanged() .DistinctUntilChanged()
@ -119,6 +144,7 @@ public class PopcornGameManager : MonoBehaviour
{ {
StartGame(); StartGame();
}).AddTo(compositeDisposable); }).AddTo(compositeDisposable);
ResetUI(); ResetUI();
thermalControl.ResetMeter(); thermalControl.ResetMeter();
cornManager.RespawnCorn(); cornManager.RespawnCorn();