タップされたら購入に向かう処理を修正
This commit is contained in:
parent
aeae4ad8f6
commit
99f11ac6dc
|
|
@ -21,6 +21,7 @@ public enum CustomerMovingType
|
||||||
public enum CustomerState
|
public enum CustomerState
|
||||||
{
|
{
|
||||||
Walk,
|
Walk,
|
||||||
|
WalkShop,
|
||||||
Wait,
|
Wait,
|
||||||
Order,
|
Order,
|
||||||
Leave,
|
Leave,
|
||||||
|
|
@ -68,6 +69,7 @@ public class CustomerController : MonoBehaviour
|
||||||
private Vector3 beginPos;
|
private Vector3 beginPos;
|
||||||
private Vector3 wayPoint;
|
private Vector3 wayPoint;
|
||||||
private CustomerMovingType currentMovingType;
|
private CustomerMovingType currentMovingType;
|
||||||
|
private bool isMoveOverride;
|
||||||
private List<(CustomerMovingType type, float duration)> moves = new List<(CustomerMovingType, float)>();
|
private List<(CustomerMovingType type, float duration)> moves = new List<(CustomerMovingType, float)>();
|
||||||
private float speed = 0f;
|
private float speed = 0f;
|
||||||
private float completedDuration;
|
private float completedDuration;
|
||||||
|
|
@ -96,8 +98,12 @@ public class CustomerController : MonoBehaviour
|
||||||
durationDelta += Time.deltaTime;
|
durationDelta += Time.deltaTime;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
durationDelta = 0f;
|
|
||||||
moveEndSubject.Value = currentMovingType;
|
moveEndSubject.Value = currentMovingType;
|
||||||
|
if (isMoveOverride)
|
||||||
|
{
|
||||||
|
isMoveOverride = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (moves.Count > 0)
|
if (moves.Count > 0)
|
||||||
{
|
{
|
||||||
var move = moves[0];
|
var move = moves[0];
|
||||||
|
|
@ -115,7 +121,9 @@ public class CustomerController : MonoBehaviour
|
||||||
beginPos.x = leftEndPosision * walkSideDirection;
|
beginPos.x = leftEndPosision * walkSideDirection;
|
||||||
beginPos.y = Random.Range(walkSideMidPos, walkSideBottomPos);
|
beginPos.y = Random.Range(walkSideMidPos, walkSideBottomPos);
|
||||||
transform.localPosition = beginPos;
|
transform.localPosition = beginPos;
|
||||||
currentMovingType = CustomerMovingType.StayBackOrder;
|
currentMovingType = CustomerMovingType.StayBack;
|
||||||
|
moveEndSubject.Value = CustomerMovingType.StayBack;
|
||||||
|
isMoveOverride = false;
|
||||||
SetWayPoint(beginPos);
|
SetWayPoint(beginPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,25 +134,19 @@ public class CustomerController : MonoBehaviour
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case CustomerState.Walk:
|
case CustomerState.Walk:
|
||||||
SetMove(CustomerMovingType.WalkCenter);
|
ForceSetMove(CustomerMovingType.WalkCenter);
|
||||||
// 数秒立ち止まる
|
// 数秒立ち止まる
|
||||||
AddMove(CustomerMovingType.StayBack, 2f);
|
AddMove(CustomerMovingType.StayBack, 2f);
|
||||||
AddMove(CustomerMovingType.WalkSide);
|
AddMove(CustomerMovingType.WalkSide);
|
||||||
break;
|
break;
|
||||||
|
case CustomerState.WalkShop:
|
||||||
|
ForceSetMove(CustomerMovingType.WalkCenter);
|
||||||
|
break;
|
||||||
case CustomerState.Wait:
|
case CustomerState.Wait:
|
||||||
// 店に向かう&順番待ち
|
// 店に向かう&順番待ち
|
||||||
// 近くの場合その場に待機
|
// 近くの場合その場に待機
|
||||||
// まだ遠い場合待機場所に移動
|
// まだ遠い場合待機場所に移動
|
||||||
moves.Clear();
|
ForceSetMove(CustomerMovingType.WalkBackHalf);
|
||||||
if (currentMovingType == CustomerMovingType.StayBack)
|
|
||||||
{
|
|
||||||
SetMove(CustomerMovingType.WalkBackHalf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetMove(CustomerMovingType.WalkCenter);
|
|
||||||
AddMove(CustomerMovingType.WalkBackHalf);
|
|
||||||
}
|
|
||||||
AddMove(CustomerMovingType.StayBack);
|
AddMove(CustomerMovingType.StayBack);
|
||||||
break;
|
break;
|
||||||
case CustomerState.Order:
|
case CustomerState.Order:
|
||||||
|
|
@ -153,8 +155,7 @@ public class CustomerController : MonoBehaviour
|
||||||
AddMove(CustomerMovingType.StayBackOrder);
|
AddMove(CustomerMovingType.StayBackOrder);
|
||||||
break;
|
break;
|
||||||
case CustomerState.Leave:
|
case CustomerState.Leave:
|
||||||
moves.Clear();
|
ForceSetMove(CustomerMovingType.WalkSide);
|
||||||
SetMove(CustomerMovingType.WalkSide);
|
|
||||||
break;
|
break;
|
||||||
case CustomerState.EatingLeave:
|
case CustomerState.EatingLeave:
|
||||||
AddMove(CustomerMovingType.WalkFrontEat);
|
AddMove(CustomerMovingType.WalkFrontEat);
|
||||||
|
|
@ -170,6 +171,13 @@ public class CustomerController : MonoBehaviour
|
||||||
moves.Add((type, duration));
|
moves.Add((type, duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ForceSetMove(CustomerMovingType type, float duration = 0f)
|
||||||
|
{
|
||||||
|
moves.Clear();
|
||||||
|
isMoveOverride = true;
|
||||||
|
SetMove(type, duration);
|
||||||
|
}
|
||||||
|
|
||||||
// キャラの奥行き描画順のため、y方向に対応したz軸を設定
|
// キャラの奥行き描画順のため、y方向に対応したz軸を設定
|
||||||
private void SetMove(CustomerMovingType type, float duration = 0f)
|
private void SetMove(CustomerMovingType type, float duration = 0f)
|
||||||
{
|
{
|
||||||
|
|
@ -178,10 +186,11 @@ public class CustomerController : MonoBehaviour
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
completedDuration = duration;
|
completedDuration = duration;
|
||||||
|
durationDelta = 0f;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CustomerMovingType.WalkSide:
|
case CustomerMovingType.WalkSide:
|
||||||
SetWayPoint(new Vector3(-leftEndPosision * walkSideDirection, wayPoint.y));
|
SetWayPoint(new Vector3(-leftEndPosision * walkSideDirection, transform.localPosition.y));
|
||||||
speed = walkSideSpeed;
|
speed = walkSideSpeed;
|
||||||
// アニメーション違和感回避
|
// アニメーション違和感回避
|
||||||
if (currentMovingType == CustomerMovingType.WalkCenter)
|
if (currentMovingType == CustomerMovingType.WalkCenter)
|
||||||
|
|
@ -191,13 +200,11 @@ public class CustomerController : MonoBehaviour
|
||||||
animator.SetTrigger(WalkSide);
|
animator.SetTrigger(WalkSide);
|
||||||
break;
|
break;
|
||||||
case CustomerMovingType.WalkSideEat:
|
case CustomerMovingType.WalkSideEat:
|
||||||
SetWayPoint(new Vector3(-leftEndPosision * walkSideDirection, wayPoint.y));
|
SetWayPoint(new Vector3(-leftEndPosision * walkSideDirection, transform.localPosition.y));
|
||||||
speed = walkSideSpeed;
|
speed = walkSideSpeed;
|
||||||
animator.SetTrigger(WalkSideEat);
|
animator.SetTrigger(WalkSideEat);
|
||||||
break;
|
break;
|
||||||
case CustomerMovingType.WalkCenter:
|
case CustomerMovingType.WalkCenter:
|
||||||
// 通り過ぎた人はwalkSideDirection基準にするとあるき過ぎるので改善したい
|
|
||||||
// 立ち止まったあと戻ってしまう場合があるので、中央付近だと戻りがないようにする
|
|
||||||
if (Mathf.Abs(transform.localPosition.x - stopPosision) <= stopPositionRange)
|
if (Mathf.Abs(transform.localPosition.x - stopPosision) <= stopPositionRange)
|
||||||
{
|
{
|
||||||
SetWayPoint(new Vector3(transform.localPosition.x, beginPos.y));
|
SetWayPoint(new Vector3(transform.localPosition.x, beginPos.y));
|
||||||
|
|
@ -224,18 +231,25 @@ public class CustomerController : MonoBehaviour
|
||||||
animator.SetTrigger(StayBack);
|
animator.SetTrigger(StayBack);
|
||||||
break;
|
break;
|
||||||
case CustomerMovingType.WalkBack:
|
case CustomerMovingType.WalkBack:
|
||||||
|
// 購入場所に行く
|
||||||
SetWayPoint(new Vector3(Random.value * orderPositionRange * walkSideDirection, orderPosision));
|
SetWayPoint(new Vector3(Random.value * orderPositionRange * walkSideDirection, orderPosision));
|
||||||
speed = walkFrontBackSpeed;
|
speed = walkFrontBackSpeed;
|
||||||
animator.SetTrigger(WalkBack);
|
animator.SetTrigger(WalkBack);
|
||||||
break;
|
break;
|
||||||
case CustomerMovingType.WalkBackHalf:
|
case CustomerMovingType.WalkBackHalf:
|
||||||
// 待機列に入る
|
// 待機列に入る
|
||||||
SetWayPoint(new Vector3(wayPoint.x, waitOrderPosision));
|
if (Mathf.Abs(transform.localPosition.x - stopPosision) <= stopPositionRange)
|
||||||
|
{
|
||||||
|
SetWayPoint(new Vector3(transform.localPosition.x, waitOrderPosision));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWayPoint(new Vector3(stopPosision - Random.value * stopPositionRange * walkSideDirection, waitOrderPosision));
|
||||||
|
}
|
||||||
speed = walkFrontBackSpeed;
|
speed = walkFrontBackSpeed;
|
||||||
animator.SetTrigger(WalkBack);
|
animator.SetTrigger(WalkBack);
|
||||||
break;
|
break;
|
||||||
case CustomerMovingType.WalkFront:
|
case CustomerMovingType.WalkFront:
|
||||||
// 購入場所に行く
|
|
||||||
SetWayPoint(new Vector3(wayPoint.x, Random.Range(walkSideLeavePos, walkSideTopPosition)));
|
SetWayPoint(new Vector3(wayPoint.x, Random.Range(walkSideLeavePos, walkSideTopPosition)));
|
||||||
speed = walkFrontBackSpeed;
|
speed = walkFrontBackSpeed;
|
||||||
animator.SetTrigger(WalkFront);
|
animator.SetTrigger(WalkFront);
|
||||||
|
|
|
||||||
|
|
@ -115,38 +115,31 @@ public class Market : MonoBehaviour
|
||||||
.Select(x => x.Value)
|
.Select(x => x.Value)
|
||||||
.Subscribe(customerController =>
|
.Subscribe(customerController =>
|
||||||
{
|
{
|
||||||
customerController.State.Subscribe(c =>
|
customerController.State
|
||||||
{
|
.Where(x => x == CustomerState.EatingLeave)
|
||||||
if (c == CustomerState.EatingLeave)
|
.Subscribe(c =>
|
||||||
{
|
{
|
||||||
Debug.Log($"aa order:{customerList.Count(x => x.State.Value == CustomerState.Order)} EatingLeave");
|
Debug.Log($"aa order:{customerList.Count(x => x.State.Value == CustomerState.Order)} EatingLeave");
|
||||||
orderSubject.OnNext(default);
|
orderSubject.OnNext(default);
|
||||||
}
|
}).AddTo(customerController);
|
||||||
}).AddTo(customerController);
|
if (shopState.Value == ShopState.Close)
|
||||||
|
{
|
||||||
|
customerController.ChangeCustomerState(CustomerState.Leave);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 店に向かう
|
// 店に向かう
|
||||||
customerController.ChangeCustomerState(CustomerState.Wait);
|
customerController.ChangeCustomerState(CustomerState.Wait);
|
||||||
shopState.Subscribe(x =>
|
shopState
|
||||||
{
|
.Where(x => x == ShopState.Close)
|
||||||
switch (x)
|
.Subscribe(x =>
|
||||||
{
|
{
|
||||||
case ShopState.Open:
|
// 売り切れの場合帰る
|
||||||
case ShopState.Busy:
|
if (customerController.State.Value == CustomerState.Order)
|
||||||
break;
|
{
|
||||||
case ShopState.Close:
|
return;
|
||||||
// 売り切れの場合帰る
|
}
|
||||||
if (customerController.State.Value == CustomerState.Order)
|
customerController.ChangeCustomerState(CustomerState.Leave);
|
||||||
{
|
}).AddTo(customerController);
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.CallWaitForSeconds(Random.Range(0f, .4f), () =>
|
|
||||||
{
|
|
||||||
customerController.ChangeCustomerState(CustomerState.Leave);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(x), x, null);
|
|
||||||
}
|
|
||||||
}).AddTo(customerController);
|
|
||||||
}).AddTo(this);
|
}).AddTo(this);
|
||||||
|
|
||||||
requestSubject.BatchFrame().Subscribe(customers =>
|
requestSubject.BatchFrame().Subscribe(customers =>
|
||||||
|
|
@ -356,6 +349,16 @@ public class Market : MonoBehaviour
|
||||||
customerList.Remove(customerController);
|
customerList.Remove(customerController);
|
||||||
Destroy(customer);
|
Destroy(customer);
|
||||||
break;
|
break;
|
||||||
|
case CustomerMovingType.WalkCenter:
|
||||||
|
if (shopState.Value == ShopState.Close)
|
||||||
|
{
|
||||||
|
customerController.ChangeCustomerState(CustomerState.Leave);
|
||||||
|
}
|
||||||
|
if (customerController.State.Value == CustomerState.WalkShop)
|
||||||
|
{
|
||||||
|
customerList.Add(customerController);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case CustomerMovingType.WalkBackHalf:
|
case CustomerMovingType.WalkBackHalf:
|
||||||
waitCustomerList.Add(customerController);
|
waitCustomerList.Add(customerController);
|
||||||
break;
|
break;
|
||||||
|
|
@ -368,20 +371,27 @@ public class Market : MonoBehaviour
|
||||||
}).AddTo(customerController);
|
}).AddTo(customerController);
|
||||||
|
|
||||||
var customerObject = customer.transform.GetChild(0).gameObject;
|
var customerObject = customer.transform.GetChild(0).gameObject;
|
||||||
|
var eventTrigger = customerObject.AddComponent<ObservableEventTrigger>();
|
||||||
if (x.isCustomer)
|
if (x.isCustomer)
|
||||||
{
|
{
|
||||||
// 購入客リスト追加
|
// 近くまで歩く(タップされたらcustomerList.Add()
|
||||||
customerList.Add(customerController);
|
customerController.ChangeCustomerState(CustomerState.WalkShop);
|
||||||
if (customerObject.TryGetComponent(typeof(Collider2D), out var target))
|
eventTrigger.OnPointerClickAsObservable()
|
||||||
{
|
.TakeUntil(customerController.MoveEndObservable.Where(type => type == CustomerMovingType.WalkCenter))
|
||||||
Destroy(target);
|
.Take(1)
|
||||||
}
|
.Subscribe(_ =>
|
||||||
|
{
|
||||||
|
customerList.Add(customerController);
|
||||||
|
if (customerObject.TryGetComponent(typeof(Collider2D), out var target))
|
||||||
|
{
|
||||||
|
Destroy(target);
|
||||||
|
}
|
||||||
|
}).AddTo(customerController);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 歩行者はタップ後購入客
|
// 歩行者はタップ後customerList.Add()
|
||||||
customerController.ChangeCustomerState(CustomerState.Walk);
|
customerController.ChangeCustomerState(CustomerState.Walk);
|
||||||
var eventTrigger = customerObject.AddComponent<ObservableEventTrigger>();
|
|
||||||
eventTrigger.OnPointerClickAsObservable().Take(1).Subscribe(_ =>
|
eventTrigger.OnPointerClickAsObservable().Take(1).Subscribe(_ =>
|
||||||
{
|
{
|
||||||
customerList.Add(customerController);
|
customerList.Add(customerController);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue