diff --git a/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs b/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs index 477083da..2e1d0a4a 100644 --- a/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs +++ b/popcorn/Assets/MyGame/Scenes/Title/Scripts/Title.cs @@ -89,7 +89,7 @@ public class Title : MonoBehaviour var customerAnimator = Instantiate(customerController.CustomerPrefab, customerObject.transform); customerController.CurrentMovingType.Subscribe(x => { - customerAnimator.SetTrigger(x); + customerAnimator.SetTrigger(x, customerController.DurationDelta); }).AddTo(customerAnimator); customerController.IsDefaultSide.Subscribe(x => { diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerAnimator.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerAnimator.cs index 5cd39b7c..2af282a0 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerAnimator.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerAnimator.cs @@ -5,14 +5,18 @@ using UnityEngine; public class CustomerAnimator : MonoBehaviour { - public static readonly string WantFlavorAmountFormat = "x{0}"; + private static readonly string WantFlavorAmountFormat = "x{0}"; - public static readonly int WalkFront = Animator.StringToHash("WalkFront"); - public static readonly int WalkSide = Animator.StringToHash("WalkSide"); - public static readonly int WalkBack = Animator.StringToHash("WalkBack"); - public static readonly int StayBack = Animator.StringToHash("StayBack"); - public static readonly int WalkFrontEat = Animator.StringToHash("WalkFrontEat"); - public static readonly int WalkSideEat = Animator.StringToHash("WalkSideEat"); + private static readonly int WalkFront = Animator.StringToHash("WalkFront"); + private static readonly int WalkSide = Animator.StringToHash("WalkSide"); + private static readonly int WalkBack = Animator.StringToHash("WalkBack"); + private static readonly int StayBack = Animator.StringToHash("StayBack"); + private static readonly int WalkFrontEat = Animator.StringToHash("WalkFrontEat"); + private static readonly int WalkSideEat = Animator.StringToHash("WalkSideEat"); + private static readonly int TouchNotice = Animator.StringToHash("TouchNotice"); + private static readonly int TouchQuestion = Animator.StringToHash("TouchQuestion"); + private static readonly int HashTouchNoticeState = Animator.StringToHash("Base Layer.customer_nomal_touch_notice"); + private static readonly int HashTouchQuestionState = Animator.StringToHash("Base Layer.customer_nomal_touch_Question"); private static readonly int Complain = Animator.StringToHash("ComplainTrigger"); @@ -38,7 +42,7 @@ public class CustomerAnimator : MonoBehaviour }).AddTo(this); } - public void SetTrigger(CustomerMovingType movingType) + public void SetTrigger(CustomerMovingType movingType, float duration) { switch (movingType) { @@ -51,6 +55,14 @@ public class CustomerAnimator : MonoBehaviour case CustomerMovingType.WalkCenter: triggerName.Value = WalkSide; break; + case CustomerMovingType.TouchNotice: + // Durationをもとに途中再生 + PlayResumeAnimation(HashTouchNoticeState, duration); + break; + case CustomerMovingType.TouchQuestion: + // Durationをもとに途中再生 + PlayResumeAnimation(HashTouchQuestionState, duration); + break; case CustomerMovingType.StayBackOrder: triggerName.Value = StayBack; break; @@ -75,6 +87,20 @@ public class CustomerAnimator : MonoBehaviour } + private void PlayResumeAnimation(int stateHashName, float duration) + { + /* + * durationをNormalizedTimeに変換するために + * State指定して1フレーム後にGetCurrentAnimatorClipInfoしている + */ + animator.Play(stateHashName); + Observable.NextFrame().Subscribe(_ => + { + var length = animator.GetCurrentAnimatorClipInfo(0)[0].clip.length; + animator.Play(stateHashName, 0, Mathf.Clamp01(duration/length)); + }).AddTo(this); + } + public void SetSide(bool isDefaultSide) { if (isDefaultSide) diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs index 1e9cb61e..2b64fc5f 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs @@ -309,7 +309,7 @@ public class MarketManager : MonoBehaviour var customerAnimator = Instantiate(controller.CustomerPrefab, customerObject.transform); controller.CurrentMovingType.Subscribe(x => { - customerAnimator.SetTrigger(x); + customerAnimator.SetTrigger(x, controller.DurationDelta); }).AddTo(customerAnimator); controller.IsDefaultSide.Subscribe(x => { @@ -355,7 +355,6 @@ public class MarketManager : MonoBehaviour }).AddTo(customerAnimator); var eventTrigger = customerAnimator.gameObject.AddComponent(); eventTrigger.OnPointerClickAsObservable() - .Where(_ => market.CurrentShopState.Value != ShopState.Close) .Take(1) .Subscribe(_ => { @@ -364,14 +363,14 @@ public class MarketManager : MonoBehaviour Destroy(target); } - if (controller.State.Value != CustomerState.Walk && - controller.State.Value != CustomerState.WalkShop && - controller.State.Value != CustomerState.CenterStop) + if (!(controller.State.Value == CustomerState.Walk || + controller.State.Value == CustomerState.WalkShop || + controller.State.Value == CustomerState.CenterStop)) { return; } + controller.Tapped(); - customerAnimator.ShowTapReaction(); VibrationManager.Instance.PlayVibrationOnce(); }).AddTo(customerAnimator); }