diff --git a/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs b/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs index 2e1d0a4a..7f1fc289 100644 --- a/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs +++ b/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs @@ -46,7 +46,7 @@ public class Title : MonoBehaviour .Subscribe(t => { // 一般客orセレブ - var (isSpecial, orderCount) = Market.Instance.GetCustomerData(false); + var (isSpecial, orderCount) = Market.Instance.GetCustomerData(CustomerType.Walker); // 複数パターンある場合ChooseRandom var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab(); diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs index fe48a028..2b7f8321 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs @@ -3,15 +3,22 @@ using System.Linq; using UniRx; using UnityEngine; +public enum CustomerType +{ + Walker, + Customer, + Vip +} + public class CustomerFlow : MonoBehaviour { - private IObservable customerObservable; - private IObservable walkerObservable; - private IObservable adWalkerObservable; + private IObservable customerObservable; + private IObservable walkerObservable; + private IObservable adWalkerObservable; private readonly Subject> adStartObservable = new Subject>(); - private IObservable vipCustomerObservable; + private IObservable vipCustomerObservable; private readonly Subject> vipCustomerSubject = new Subject>(); - private IObservable tastingCustomerObservable; + private IObservable tastingCustomerObservable; private static readonly float checkHeartInterval = 1f; [Header("1分間あたりの歩行者数")] @@ -33,7 +40,7 @@ public class CustomerFlow : MonoBehaviour public float TastingCustomerInterval => tastingCustomerInterval; private int adActiveCount = 0; - public IObservable Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable); + public IObservable Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable); private void Awake() { @@ -58,18 +65,18 @@ public class CustomerFlow : MonoBehaviour .Select(customerInterval => Observable.Interval(TimeSpan.FromSeconds(customerInterval))) .Switch() // .Do(_ => Debug.Log($"customer:{GetHashCode()}")) - .Select(_ => true); + .Select(_ => CustomerType.Customer); // 歩行者出現頻度、立ち止まり確率も設定(歩行者タイマー1分間に6人 walkerObservable = Observable.Interval(TimeSpan.FromSeconds(walkerInterval)) // .Do(l => Debug.Log($"walker:{GetHashCode()}")) - .Select(x => false); + .Select(_ => CustomerType.Walker); // 宣伝時、タップすると60秒だけ稼働するストリーム adWalkerObservable = adStartObservable .Switch() // .Do(_ => Debug.Log($"adWalker:{GetHashCode()}")) - .Select(_ => false); + .Select(_ => CustomerType.Walker); #if DEVELOPMENT_BUILD || UNITY_EDITOR if (UsayaStorageManager.LoadOrDefault(UsayaStorageFilename.Settings_Data, "DebugManyWalker", false)) { @@ -80,7 +87,7 @@ public class CustomerFlow : MonoBehaviour // VIP宣伝 vipCustomerObservable = vipCustomerSubject .Switch() - .Select(_ => true); + .Select(_ => CustomerType.Vip); // 試食 // tastingCustomerInterval毎にTastingCountを確認 @@ -97,7 +104,7 @@ public class CustomerFlow : MonoBehaviour }); tastingCustomerObservable = tastingTimer // .Do(_ => Debug.Log($"tastingCustomer remain:{GameDataManager.GameData.TastingCount}")) - .Select(_ => true); + .Select(_ => CustomerType.Customer); } public void StartAdWalker(Action onComplete = null) diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs index 504d2d4c..4e145da0 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs @@ -1,5 +1,7 @@ +using System; using System.Linq; using UnityEngine; +using Random = UnityEngine.Random; namespace MyGame.Scenes.marketing.Scripts { @@ -18,13 +20,19 @@ namespace MyGame.Scenes.marketing.Scripts (0, 5f), }; - public (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer) + public (bool isSpecial, int orderCount) GetCustomerData (CustomerType customerType) { - var specialRate = isCustomer ? walkerSpecialRate : customerSpecialRate; - var isSpecial = Random.value < specialRate; - - // セレブは5個購入固定 - return isSpecial ? (true, specialOrderCount) : (false, GetOrderCount()); + switch (customerType) + { + case CustomerType.Walker: + return Random.value < walkerSpecialRate ? (true, specialOrderCount) : (false, GetOrderCount()); + case CustomerType.Customer: + return Random.value < customerSpecialRate ? (true, specialOrderCount) : (false, GetOrderCount()); + case CustomerType.Vip: + return (true, specialOrderCount); + default: + throw new ArgumentOutOfRangeException(nameof(customerType), customerType, null); + } } // お客さん出現パターン確率計算と行動パターン計算 diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs index 699bf550..2ac78b1f 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs @@ -285,7 +285,7 @@ public class Market : SingletonMonoBehaviour }).AddTo(this); // 客湧き - customerFlow.Flow.Subscribe(isCustomer => + customerFlow.Flow.Subscribe(customerType => { if (IsPause.Value) { @@ -298,17 +298,32 @@ public class Market : SingletonMonoBehaviour return; } // 一般客orセレブ - var (isSpecial, orderCount) = GetCustomerData(isCustomer); + CustomerState customerState; - // 複数パターンある場合ChooseRandom - var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab(); + switch (customerType) + { + case CustomerType.Walker: + customerState = CustomerState.Walk; + break; + case CustomerType.Customer: + customerState = CustomerState.WalkShop; + break; + case CustomerType.Vip: + customerState = CustomerState.WalkShop; + break; + default: + throw new ArgumentOutOfRangeException(nameof(customerType), customerType, null); + } + + var (isSpecial, orderCount) = GetCustomerData(customerType); var customerController = SpawnCustomer(); customerController.Setup(orderPosisionObject.transform.GetComponentsInChildren().ToList().Skip(1).ToList()); + customerController.ChangeCustomerState(customerState); + // 複数パターンある場合ChooseRandom + customerController.CustomerPrefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab(); customerController.OrderCount = orderCount; - customerController.CustomerPrefab = prefab; customerControllerList.Add(customerController); - - customerController.ChangeCustomerState(isCustomer ? CustomerState.WalkShop : CustomerState.Walk); + customerController.TappedObservable .Take(1) .Subscribe(_ => @@ -355,9 +370,9 @@ public class Market : SingletonMonoBehaviour } - public (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer) + public (bool isSpecial, int orderCount) GetCustomerData (CustomerType customerType) { - return customerSetting.GetCustomerData(isCustomer); + return customerSetting.GetCustomerData(customerType); } private CustomerController SpawnCustomer()