複数お客さんタイプに対応

This commit is contained in:
kimura 2022-02-04 19:39:44 +09:00
parent e6ffd80e7a
commit 86baca721c
4 changed files with 57 additions and 27 deletions

View File

@ -46,7 +46,7 @@ public class Title : MonoBehaviour
.Subscribe(t => .Subscribe(t =>
{ {
// 一般客orセレブ // 一般客orセレブ
var (isSpecial, orderCount) = Market.Instance.GetCustomerData(false); var (isSpecial, orderCount) = Market.Instance.GetCustomerData(CustomerType.Walker);
// 複数パターンある場合ChooseRandom // 複数パターンある場合ChooseRandom
var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab(); var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab();

View File

@ -3,15 +3,22 @@ using System.Linq;
using UniRx; using UniRx;
using UnityEngine; using UnityEngine;
public enum CustomerType
{
Walker,
Customer,
Vip
}
public class CustomerFlow : MonoBehaviour public class CustomerFlow : MonoBehaviour
{ {
private IObservable<bool> customerObservable; private IObservable<CustomerType> customerObservable;
private IObservable<bool> walkerObservable; private IObservable<CustomerType> walkerObservable;
private IObservable<bool> adWalkerObservable; private IObservable<CustomerType> adWalkerObservable;
private readonly Subject<IObservable<Unit>> adStartObservable = new Subject<IObservable<Unit>>(); private readonly Subject<IObservable<Unit>> adStartObservable = new Subject<IObservable<Unit>>();
private IObservable<bool> vipCustomerObservable; private IObservable<CustomerType> vipCustomerObservable;
private readonly Subject<IObservable<Unit>> vipCustomerSubject = new Subject<IObservable<Unit>>(); private readonly Subject<IObservable<Unit>> vipCustomerSubject = new Subject<IObservable<Unit>>();
private IObservable<bool> tastingCustomerObservable; private IObservable<CustomerType> tastingCustomerObservable;
private static readonly float checkHeartInterval = 1f; private static readonly float checkHeartInterval = 1f;
[Header("1分間あたりの歩行者数")] [Header("1分間あたりの歩行者数")]
@ -33,7 +40,7 @@ public class CustomerFlow : MonoBehaviour
public float TastingCustomerInterval => tastingCustomerInterval; public float TastingCustomerInterval => tastingCustomerInterval;
private int adActiveCount = 0; private int adActiveCount = 0;
public IObservable<bool> Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable); public IObservable<CustomerType> Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable);
private void Awake() private void Awake()
{ {
@ -58,18 +65,18 @@ public class CustomerFlow : MonoBehaviour
.Select(customerInterval => Observable.Interval(TimeSpan.FromSeconds(customerInterval))) .Select(customerInterval => Observable.Interval(TimeSpan.FromSeconds(customerInterval)))
.Switch() .Switch()
// .Do(_ => Debug.Log($"customer:{GetHashCode()}")) // .Do(_ => Debug.Log($"customer:{GetHashCode()}"))
.Select(_ => true); .Select(_ => CustomerType.Customer);
// 歩行者出現頻度、立ち止まり確率も設定(歩行者タイマー1分間に6人 // 歩行者出現頻度、立ち止まり確率も設定(歩行者タイマー1分間に6人
walkerObservable = Observable.Interval(TimeSpan.FromSeconds(walkerInterval)) walkerObservable = Observable.Interval(TimeSpan.FromSeconds(walkerInterval))
// .Do(l => Debug.Log($"walker:{GetHashCode()}")) // .Do(l => Debug.Log($"walker:{GetHashCode()}"))
.Select(x => false); .Select(_ => CustomerType.Walker);
// 宣伝時、タップすると60秒だけ稼働するストリーム // 宣伝時、タップすると60秒だけ稼働するストリーム
adWalkerObservable = adStartObservable adWalkerObservable = adStartObservable
.Switch() .Switch()
// .Do(_ => Debug.Log($"adWalker:{GetHashCode()}")) // .Do(_ => Debug.Log($"adWalker:{GetHashCode()}"))
.Select(_ => false); .Select(_ => CustomerType.Walker);
#if DEVELOPMENT_BUILD || UNITY_EDITOR #if DEVELOPMENT_BUILD || UNITY_EDITOR
if (UsayaStorageManager.LoadOrDefault(UsayaStorageFilename.Settings_Data, "DebugManyWalker", false)) if (UsayaStorageManager.LoadOrDefault(UsayaStorageFilename.Settings_Data, "DebugManyWalker", false))
{ {
@ -80,7 +87,7 @@ public class CustomerFlow : MonoBehaviour
// VIP宣伝 // VIP宣伝
vipCustomerObservable = vipCustomerSubject vipCustomerObservable = vipCustomerSubject
.Switch() .Switch()
.Select(_ => true); .Select(_ => CustomerType.Vip);
// 試食 // 試食
// tastingCustomerInterval毎にTastingCountを確認 // tastingCustomerInterval毎にTastingCountを確認
@ -97,7 +104,7 @@ public class CustomerFlow : MonoBehaviour
}); });
tastingCustomerObservable = tastingTimer tastingCustomerObservable = tastingTimer
// .Do(_ => Debug.Log($"tastingCustomer remain:{GameDataManager.GameData.TastingCount}")) // .Do(_ => Debug.Log($"tastingCustomer remain:{GameDataManager.GameData.TastingCount}"))
.Select(_ => true); .Select(_ => CustomerType.Customer);
} }
public void StartAdWalker(Action onComplete = null) public void StartAdWalker(Action onComplete = null)

View File

@ -1,5 +1,7 @@
using System;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
namespace MyGame.Scenes.marketing.Scripts namespace MyGame.Scenes.marketing.Scripts
{ {
@ -18,13 +20,19 @@ namespace MyGame.Scenes.marketing.Scripts
(0, 5f), (0, 5f),
}; };
public (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer) public (bool isSpecial, int orderCount) GetCustomerData (CustomerType customerType)
{ {
var specialRate = isCustomer ? walkerSpecialRate : customerSpecialRate; switch (customerType)
var isSpecial = Random.value < specialRate; {
case CustomerType.Walker:
// セレブは5個購入固定 return Random.value < walkerSpecialRate ? (true, specialOrderCount) : (false, GetOrderCount());
return isSpecial ? (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);
}
} }
// お客さん出現パターン確率計算と行動パターン計算 // お客さん出現パターン確率計算と行動パターン計算

View File

@ -285,7 +285,7 @@ public class Market : SingletonMonoBehaviour<Market>
}).AddTo(this); }).AddTo(this);
// 客湧き // 客湧き
customerFlow.Flow.Subscribe(isCustomer => customerFlow.Flow.Subscribe(customerType =>
{ {
if (IsPause.Value) if (IsPause.Value)
{ {
@ -298,17 +298,32 @@ public class Market : SingletonMonoBehaviour<Market>
return; return;
} }
// 一般客orセレブ // 一般客orセレブ
var (isSpecial, orderCount) = GetCustomerData(isCustomer); CustomerState customerState;
// 複数パターンある場合ChooseRandom switch (customerType)
var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab(); {
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(); var customerController = SpawnCustomer();
customerController.Setup(orderPosisionObject.transform.GetComponentsInChildren<Transform>().ToList().Skip(1).ToList()); customerController.Setup(orderPosisionObject.transform.GetComponentsInChildren<Transform>().ToList().Skip(1).ToList());
customerController.ChangeCustomerState(customerState);
// 複数パターンある場合ChooseRandom
customerController.CustomerPrefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab();
customerController.OrderCount = orderCount; customerController.OrderCount = orderCount;
customerController.CustomerPrefab = prefab;
customerControllerList.Add(customerController); customerControllerList.Add(customerController);
customerController.ChangeCustomerState(isCustomer ? CustomerState.WalkShop : CustomerState.Walk);
customerController.TappedObservable customerController.TappedObservable
.Take(1) .Take(1)
.Subscribe(_ => .Subscribe(_ =>
@ -355,9 +370,9 @@ public class Market : SingletonMonoBehaviour<Market>
} }
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() private CustomerController SpawnCustomer()