From f9ceb4bde8b09767d650f421a55716fd834ff786 Mon Sep 17 00:00:00 2001 From: kimura Date: Tue, 14 Dec 2021 13:44:23 +0900 Subject: [PATCH] =?UTF-8?q?=E8=B2=A9=E5=A3=B2=E3=82=B7=E3=83=BC=E3=83=B3?= =?UTF-8?q?=E8=A9=A6=E9=A3=9F=E4=B8=AD=E5=88=B6=E5=BE=A1=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Animation/Brother/Brother_pink.controller | 72 +++++++++- .../marketing/Scripts/BrotherPinkView.cs | 129 +++++++++++++----- 2 files changed, 164 insertions(+), 37 deletions(-) diff --git a/popcorn/Assets/MyGame/Resource/Animation/Brother/Brother_pink.controller b/popcorn/Assets/MyGame/Resource/Animation/Brother/Brother_pink.controller index fc11917a..09421063 100644 --- a/popcorn/Assets/MyGame/Resource/Animation/Brother/Brother_pink.controller +++ b/popcorn/Assets/MyGame/Resource/Animation/Brother/Brother_pink.controller @@ -91,6 +91,8 @@ AnimatorStateMachine: - {fileID: 51081042415013300} - {fileID: 4394378192515912696} - {fileID: -4201787685094799525} + - {fileID: 1938256483501769669} + - {fileID: 265964369079198928} m_EntryTransitions: [] m_StateMachineTransitions: {} m_StateMachineBehaviours: [] @@ -242,25 +244,37 @@ 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: 9100000} + m_Controller: {fileID: 0} + - m_Name: Tasting + m_Type: 9 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 0} + - m_Name: TastingWalk + m_Type: 9 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 0} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -299,6 +313,56 @@ AnimatorStateTransition: m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 0 +--- !u!1101 &265964369079198928 +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: TastingWalk + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -7730918100354297461} + 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!1101 &1938256483501769669 +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: Tasting + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -6388531656861423336} + 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 &4390197982913342166 AnimatorState: serializedVersion: 5 diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/BrotherPinkView.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/BrotherPinkView.cs index ad5bf563..9ee208f5 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/BrotherPinkView.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/BrotherPinkView.cs @@ -1,4 +1,5 @@ using System; +using MyGame.Scenes.marketing.Scripts; using UniRx; using UniRx.Triggers; using UnityEngine; @@ -9,6 +10,8 @@ public class BrotherPinkView : SingletonMonoBehaviour 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 int Tasting = Animator.StringToHash("Tasting"); + private static readonly int TastingWalk = Animator.StringToHash("TastingWalk"); private static readonly Vector2 RightPos = new Vector2(4.96f, -0.26f); private static readonly Vector2 LeftPos = new Vector2(-4.96f, -0.26f); @@ -22,9 +25,12 @@ public class BrotherPinkView : SingletonMonoBehaviour public int FewerBorder => fewerBorder; private Animator animator; - private bool isManyCustomer; - private bool isLocked; + private TastingBasketView basketView; + private bool waitMove; + private bool isMoveLocked; private bool isPromotion; + private bool isEndingPromotion; + private bool isTasting; private int nextId; private readonly (int trigger, Vector2 wayPoint, float wait)[] pinkMoves = { @@ -33,23 +39,48 @@ public class BrotherPinkView : SingletonMonoBehaviour (Walk, RightPos, 0f), (Promotion, RightPos + Vector2.left * .03f, 5.35f), }; + private readonly (int trigger, Vector2 wayPoint, float wait)[] pinkTastingMoves = + { + (TastingWalk, LeftPos, 0f), + (Tasting, LeftPos + Vector2.right * .03f, 5.35f), + (TastingWalk, RightPos, 0f), + (Tasting, RightPos + Vector2.left * .03f, 5.35f), + }; private int moveIndex; private Vector2 wayPoint; private float durationDelta; private float completedDuration; + private (int trigger, Vector2 wayPoint, float wait)[] selectedMoves; + private IDisposable moveLockDispose; + private Subject setTrigger = new Subject(); private void Awake() { + setTrigger.AddTo(this); nextId = Normal; - isManyCustomer = true; + waitMove = true; + selectedMoves = pinkMoves; } private void Start() { pinkTransform.localPosition = RightPos; + /* + * 1フレーム内で最後に受け取った値をSetする + * アニメーター挙動考慮 + */ + setTrigger + .ThrottleFrame(1) + .Subscribe(x => + { + if (animator != null) + { + animator.SetTrigger(x); + } + }).AddTo(this); this.UpdateAsObservable().Subscribe(_ => { - if (isManyCustomer || isLocked || isPromotion) + if (waitMove || isMoveLocked || isPromotion) { return; } @@ -66,14 +97,16 @@ public class BrotherPinkView : SingletonMonoBehaviour } durationDelta = 0; moveIndex++; - if (moveIndex == pinkMoves.Length) + if (moveIndex == selectedMoves.Length) { - ResetMove(); - isLocked = true; - this.CallWaitForSeconds(coolTime, () => + if (isTasting) { - isLocked = false; - }); + moveIndex = 0; + SetPinkMove(); + return; + } + ResetMove(); + LockMove(coolTime); return; } SetPinkMove(); @@ -81,10 +114,21 @@ public class BrotherPinkView : SingletonMonoBehaviour }).AddTo(this); } + private void LockMove(float time) + { + isMoveLocked = true; + moveLockDispose?.Dispose(); + moveLockDispose = Observable.Timer(TimeSpan.FromSeconds(time)) + .Subscribe(l => { }, () => + { + isMoveLocked = false; + }).AddTo(this); + } + private void ResetMove() { + waitMove = true; moveIndex = 0; - isManyCustomer = true; if (animator != null) animator.SetTrigger(nextId); } @@ -92,12 +136,13 @@ public class BrotherPinkView : SingletonMonoBehaviour { target.DestroyAllChildrens(); animator = Instantiate(animatorPrefab, target); + basketView = animator.GetComponent(); this.UpdateAsObservable().Subscribe(_ => { target.localPosition = pinkTransform.localPosition; target.localRotation = pinkTransform.localRotation; }).AddTo(animator); - if (isManyCustomer || isPromotion) + if (waitMove || isPromotion || isTasting) { return; } @@ -106,13 +151,14 @@ public class BrotherPinkView : SingletonMonoBehaviour private void SetPinkMove() { - var move = pinkMoves[moveIndex]; + var move = selectedMoves[moveIndex]; wayPoint = move.wayPoint; completedDuration = move.wait; if (animator != null) { animator.ResetTrigger(Normal); - animator.SetTrigger(move.trigger); + // animator.SetTrigger(move.trigger); + setTrigger.OnNext(move.trigger); } if (Vector2.Distance(wayPoint, pinkTransform.localPosition.ToVector2()) < .01f) { @@ -127,10 +173,11 @@ public class BrotherPinkView : SingletonMonoBehaviour } } + // お客さんが多い場合に使用するアニメーション切替え private void SetTrigger(int id) { nextId = id; - if (isManyCustomer) + if (waitMove) { animator.SetTrigger(id); } @@ -161,34 +208,50 @@ public class BrotherPinkView : SingletonMonoBehaviour { if (animator != null) { - var stateInfo = animator.GetCurrentAnimatorStateInfo(0); - if (stateInfo.IsName("Brother_pink_promotion")) - { - var length = stateInfo.length; - var time = stateInfo.normalizedTime; - this.CallWaitForSeconds((1 - time % 1) * length - .3f, () => - { - animator.ResetTrigger(Promotion); - ResetMove(); - isPromotion = false; - }); - return; - } + animator.ResetTrigger(Promotion); } ResetMove(); isPromotion = false; } - public void SetWalk() + public void StartTasting() { - if (isLocked || isPromotion) + // tasting発動 + moveLockDispose?.Dispose(); + isMoveLocked = false; + waitMove = false; + + isTasting = true; + selectedMoves = pinkTastingMoves; + SetPinkMove(); + } + + public void StopTasting() + { + if (!isTasting) { return; } - if (isManyCustomer) + isTasting = false; + selectedMoves = pinkMoves; + SetPinkMove(); + } + + public void SetTastingCount(int count) + { + if (basketView != null) { - isManyCustomer = false; - SetPinkMove(); + basketView.SetItem(count); } } + + public void SetWalk() + { + if (!waitMove || isMoveLocked || isPromotion || isTasting) + { + return; + } + waitMove = false; + SetPinkMove(); + } }