販売の弟アニメーション追加
This commit is contained in:
parent
b7db2cd68f
commit
2cda06db9f
|
|
@ -52,6 +52,7 @@ AnimatorStateMachine:
|
|||
- {fileID: 5858741034395082888}
|
||||
- {fileID: 51081042415013300}
|
||||
- {fileID: 4394378192515912696}
|
||||
- {fileID: -4201787685094799525}
|
||||
m_EntryTransitions: []
|
||||
m_StateMachineTransitions: {}
|
||||
m_StateMachineBehaviours: []
|
||||
|
|
@ -112,6 +113,31 @@ AnimatorState:
|
|||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1101 &-4201787685094799525
|
||||
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: Walk
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 8708174739101812674}
|
||||
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!91 &9100000
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -126,19 +152,25 @@ AnimatorController:
|
|||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Promotion
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Sleepy
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Walk
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
|
|
|
|||
|
|
@ -1,24 +1,138 @@
|
|||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
|
||||
public class BrotherPinkView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Animator animator;
|
||||
private static readonly int Normal = Animator.StringToHash("Normal");
|
||||
private static readonly int Promotion = Animator.StringToHash("Promotion");
|
||||
private static readonly int Sleepy = Animator.StringToHash("Sleepy");
|
||||
private static readonly int Walk = Animator.StringToHash("Walk");
|
||||
private static readonly Vector2 RightPos = new Vector2(4.96f, -0.26f);
|
||||
private static readonly Vector2 LeftPos = new Vector2(-4.96f, -0.26f);
|
||||
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private Transform pinkTransform;
|
||||
[SerializeField] private float walkSideBottomPos;
|
||||
[SerializeField] private float pinkWalkSpeed = 4f;
|
||||
[SerializeField] private float coolTime = 10f;
|
||||
[SerializeField] private int fewerBorder = 5;
|
||||
|
||||
public int FewerBorder => fewerBorder;
|
||||
|
||||
private bool isManyCustomer;
|
||||
private bool isLocked;
|
||||
private int nextId;
|
||||
private readonly (int trigger, Vector2 wayPoint, float wait)[] pinkMoves =
|
||||
{
|
||||
(Walk, LeftPos, 0f),
|
||||
(Promotion, LeftPos + Vector2.right * .03f, 5.35f),
|
||||
(Walk, RightPos, 0f),
|
||||
(Promotion, RightPos + Vector2.left * .03f, 5.35f),
|
||||
};
|
||||
private int moveIndex;
|
||||
private Vector2 wayPoint;
|
||||
private float durationDelta;
|
||||
private float completedDuration;
|
||||
private void Start()
|
||||
{
|
||||
nextId = Normal;
|
||||
isManyCustomer = true;
|
||||
this.UpdateAsObservable().Subscribe(_ =>
|
||||
{
|
||||
if (isManyCustomer || isLocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var localPosition = pinkTransform.localPosition;
|
||||
localPosition = Vector2.MoveTowards(localPosition, wayPoint, pinkWalkSpeed * Time.deltaTime);
|
||||
localPosition = localPosition + Vector3.forward * (localPosition.y + Mathf.Abs(walkSideBottomPos));
|
||||
pinkTransform.localPosition = localPosition;
|
||||
if (Vector2.Distance(localPosition, wayPoint) < .01f)
|
||||
{
|
||||
if (durationDelta < completedDuration)
|
||||
{
|
||||
durationDelta += Time.deltaTime;
|
||||
return;
|
||||
}
|
||||
durationDelta = 0;
|
||||
moveIndex++;
|
||||
if (moveIndex == pinkMoves.Length)
|
||||
{
|
||||
moveIndex = 0;
|
||||
isLocked = true;
|
||||
isManyCustomer = true;
|
||||
animator.SetTrigger(nextId);
|
||||
this.CallWaitForSeconds(coolTime, () =>
|
||||
{
|
||||
isLocked = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
SetPinkMove();
|
||||
}
|
||||
}).AddTo(this);
|
||||
}
|
||||
|
||||
private void SetPinkMove()
|
||||
{
|
||||
var move = pinkMoves[moveIndex];
|
||||
wayPoint = move.wayPoint;
|
||||
completedDuration = move.wait;
|
||||
animator.SetTrigger(move.trigger);
|
||||
if (Vector2.Distance(wayPoint, pinkTransform.localPosition.ToVector2()) < .01f)
|
||||
{
|
||||
// nop
|
||||
} else if ((wayPoint - pinkTransform.localPosition.ToVector2()).x > 0)
|
||||
{
|
||||
pinkTransform.localRotation = Quaternion.Euler(Vector3.up * 180);
|
||||
}
|
||||
else
|
||||
{
|
||||
pinkTransform.localRotation = Quaternion.Euler(Vector3.zero);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTrigger(int id)
|
||||
{
|
||||
if (nextId == id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
nextId = id;
|
||||
if (isManyCustomer)
|
||||
{
|
||||
animator.SetTrigger(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNormal()
|
||||
{
|
||||
animator.SetTrigger(Normal);
|
||||
}
|
||||
|
||||
public void SetPromotion()
|
||||
{
|
||||
animator.SetTrigger(Promotion);
|
||||
SetTrigger(Normal);
|
||||
}
|
||||
|
||||
public void SetSleepy()
|
||||
{
|
||||
animator.SetTrigger(Sleepy);
|
||||
SetTrigger(Sleepy);
|
||||
}
|
||||
|
||||
public void SetPromotion()
|
||||
{
|
||||
isManyCustomer = true;
|
||||
pinkTransform.localPosition = LeftPos;
|
||||
animator.SetTrigger(Promotion);
|
||||
}
|
||||
|
||||
public void SetWalk()
|
||||
{
|
||||
if (!isManyCustomer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!isLocked)
|
||||
{
|
||||
isManyCustomer = false;
|
||||
SetPinkMove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -419,7 +419,6 @@ public class Market : MonoBehaviour
|
|||
case ShopState.Busy:
|
||||
break;
|
||||
case ShopState.Close:
|
||||
// お客さんが購入中の場合待つ
|
||||
if (customerList.Count(x => x.State.Value == CustomerState.Order) == 0)
|
||||
{
|
||||
pinkView.SetSleepy();
|
||||
|
|
@ -427,6 +426,7 @@ public class Market : MonoBehaviour
|
|||
}
|
||||
else
|
||||
{
|
||||
// お客さんがいなくなったあと、閉店の看板を出す
|
||||
Observable.CombineLatest(customerList.Select(x => x.State).Where(x => x.Value == CustomerState.Order))
|
||||
.First(states => states.Count(x => x == CustomerState.Order) == 0)
|
||||
.Delay(TimeSpan.FromSeconds(2f))
|
||||
|
|
@ -442,6 +442,18 @@ public class Market : MonoBehaviour
|
|||
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
||||
}
|
||||
}).AddTo(this);
|
||||
|
||||
// お客さんが少なくなったら弟が走る
|
||||
customerList.ObserveCountChanged(true).AsUnitObservable()
|
||||
.Merge(Observable.Interval(TimeSpan.FromSeconds(1f)).AsUnitObservable())
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
var count = customerList.Count(c => c.State.Value == CustomerState.Wait || c.State.Value == CustomerState.Order);
|
||||
if (count < pinkView.FewerBorder)
|
||||
{
|
||||
pinkView.SetWalk();
|
||||
}
|
||||
}).AddTo(this);
|
||||
}
|
||||
|
||||
private int SellPopcorn(List<(int flavor, int bonusRate)> flavors)
|
||||
|
|
|
|||
|
|
@ -5274,6 +5274,7 @@ GameObject:
|
|||
- component: {fileID: 1749782974}
|
||||
- component: {fileID: 1749782975}
|
||||
- component: {fileID: 1749782976}
|
||||
- component: {fileID: 1749782977}
|
||||
m_Layer: 0
|
||||
m_Name: Brother_pink
|
||||
m_TagString: Untagged
|
||||
|
|
@ -5332,6 +5333,21 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
animator: {fileID: 1749782975}
|
||||
pinkTransform: {fileID: 1749782974}
|
||||
walkSideBottomPos: -8
|
||||
pinkWalkSpeed: 4
|
||||
coolTime: 20
|
||||
--- !u!210 &1749782977
|
||||
SortingGroup:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1749782973}
|
||||
m_Enabled: 1
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 23
|
||||
--- !u!1001 &1775193988
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue