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 Corn cornPrefab;
[SerializeField] private int cornSpawnCount = 20;
[SerializeField] private int maxFailedCornCount = 10;
[SerializeField, ReadOnly] private float baseGrowSpeed = 1f;
[SerializeField] private float hotGrowSpeed;
[SerializeField] private float baseCornPopTime = 5f;
@ -40,6 +41,7 @@ public class CornManager : MonoBehaviour
cornArray = new Corn[cornSpawnCount];
result.AddTo(this);
cornGrowSpeed.AddTo(this);
compositeDisposable.AddTo(this);
}
public void RespawnCorn()
@ -62,6 +64,7 @@ public class CornManager : MonoBehaviour
cornArray[i] = corn;
corn.SetCornProperty(baseCornPopTime, cornBurntDuration);
// 進行速度の変更時、コーン速度変更
cornGrowSpeed.TakeWhile(_ => !isCompleted).Subscribe(x =>
{
// コーンが弾けた後はRedの場合のみ焦げ進行する
@ -79,6 +82,7 @@ public class CornManager : MonoBehaviour
.FirstOrDefault()
.Subscribe(_ =>
{
// ThermalCondition.Hot以外では焦げ進行なし
if (!isHot)
{
corn.ChangeGrowSpeed(0f);
@ -88,24 +92,35 @@ public class CornManager : MonoBehaviour
cornConditions.Add(corn.Condition);
}
// すべてのコーンがSeedではなくなったら通知
Observable.CombineLatest(cornConditions)
var cornConditionsObservable = Observable.CombineLatest(cornConditions).Publish().RefCount();
// 焦げたコーン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))
.Subscribe(x =>
{
cornGrowSpeed.Value = 0f;
isCompleted = true;
if (x == null) return;
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
{
result.SetValueAndForceNotify(CornResult.Good);
SetResult(CornResult.Good);
}
}).AddTo(compositeDisposable);
}
@ -130,4 +145,11 @@ public class CornManager : MonoBehaviour
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 UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum GameState
@ -31,10 +30,11 @@ public class PopcornGameManager : MonoBehaviour
private readonly ReactiveProperty<GameState> state = new ReactiveProperty<GameState>(GameState.Guide);
private readonly CompositeDisposable compositeDisposable = new CompositeDisposable();
// Start is called before the first frame update
void Start()
{
compositeDisposable.AddTo(this);
thermalControl.Condition.Subscribe(x =>
{
cornManager.ChangeGrowSpeed(x);
@ -57,41 +57,23 @@ public class PopcornGameManager : MonoBehaviour
}
}).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();
#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()
@ -110,6 +92,49 @@ public class PopcornGameManager : MonoBehaviour
private void ResetGame()
{
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()
.Select(_ => Input.GetMouseButton(0))
.DistinctUntilChanged()
@ -119,6 +144,7 @@ public class PopcornGameManager : MonoBehaviour
{
StartGame();
}).AddTo(compositeDisposable);
ResetUI();
thermalControl.ResetMeter();
cornManager.RespawnCorn();