From 0ba6b6fc014f483fad5ef0ffdae69a4d185b5e2e Mon Sep 17 00:00:00 2001 From: kimura Date: Wed, 27 Oct 2021 09:58:07 +0900 Subject: [PATCH] =?UTF-8?q?Market=E3=82=AF=E3=83=A9=E3=82=B9=E3=83=AA?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyGame/Scenes/marketing/Scripts/Market.cs | 149 +++++++----------- 1 file changed, 59 insertions(+), 90 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs index 79cba9b2..03e9b95b 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs @@ -18,6 +18,14 @@ public enum ShopState public class Market : SingletonMonoBehaviour { public static readonly int ShopStockCount = 20; + private static readonly (int want, float weight)[] customerWeightTable = { + (1, 70f), + (2, 20f), + (3, 3f), + (4, 1.5f), + (5, .5f), + (0, 5f), + }; [SerializeField] private CustomerFlow customerFlow; [SerializeField] private GameObject orderPosisionObject; @@ -189,14 +197,7 @@ public class Market : SingletonMonoBehaviour // 商品補充 RefillShopStockData(); - -#if UNITY_EDITOR - StockFlavorLog(); - Debug.Log($"ShopStock{gameData.ShopStock.Count}, {shuffledOrder.Count + orders.Count}"); - Debug.Log($"displayCount:{displayFlavors.Count}\n" + - $"shuffled:{shuffledOrder.Count} {string.Join(",", shuffledOrder)}\n" + - $"orders:{orders.Count} {string.Join(",", orders)}"); -#endif + // 表示データ更新 var isReorder = false; var refillList = new List(); @@ -261,6 +262,7 @@ public class Market : SingletonMonoBehaviour controller.ChangeCustomerState(CustomerState.Wait); }).AddTo(this); + // 客湧き customerFlow.Flow.Subscribe(isCustomer => { if (IsPause.Value) @@ -271,58 +273,14 @@ public class Market : SingletonMonoBehaviour var (isSpecial, orderCount) = GetCustomerData(isCustomer); // 複数パターンある場合ChooseRandom - CustomerAnimator prefab; - if (isSpecial) - { - prefab = customerData.ChooseSpecialPrefab(); - } - else - { - prefab = customerData.ChooseNormalPrefab(); - } - - var customerController = Instantiate(customerControllerPrefab, transform); + var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab(); + var customerController = SpawnCustomer(); customerController.Setup(orderPosisionObject.transform.GetComponentsInChildren().ToList().Skip(1).ToList()); customerController.OrderCount = orderCount; customerController.CustomerPrefab = prefab; customerControllerList.Add(customerController); - - IsPause.Subscribe(x => - { - customerController.IsPause = x; - }).AddTo(customerController); + - customerController.MoveEndObservable - .SkipLatestValueOnSubscribe() - .DistinctUntilChanged() - .Subscribe(prevMovingType => - { - // Debug.Log($"move end {type} {customerController.GetHashCode()}"); - switch (prevMovingType) - { - case CustomerMovingType.WalkSide: - case CustomerMovingType.WalkSideEat: - customerList.Remove(customerController); - customerControllerList.Remove(customerController); - Destroy(customerController.gameObject); - break; - case CustomerMovingType.WalkCenter: - if (customerController.State.Value == CustomerState.WalkShop) - { - customerList.Add(customerController); - } - break; - case CustomerMovingType.WalkBackHalf: - waitCustomerList.Add(customerController); - break; - case CustomerMovingType.StayBackOrder: - requestSubject.OnNext(customerController); - break; - default: - break; - } - }).AddTo(customerController); - if (isCustomer) { // 近くまで歩く(タップされたらcustomerList.Add() @@ -361,24 +319,19 @@ public class Market : SingletonMonoBehaviour } }).AddTo(this); } + + + private (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer) + { + var isSpecial = isCustomer ? Random.value < .01f : Random.value < .03f; + + // セレブは5個購入固定 + return isSpecial ? (true, 5) : (false, GetOrderCount()); + } // お客さん出現パターン確率計算と行動パターン計算 - private int GetOrderCount(bool isSpecial) + private int GetOrderCount() { - if (isSpecial) - { - return 5; - } - - var customerWeightTable = new (int want, float weight)[]{ - (1, 70f), - (2, 20f), - (3, 3f), - (4, 1.5f), - (5, .5f), - (0, 5f), - }; - var randomPoint = Random.value * customerWeightTable.Sum(x => x.weight); foreach (var value in customerWeightTable) { @@ -390,27 +343,43 @@ public class Market : SingletonMonoBehaviour } return customerWeightTable.Last().want; } - - private (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer) + + private CustomerController SpawnCustomer() { - var isSpecial = false; - - if (isCustomer) - { - isSpecial = Random.value < .01f; - } - else - { - isSpecial = Random.value < .03f; - } - - // セレブは5個購入固定 - if (isSpecial) - { - return (true, GetOrderCount(true)); - } - - return (false, GetOrderCount(false)); + var customerController = Instantiate(customerControllerPrefab, transform); + IsPause.Subscribe(x => customerController.IsPause = x).AddTo(customerController); + + customerController.MoveEndObservable + .SkipLatestValueOnSubscribe() + .DistinctUntilChanged() + .Subscribe(prevMovingType => + { + // Debug.Log($"move end {type} {customerController.GetHashCode()}"); + switch (prevMovingType) + { + case CustomerMovingType.WalkSide: + case CustomerMovingType.WalkSideEat: + customerList.Remove(customerController); + customerControllerList.Remove(customerController); + Destroy(customerController.gameObject); + break; + case CustomerMovingType.WalkCenter: + if (customerController.State.Value == CustomerState.WalkShop) + { + customerList.Add(customerController); + } + break; + case CustomerMovingType.WalkBackHalf: + waitCustomerList.Add(customerController); + break; + case CustomerMovingType.StayBackOrder: + requestSubject.OnNext(customerController); + break; + default: + break; + } + }).AddTo(customerController); + return customerController; } private int SellPopcorn(List stockDataList)