複数お客さんタイプに対応
This commit is contained in:
parent
e6ffd80e7a
commit
86baca721c
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -3,15 +3,22 @@ using System.Linq;
|
|||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public enum CustomerType
|
||||
{
|
||||
Walker,
|
||||
Customer,
|
||||
Vip
|
||||
}
|
||||
|
||||
public class CustomerFlow : MonoBehaviour
|
||||
{
|
||||
private IObservable<bool> customerObservable;
|
||||
private IObservable<bool> walkerObservable;
|
||||
private IObservable<bool> adWalkerObservable;
|
||||
private IObservable<CustomerType> customerObservable;
|
||||
private IObservable<CustomerType> walkerObservable;
|
||||
private IObservable<CustomerType> adWalkerObservable;
|
||||
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 IObservable<bool> tastingCustomerObservable;
|
||||
private IObservable<CustomerType> 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<bool> Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable);
|
||||
public IObservable<CustomerType> 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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
// お客さん出現パターン確率計算と行動パターン計算
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
}).AddTo(this);
|
||||
|
||||
// 客湧き
|
||||
customerFlow.Flow.Subscribe(isCustomer =>
|
||||
customerFlow.Flow.Subscribe(customerType =>
|
||||
{
|
||||
if (IsPause.Value)
|
||||
{
|
||||
|
|
@ -298,17 +298,32 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
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<Transform>().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<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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue