販売にお客さんの動きを対応

This commit is contained in:
kimura 2021-08-26 16:54:41 +09:00
parent bed3d85a7c
commit 5a351d60c6
5 changed files with 315 additions and 101 deletions

View File

@ -121,6 +121,31 @@ AnimatorStateMachine:
m_ExitPosition: {x: 800, y: 120, z: 0} m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 0} m_DefaultState: {fileID: 0}
--- !u!1101 &-3061360668537635468
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: StayBackLook
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -4685533525633903185}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &-2685166620078894664 --- !u!1102 &-2685166620078894664
AnimatorState: AnimatorState:
serializedVersion: 5 serializedVersion: 5
@ -161,37 +186,43 @@ AnimatorController:
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
- m_Name: WalkSide - m_Name: WalkSide
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
- m_Name: WalkBack - m_Name: WalkBack
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
- m_Name: StayBackLook
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
- m_Name: StayBack - m_Name: StayBack
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
- m_Name: WalkFrontEat - m_Name: WalkFrontEat
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
- m_Name: WalkSideEat - m_Name: WalkSideEat
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer
@ -292,13 +323,13 @@ AnimatorStateMachine:
m_ChildStates: m_ChildStates:
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 7772821984771188997} m_State: {fileID: 7772821984771188997}
m_Position: {x: 290, y: -70, z: 0} m_Position: {x: 270, y: -120, z: 0}
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 1218383692422006508} m_State: {fileID: 1218383692422006508}
m_Position: {x: 330, y: 0, z: 0} m_Position: {x: 310, y: -50, z: 0}
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 6151281156751506126} m_State: {fileID: 6151281156751506126}
m_Position: {x: 360, y: 60, z: 0} m_Position: {x: 340, y: 10, z: 0}
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: -6652428263484434225} m_State: {fileID: -6652428263484434225}
m_Position: {x: 400, y: 130, z: 0} m_Position: {x: 400, y: 130, z: 0}
@ -313,7 +344,7 @@ AnimatorStateMachine:
m_Position: {x: 310, y: 330, z: 0} m_Position: {x: 310, y: 330, z: 0}
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: -4685533525633903185} m_State: {fileID: -4685533525633903185}
m_Position: {x: 345, y: 395, z: 0} m_Position: {x: 370, y: 70, z: 0}
m_ChildStateMachines: [] m_ChildStateMachines: []
m_AnyStateTransitions: m_AnyStateTransitions:
- {fileID: 3241850798776372350} - {fileID: 3241850798776372350}
@ -322,6 +353,7 @@ AnimatorStateMachine:
- {fileID: 6505056884794429815} - {fileID: 6505056884794429815}
- {fileID: 8021089965930707737} - {fileID: 8021089965930707737}
- {fileID: -6933872665675759000} - {fileID: -6933872665675759000}
- {fileID: -3061360668537635468}
m_EntryTransitions: [] m_EntryTransitions: []
m_StateMachineTransitions: {} m_StateMachineTransitions: {}
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []

View File

@ -45,11 +45,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3aa8dec9a88540bf93de4c93663335ec, type: 3} m_Script: {fileID: 11500000, guid: 3aa8dec9a88540bf93de4c93663335ec, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
animator: {fileID: 5409985851491668857}
leftPopcorn: {fileID: 1950136324582499262}
rightPopcorn: {fileID: 1950136324150437342}
frontPopcorn: {fileID: 1950136324089803489}
wantFlavorSprite: {fileID: 5409985849570169883}
defaultSprite: {fileID: 21300000, guid: 99d426990eeb08d4d85ae03f04609196, type: 3}
caramelSprite: {fileID: 21300000, guid: 469b78432f101024aa1a2060a57231d8, type: 3}
walkSideTopPos: -1.55 walkSideTopPos: -1.55
walkSideBottomPos: -6.5 walkSideBottomPos: -6.5
stopPosision: 0
stopPositionRange: 2
orderStayPositions: []
orderPosision: 0.5
waitOrderPosision: -0.6
walkSideSpeed: 1.3 walkSideSpeed: 1.3
walkFrontSpeed: 1 walkFrontBackSpeed: 1
animator: {fileID: 5409985851491668857}
--- !u!114 &1385243083193661112 --- !u!114 &1385243083193661112
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -62,7 +73,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 786931d1da2c4b1c8ce9519c9b3c32fd, type: 3} m_Script: {fileID: 11500000, guid: 786931d1da2c4b1c8ce9519c9b3c32fd, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
animator: {fileID: 0} heart: {fileID: 0}
target: {fileID: 0}
--- !u!1001 &631677504613307640 --- !u!1001 &631677504613307640
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -140,6 +152,16 @@ PrefabInstance:
propertyPath: m_IsActive propertyPath: m_IsActive
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8422870931014696725, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8422870931732035957, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: db654393793a67d45a7d0b70a68b73a6, type: 3} m_SourcePrefab: {fileID: 100100000, guid: db654393793a67d45a7d0b70a68b73a6, type: 3}
--- !u!4 &5409985851491668856 stripped --- !u!4 &5409985851491668856 stripped
@ -154,3 +176,27 @@ Animator:
type: 3} type: 3}
m_PrefabInstance: {fileID: 631677504613307640} m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!212 &1950136324089803489 stripped
SpriteRenderer:
m_CorrespondingSourceObject: {fileID: 1428887861354145305, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0}
--- !u!212 &5409985849570169883 stripped
SpriteRenderer:
m_CorrespondingSourceObject: {fileID: 4886416730275037411, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0}
--- !u!212 &1950136324150437342 stripped
SpriteRenderer:
m_CorrespondingSourceObject: {fileID: 1428887861146841382, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0}
--- !u!212 &1950136324582499262 stripped
SpriteRenderer:
m_CorrespondingSourceObject: {fileID: 1428887860706522950, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0}

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic;
using UniRx; using UniRx;
using UniRx.Triggers; using UniRx.Triggers;
using UnityEditor.UIElements;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
@ -10,9 +10,12 @@ public enum CustomerMovingType
WalkFront, WalkFront,
WalkSide, WalkSide,
WalkBack, WalkBack,
WalkBackHalf,
StayBack, StayBack,
StayBackLook,
WalkFrontEat, WalkFrontEat,
WalkSideEat, WalkSideEat,
WalkCenter,
} }
public class CustomerController : MonoBehaviour public class CustomerController : MonoBehaviour
{ {
@ -20,68 +23,144 @@ public class CustomerController : MonoBehaviour
private static readonly int WalkSide = Animator.StringToHash("WalkSide"); private static readonly int WalkSide = Animator.StringToHash("WalkSide");
private static readonly int WalkBack = Animator.StringToHash("WalkBack"); private static readonly int WalkBack = Animator.StringToHash("WalkBack");
private static readonly int StayBack = Animator.StringToHash("StayBack"); private static readonly int StayBack = Animator.StringToHash("StayBack");
private static readonly int StayBackLook = Animator.StringToHash("StayBackLook");
private static readonly int WalkFrontEat = Animator.StringToHash("WalkFrontEat"); private static readonly int WalkFrontEat = Animator.StringToHash("WalkFrontEat");
private static readonly int WalkSideEat = Animator.StringToHash("WalkSideEat"); private static readonly int WalkSideEat = Animator.StringToHash("WalkSideEat");
// 画面端 [SerializeField] private Animator animator;
private float leftEndPosision = -10f;
[SerializeField] private SpriteRenderer leftPopcorn;
[SerializeField] private SpriteRenderer rightPopcorn;
[SerializeField] private SpriteRenderer frontPopcorn;
[SerializeField] private SpriteRenderer wantFlavorSprite;
[SerializeField] private Sprite defaultSprite;
[SerializeField] private Sprite caramelSprite;
// 歩道の幅(min,max) // 歩道の幅(min,max)
[SerializeField] private float walkSideTopPos = -1.55f; [SerializeField] private float walkSideTopPos = -1.55f;
[SerializeField] private float walkSideBottomPos = -6.50f; [SerializeField] private float walkSideBottomPos = -6.50f;
// 立ち止まる範囲
[SerializeField] private float stopPosision = 0f;
[SerializeField] private float stopPositionRange = 2f;
// オーダー待ちは複数箇所用意
[SerializeField] private List<Transform> orderStayPositions = new List<Transform>();
// 購入ポジ
[SerializeField] private float orderPosision = .5f;
[SerializeField] private float waitOrderPosision = .2f;
// 歩行速度 // 歩行速度
[SerializeField] private float walkSideSpeed = 1.3f; // 1.3f [SerializeField] private float walkSideSpeed = 1.3f; // 1.3f
[SerializeField] private float walkFrontSpeed = 1.0f; // 1.0f [SerializeField] private float walkFrontBackSpeed = 1.0f; // 1.0f
private Vector3 speed = Vector3.zero; private float speed = 0f;
private Vector3 beginPos;
private Vector3 wayPoint;
private List<CustomerMovingType> moves = new List<CustomerMovingType>();
private static readonly float leftEndPosision = -10f;
// 停止時間 // 停止時間
// 左右どちらから出るか // 左右どちらから出るか
private Subject<Unit> orderSubject = new Subject<Unit>();
public IObservable<Unit> OrderObservable => orderSubject;
[SerializeField] private Animator animator;
private void Start() private void Start()
{ {
this.UpdateAsObservable().Subscribe(_ => this.UpdateAsObservable().Subscribe(_ =>
{ {
transform.localPosition += speed * Time.deltaTime; transform.localPosition = Vector3.MoveTowards(transform.localPosition, wayPoint, speed * Time.deltaTime);
if (Vector3.Distance(transform.localPosition, wayPoint) < .01f)
{
if (moves.Count > 0)
{
SetMove(moves[0]);
moves.RemoveAt(0);
}
}
}).AddTo(this); }).AddTo(this);
} }
public void Setup() public void Setup()
{ {
var tmpPos = Vector3.zero; beginPos = Vector3.zero;
tmpPos.x = leftEndPosision; beginPos.x = leftEndPosision;
tmpPos.y = Random.Range(walkSideTopPos, walkSideBottomPos); beginPos.y = Random.Range(walkSideTopPos, walkSideBottomPos);
transform.localPosition = tmpPos; transform.localPosition = beginPos;
wayPoint = beginPos;
} }
public void SetMove(CustomerMovingType type) public void AddMove(CustomerMovingType type)
{
moves.Add(type);
}
private void SetMove(CustomerMovingType type)
{ {
switch (type) switch (type)
{ {
case CustomerMovingType.WalkFront: case CustomerMovingType.WalkFront:
wayPoint = Vector3.zero + Vector3.up * beginPos.y;
speed = walkFrontBackSpeed;
animator.SetTrigger(WalkFront); animator.SetTrigger(WalkFront);
break; break;
case CustomerMovingType.WalkSide: case CustomerMovingType.WalkSide:
speed = Vector3.right * walkSideSpeed; wayPoint = beginPos + Vector3.right * -leftEndPosision * 2;
speed = walkSideSpeed;
animator.SetTrigger(WalkSide); animator.SetTrigger(WalkSide);
break; break;
case CustomerMovingType.WalkBack: case CustomerMovingType.WalkBack:
wayPoint = Vector3.zero + Vector3.up * orderPosision;
speed = walkFrontBackSpeed;
animator.SetTrigger(WalkBack);
break;
case CustomerMovingType.WalkBackHalf:
wayPoint = new Vector3(stopPosision + (Random.value - .5f) * 2 * stopPositionRange, waitOrderPosision);
speed = walkFrontBackSpeed;
animator.SetTrigger(WalkBack); animator.SetTrigger(WalkBack);
break; break;
case CustomerMovingType.StayBack: case CustomerMovingType.StayBack:
speed = Vector3.zero; speed = 0f;
animator.SetTrigger(StayBack); animator.SetTrigger(StayBack);
orderSubject.OnNext(Unit.Default);
break;
case CustomerMovingType.StayBackLook:
speed = 0f;
animator.SetTrigger(StayBackLook);
break; break;
case CustomerMovingType.WalkFrontEat: case CustomerMovingType.WalkFrontEat:
wayPoint = Vector3.zero + Vector3.up * beginPos.y;
speed = walkFrontBackSpeed;
animator.SetTrigger(WalkFrontEat); animator.SetTrigger(WalkFrontEat);
break; break;
case CustomerMovingType.WalkSideEat: case CustomerMovingType.WalkSideEat:
wayPoint = beginPos + Vector3.right * -leftEndPosision * 2;
speed = walkSideSpeed;
animator.SetTrigger(WalkSideEat); animator.SetTrigger(WalkSideEat);
break; break;
case CustomerMovingType.WalkCenter:
wayPoint = new Vector3(stopPosision + (Random.value - .5f) * 2 * stopPositionRange, beginPos.y);
speed = walkSideSpeed;
animator.SetTrigger(WalkSide);
break;
default: default:
throw new ArgumentOutOfRangeException(nameof(type), type, null); throw new ArgumentOutOfRangeException(nameof(type), type, null);
} }
} }
public void ChangeWantFlavor(int flavor)
{
if (flavor == 2)
{
leftPopcorn.sprite = caramelSprite;
rightPopcorn.sprite = caramelSprite;
frontPopcorn.sprite = caramelSprite;
wantFlavorSprite.sprite = caramelSprite;
}
else
{
leftPopcorn.sprite = defaultSprite;
rightPopcorn.sprite = defaultSprite;
frontPopcorn.sprite = defaultSprite;
wantFlavorSprite.sprite = defaultSprite;
}
}
public void SetCustomerType() public void SetCustomerType()
{ {

View File

@ -12,108 +12,150 @@ public class Market : MonoBehaviour
[SerializeField] private ShopStockView stockView; [SerializeField] private ShopStockView stockView;
[SerializeField] private MarketCartView cartView; [SerializeField] private MarketCartView cartView;
[SerializeField] private BrotherBlueView blueView;
[SerializeField] private GameObject customerPrefab; [SerializeField] private GameObject customerPrefab;
private readonly List<RecipeData> allRecipe = RecipeData.GetAllRecipe();
private List<int> displayFlavors;
private List<int> shuffledOrder;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
var gameData = GameDataManager.GameData; var gameData = GameDataManager.GameData;
CoinManager.Instance.ChangeCoin(gameData.coin); CoinManager.Instance.ChangeCoin(gameData.coin);
// 全レシピ
var allRecipe = RecipeData.GetAllRecipe();
// 在庫数表示 // 在庫数表示
stockView.SetStock(gameData.StorageTanks); stockView.SetStock(gameData.StorageTanks);
StockFlavorLog(); StockFlavorLog();
// 陳列 // 陳列
var displayFlavors = gameData.ShopStock.Select(x => x).ToList(); displayFlavors = gameData.ShopStock.Select(x => x).ToList();
cartView.SetStock(displayFlavors); cartView.SetStock(displayFlavors);
// 売り順決定 // 売り順決定
var shuffledOrder = ShuffleOrder(displayFlavors.Count); shuffledOrder = ShuffleOrder(displayFlavors.Count);
// お客さん出現パターン確率計算と行動パターン計算 // お客さん出現パターン確率計算と行動パターン計算
Observable.Interval(TimeSpan.FromSeconds(.5f)).Take(5).Subscribe(_ =>
{
var customer = Instantiate(customerPrefab);
var customerController = customer.GetComponent<CustomerController>();
customerController.SetMove(CustomerMovingType.WalkSide);
customerController.Setup();
var heartAnimation = customer.GetComponent<HeartAnimation>();
Observable.Timer(TimeSpan.FromSeconds(2f)).Subscribe(__ =>
{
heartAnimation.GetHeart();
});
}).AddTo(this);
// お客さんの出現タイミング(10秒間に回) var customerObservable = Observable.Interval(TimeSpan.FromSeconds(60f)).Select(_ =>
Observable.Timer(TimeSpan.FromSeconds(2f), TimeSpan.FromSeconds(10f)) {
return 0;
});
var walkerObservable = Observable.Timer(TimeSpan.FromSeconds(2f), TimeSpan.FromSeconds(5f))
.Select(x =>
{
return 0;
});
Observable.Merge(customerObservable, walkerObservable)
// .Take(5)
.Subscribe(_ => .Subscribe(_ =>
{ {
// 品切れ var customer = Instantiate(customerPrefab);
if (gameData.ShopStock.Count == 0) var heartAnimation = customer.GetComponent<HeartAnimation>();
var customerController = customer.GetComponent<CustomerController>();
customerController.Setup();
if (Random.value < .4f)
{ {
return; customerController.AddMove(CustomerMovingType.WalkSide);
} }
// shuffledOrder順に販売 else
var orderNum = shuffledOrder[0];
shuffledOrder.RemoveAt(0);
var targetFlavorId = displayFlavors[orderNum];
Debug.Log($"sell:{orderNum} flavor:{targetFlavorId} {shuffledOrder.Count}");
cartView.SellStock(orderNum);
var targetIndex = gameData.ShopStock.FindIndex(x => x == targetFlavorId);
var stockData = gameData.ShopStock[targetIndex];
gameData.ShopStock.RemoveAt(targetIndex);
// コイン獲得
var bonusRate = 0;
var flavor = allRecipe.First(x => x.RecipeId == stockData);
CoinManager.Instance.AddCoinWithEffect(flavor.Price * (1 + bonusRate / 100), () => { });
gameData.coin = CoinManager.Instance.OwnCoin;
GameDataManager.SaveGameData();
// 自動補充 refill
RefillOneProduct();
var setStockFlag = false;
// 補充された場合フレーバー再設定
if (gameData.ShopStock.Count == ShopStockCount)
{ {
shuffledOrder.Add(orderNum); customerController.AddMove(CustomerMovingType.WalkCenter);
displayFlavors[orderNum] = gameData.ShopStock.Last(); customerController.AddMove(CustomerMovingType.WalkBack);
customerController.AddMove(CustomerMovingType.StayBack);
} }
else if (gameData.ShopStock.Count <= 13 && shuffledOrder.Exists(x => x > 13)) customerController.OrderObservable.Subscribe(__ =>
{ {
displayFlavors = gameData.ShopStock.Select(x => x).ToList(); // 購入
shuffledOrder = ShuffleOrder(displayFlavors.Count); if (gameData.ShopStock.Count == 0)
setStockFlag = true;
}
else if (gameData.ShopStock.Count <= 7 && shuffledOrder.Exists(x => x > 7))
{
displayFlavors = gameData.ShopStock.Select(x => x).ToList();
shuffledOrder = ShuffleOrder(displayFlavors.Count);
setStockFlag = true;
}
// 表示更新
this.CallWaitForSeconds(1f, () =>
{
stockView.SetStock(gameData.StorageTanks);
if (gameData.ShopStock.Count == ShopStockCount)
{ {
// 補充したフレーバーのスキンを設定 customerController.AddMove(CustomerMovingType.WalkFront);
cartView.Refill(orderNum, displayFlavors[orderNum]); customerController.AddMove(CustomerMovingType.WalkSide);
return;
} }
else if (setStockFlag) // shuffledOrder順に販売
var orderNum = shuffledOrder[0];
shuffledOrder.RemoveAt(0);
// コーンの味吹き出しを設定
customerController.ChangeWantFlavor(displayFlavors[orderNum]);
this.CallWaitForSeconds(2f, () =>
{ {
cartView.SetStock(displayFlavors); SellPopcorn(orderNum);
} blueView.SellAction();
this.CallWaitForSeconds(2f, () =>
{
heartAnimation.GetHeart();
customerController.AddMove(CustomerMovingType.WalkFrontEat);
customerController.AddMove(CustomerMovingType.WalkSideEat);
});
});
}); });
StockFlavorLog();
}).AddTo(this); }).AddTo(this);
} }
private void SellPopcorn(int orderNum)
{
var gameData = GameDataManager.GameData;
// 品切れ
if (gameData.ShopStock.Count == 0)
{
return;
}
var targetFlavorId = displayFlavors[orderNum];
Debug.Log($"sell:{orderNum} flavor:{targetFlavorId} {shuffledOrder.Count}");
var targetIndex = gameData.ShopStock.FindIndex(x => x == targetFlavorId);
var stockData = gameData.ShopStock[targetIndex];
gameData.ShopStock.RemoveAt(targetIndex);
cartView.SellStock(orderNum);
// コイン獲得
var bonusRate = 0;
var flavor = allRecipe.First(x => x.RecipeId == stockData);
CoinManager.Instance.AddCoinWithEffect(flavor.Price * (1 + bonusRate / 100), () => { });
gameData.coin = CoinManager.Instance.OwnCoin;
GameDataManager.SaveGameData();
// 自動補充 refill
RefillOneProduct();
var setStockFlag = false;
// 補充された場合フレーバー再設定
if (gameData.ShopStock.Count == ShopStockCount)
{
shuffledOrder.Add(orderNum);
displayFlavors[orderNum] = gameData.ShopStock.Last();
}
else if (gameData.ShopStock.Count <= 13 && shuffledOrder.Exists(x => x > 13))
{
displayFlavors = gameData.ShopStock.Select(x => x).ToList();
shuffledOrder = ShuffleOrder(displayFlavors.Count);
setStockFlag = true;
}
else if (gameData.ShopStock.Count <= 7 && shuffledOrder.Exists(x => x > 7))
{
displayFlavors = gameData.ShopStock.Select(x => x).ToList();
shuffledOrder = ShuffleOrder(displayFlavors.Count);
setStockFlag = true;
}
// 表示更新
this.CallWaitForSeconds(1f, () =>
{
stockView.SetStock(gameData.StorageTanks);
if (gameData.ShopStock.Count == ShopStockCount)
{
// 補充したフレーバーのスキンを設定
cartView.Refill(orderNum, displayFlavors[orderNum]);
}
else if (setStockFlag)
{
cartView.SetStock(displayFlavors);
}
});
StockFlavorLog();
}
private List<int> ShuffleOrder(int length) private List<int> ShuffleOrder(int length)
{ {
return Enumerable.Range(0, length) return Enumerable.Range(0, length)

View File

@ -3000,6 +3000,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
stockView: {fileID: 438315601} stockView: {fileID: 438315601}
cartView: {fileID: 2048621276} cartView: {fileID: 2048621276}
blueView: {fileID: 1506158581}
customerPrefab: {fileID: 343963611} customerPrefab: {fileID: 343963611}
--- !u!1 &1035509476 --- !u!1 &1035509476
GameObject: GameObject:
@ -4386,6 +4387,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 1506158580} - component: {fileID: 1506158580}
- component: {fileID: 1506158581}
m_Layer: 0 m_Layer: 0
m_Name: Brother m_Name: Brother
m_TagString: Untagged m_TagString: Untagged
@ -4409,6 +4411,19 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1506158581
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1506158579}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bd193a44e53642d38087d1bc9e9d4071, type: 3}
m_Name:
m_EditorClassIdentifier:
animator: {fileID: 1178501603}
--- !u!1001 &1515102455 --- !u!1001 &1515102455
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -11546,12 +11561,12 @@ PrefabInstance:
- target: {fileID: 5409985849651702441, guid: 6fbb038c9aae840f2bea57bce30740f7, - target: {fileID: 5409985849651702441, guid: 6fbb038c9aae840f2bea57bce30740f7,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 0 value: -4.8
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5409985849651702441, guid: 6fbb038c9aae840f2bea57bce30740f7, - target: {fileID: 5409985849651702441, guid: 6fbb038c9aae840f2bea57bce30740f7,
type: 3} type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: -1.55 value: -0.02
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5409985849651702441, guid: 6fbb038c9aae840f2bea57bce30740f7, - target: {fileID: 5409985849651702441, guid: 6fbb038c9aae840f2bea57bce30740f7,
type: 3} type: 3}