カウンタークラス追加
This commit is contained in:
		
							parent
							
								
									391c4dba11
								
							
						
					
					
						commit
						5f84e67316
					
				|  | @ -104,7 +104,7 @@ AnimationClip: | |||
|     m_Level: 0 | ||||
|     m_CycleOffset: 0 | ||||
|     m_HasAdditiveReferencePose: 0 | ||||
|     m_LoopTime: 1 | ||||
|     m_LoopTime: 0 | ||||
|     m_LoopBlend: 0 | ||||
|     m_LoopBlendOrientation: 0 | ||||
|     m_LoopBlendPositionY: 0 | ||||
|  |  | |||
|  | @ -1,5 +1,30 @@ | |||
| %YAML 1.1 | ||||
| %TAG !u! tag:unity3d.com,2011: | ||||
| --- !u!1101 &-8642731778310273473 | ||||
| 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: Appear | ||||
|     m_EventTreshold: 0 | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: -7636538999637159995} | ||||
|   m_Solo: 0 | ||||
|   m_Mute: 0 | ||||
|   m_IsExit: 0 | ||||
|   serializedVersion: 3 | ||||
|   m_TransitionDuration: 0 | ||||
|   m_TransitionOffset: 0.24 | ||||
|   m_ExitTime: 1 | ||||
|   m_HasExitTime: 0 | ||||
|   m_HasFixedDuration: 1 | ||||
|   m_InterruptionSource: 0 | ||||
|   m_OrderedInterruption: 1 | ||||
|   m_CanTransitionToSelf: 1 | ||||
| --- !u!1102 &-7636538999637159995 | ||||
| AnimatorState: | ||||
|   serializedVersion: 5 | ||||
|  | @ -10,6 +35,58 @@ AnimatorState: | |||
|   m_Name: StockCorn_addition_appear | ||||
|   m_Speed: 1 | ||||
|   m_CycleOffset: 0 | ||||
|   m_Transitions: | ||||
|   - {fileID: 3383956810922778620} | ||||
|   m_StateMachineBehaviours: [] | ||||
|   m_Position: {x: 50, y: 50, z: 0} | ||||
|   m_IKOnFeet: 0 | ||||
|   m_WriteDefaultValues: 1 | ||||
|   m_Mirror: 0 | ||||
|   m_SpeedParameterActive: 0 | ||||
|   m_MirrorParameterActive: 0 | ||||
|   m_CycleOffsetParameterActive: 0 | ||||
|   m_TimeParameterActive: 0 | ||||
|   m_Motion: {fileID: 7400000, guid: a4e9d84ee63cf8441912c536b0a82c86, type: 2} | ||||
|   m_Tag:  | ||||
|   m_SpeedParameter:  | ||||
|   m_MirrorParameter:  | ||||
|   m_CycleOffsetParameter:  | ||||
|   m_TimeParameter:  | ||||
| --- !u!1101 &-6879587025651168406 | ||||
| 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: Add | ||||
|     m_EventTreshold: 0 | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: -788033614754781971} | ||||
|   m_Solo: 0 | ||||
|   m_Mute: 0 | ||||
|   m_IsExit: 0 | ||||
|   serializedVersion: 3 | ||||
|   m_TransitionDuration: 0 | ||||
|   m_TransitionOffset: 0 | ||||
|   m_ExitTime: 0.15 | ||||
|   m_HasExitTime: 1 | ||||
|   m_HasFixedDuration: 1 | ||||
|   m_InterruptionSource: 0 | ||||
|   m_OrderedInterruption: 1 | ||||
|   m_CanTransitionToSelf: 1 | ||||
| --- !u!1102 &-3946120656019495017 | ||||
| AnimatorState: | ||||
|   serializedVersion: 5 | ||||
|   m_ObjectHideFlags: 3 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_Name: StockCorn_addition_disappear | ||||
|   m_Speed: -1 | ||||
|   m_CycleOffset: 0 | ||||
|   m_Transitions: [] | ||||
|   m_StateMachineBehaviours: [] | ||||
|   m_Position: {x: 50, y: 50, z: 0} | ||||
|  | @ -36,7 +113,9 @@ AnimatorState: | |||
|   m_Name: StockCorn_addition | ||||
|   m_Speed: 1 | ||||
|   m_CycleOffset: 0 | ||||
|   m_Transitions: [] | ||||
|   m_Transitions: | ||||
|   - {fileID: -6879587025651168406} | ||||
|   - {fileID: 719906150159968281} | ||||
|   m_StateMachineBehaviours: [] | ||||
|   m_Position: {x: 50, y: 50, z: 0} | ||||
|   m_IKOnFeet: 0 | ||||
|  | @ -60,7 +139,31 @@ AnimatorController: | |||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_Name: StockCorn_addition | ||||
|   serializedVersion: 5 | ||||
|   m_AnimatorParameters: [] | ||||
|   m_AnimatorParameters: | ||||
|   - m_Name: Add | ||||
|     m_Type: 9 | ||||
|     m_DefaultFloat: 0 | ||||
|     m_DefaultInt: 0 | ||||
|     m_DefaultBool: 0 | ||||
|     m_Controller: {fileID: 9100000} | ||||
|   - m_Name: Appear | ||||
|     m_Type: 9 | ||||
|     m_DefaultFloat: 0 | ||||
|     m_DefaultInt: 0 | ||||
|     m_DefaultBool: 0 | ||||
|     m_Controller: {fileID: 9100000} | ||||
|   - m_Name: Disappear | ||||
|     m_Type: 9 | ||||
|     m_DefaultFloat: 0 | ||||
|     m_DefaultInt: 0 | ||||
|     m_DefaultBool: 0 | ||||
|     m_Controller: {fileID: 9100000} | ||||
|   - m_Name: Wait | ||||
|     m_Type: 9 | ||||
|     m_DefaultFloat: 0 | ||||
|     m_DefaultInt: 0 | ||||
|     m_DefaultBool: 0 | ||||
|     m_Controller: {fileID: 9100000} | ||||
|   m_AnimatorLayers: | ||||
|   - serializedVersion: 5 | ||||
|     m_Name: Base Layer | ||||
|  | @ -74,6 +177,78 @@ AnimatorController: | |||
|     m_IKPass: 0 | ||||
|     m_SyncedLayerAffectsTiming: 0 | ||||
|     m_Controller: {fileID: 9100000} | ||||
| --- !u!1101 &705613616560957241 | ||||
| AnimatorStateTransition: | ||||
|   m_ObjectHideFlags: 3 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_Name:  | ||||
|   m_Conditions: [] | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: 0} | ||||
|   m_Solo: 0 | ||||
|   m_Mute: 0 | ||||
|   m_IsExit: 1 | ||||
|   serializedVersion: 3 | ||||
|   m_TransitionDuration: 0 | ||||
|   m_TransitionOffset: 0 | ||||
|   m_ExitTime: 0 | ||||
|   m_HasExitTime: 1 | ||||
|   m_HasFixedDuration: 1 | ||||
|   m_InterruptionSource: 0 | ||||
|   m_OrderedInterruption: 1 | ||||
|   m_CanTransitionToSelf: 1 | ||||
| --- !u!1101 &719906150159968281 | ||||
| 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: Wait | ||||
|     m_EventTreshold: 0 | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: 2789945997106464607} | ||||
|   m_Solo: 0 | ||||
|   m_Mute: 0 | ||||
|   m_IsExit: 0 | ||||
|   serializedVersion: 3 | ||||
|   m_TransitionDuration: 0 | ||||
|   m_TransitionOffset: 0 | ||||
|   m_ExitTime: 0.1 | ||||
|   m_HasExitTime: 1 | ||||
|   m_HasFixedDuration: 1 | ||||
|   m_InterruptionSource: 0 | ||||
|   m_OrderedInterruption: 1 | ||||
|   m_CanTransitionToSelf: 1 | ||||
| --- !u!1101 &797903091149478652 | ||||
| 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: Add | ||||
|     m_EventTreshold: 0 | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: -788033614754781971} | ||||
|   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!1107 &2098577713097479084 | ||||
| AnimatorStateMachine: | ||||
|   serializedVersion: 5 | ||||
|  | @ -85,12 +260,20 @@ AnimatorStateMachine: | |||
|   m_ChildStates: | ||||
|   - serializedVersion: 1 | ||||
|     m_State: {fileID: -788033614754781971} | ||||
|     m_Position: {x: 200, y: 0, z: 0} | ||||
|     m_Position: {x: 340, y: -40, z: 0} | ||||
|   - serializedVersion: 1 | ||||
|     m_State: {fileID: -7636538999637159995} | ||||
|     m_Position: {x: 230, y: 60, z: 0} | ||||
|     m_Position: {x: 540, y: 20, z: 0} | ||||
|   - serializedVersion: 1 | ||||
|     m_State: {fileID: 2789945997106464607} | ||||
|     m_Position: {x: 340, y: 120, z: 0} | ||||
|   - serializedVersion: 1 | ||||
|     m_State: {fileID: -3946120656019495017} | ||||
|     m_Position: {x: 260, y: -150, z: 0} | ||||
|   m_ChildStateMachines: [] | ||||
|   m_AnyStateTransitions: [] | ||||
|   m_AnyStateTransitions: | ||||
|   - {fileID: -8642731778310273473} | ||||
|   - {fileID: 8499302709827305042} | ||||
|   m_EntryTransitions: [] | ||||
|   m_StateMachineTransitions: {} | ||||
|   m_StateMachineBehaviours: [] | ||||
|  | @ -98,4 +281,78 @@ AnimatorStateMachine: | |||
|   m_EntryPosition: {x: 50, y: 120, z: 0} | ||||
|   m_ExitPosition: {x: 800, y: 120, z: 0} | ||||
|   m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} | ||||
|   m_DefaultState: {fileID: -788033614754781971} | ||||
|   m_DefaultState: {fileID: 2789945997106464607} | ||||
| --- !u!1102 &2789945997106464607 | ||||
| AnimatorState: | ||||
|   serializedVersion: 5 | ||||
|   m_ObjectHideFlags: 1 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_Name: Wait | ||||
|   m_Speed: 1 | ||||
|   m_CycleOffset: 0 | ||||
|   m_Transitions: | ||||
|   - {fileID: 797903091149478652} | ||||
|   m_StateMachineBehaviours: [] | ||||
|   m_Position: {x: 50, y: 50, z: 0} | ||||
|   m_IKOnFeet: 0 | ||||
|   m_WriteDefaultValues: 1 | ||||
|   m_Mirror: 0 | ||||
|   m_SpeedParameterActive: 0 | ||||
|   m_MirrorParameterActive: 0 | ||||
|   m_CycleOffsetParameterActive: 0 | ||||
|   m_TimeParameterActive: 0 | ||||
|   m_Motion: {fileID: 0} | ||||
|   m_Tag:  | ||||
|   m_SpeedParameter:  | ||||
|   m_MirrorParameter:  | ||||
|   m_CycleOffsetParameter:  | ||||
|   m_TimeParameter:  | ||||
| --- !u!1101 &3383956810922778620 | ||||
| AnimatorStateTransition: | ||||
|   m_ObjectHideFlags: 1 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_Name:  | ||||
|   m_Conditions: [] | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: -788033614754781971} | ||||
|   m_Solo: 0 | ||||
|   m_Mute: 0 | ||||
|   m_IsExit: 0 | ||||
|   serializedVersion: 3 | ||||
|   m_TransitionDuration: 0 | ||||
|   m_TransitionOffset: 0.13288593 | ||||
|   m_ExitTime: 1 | ||||
|   m_HasExitTime: 1 | ||||
|   m_HasFixedDuration: 1 | ||||
|   m_InterruptionSource: 0 | ||||
|   m_OrderedInterruption: 1 | ||||
|   m_CanTransitionToSelf: 1 | ||||
| --- !u!1101 &8499302709827305042 | ||||
| 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: Disappear | ||||
|     m_EventTreshold: 0 | ||||
|   m_DstStateMachine: {fileID: 0} | ||||
|   m_DstState: {fileID: -3946120656019495017} | ||||
|   m_Solo: 0 | ||||
|   m_Mute: 0 | ||||
|   m_IsExit: 0 | ||||
|   serializedVersion: 3 | ||||
|   m_TransitionDuration: 0 | ||||
|   m_TransitionOffset: 0.13 | ||||
|   m_ExitTime: 0.75 | ||||
|   m_HasExitTime: 0 | ||||
|   m_HasFixedDuration: 1 | ||||
|   m_InterruptionSource: 0 | ||||
|   m_OrderedInterruption: 1 | ||||
|   m_CanTransitionToSelf: 1 | ||||
|  |  | |||
|  | @ -0,0 +1,109 @@ | |||
| using System; | ||||
| using System.Text; | ||||
| using UniRx; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
| 
 | ||||
| 
 | ||||
| public class HarvestedAdditionView : MonoBehaviour | ||||
| { | ||||
|     private static readonly int Add = Animator.StringToHash("Add"); | ||||
|     private static readonly int Appear = Animator.StringToHash("Appear"); | ||||
|     private static readonly int Disappear = Animator.StringToHash("Disappear"); | ||||
|     private static readonly int Wait = Animator.StringToHash("Wait"); | ||||
|      | ||||
|     [SerializeField] private Animator counterAnimator; | ||||
|     [SerializeField] private TextWithCountUpInt counter; | ||||
|     [Tooltip("揺れる頻度")] | ||||
|     [SerializeField] private float triggerThrottle = .1f; | ||||
|     [Tooltip("カウントアップ時間")] | ||||
|     [SerializeField] private float countDuration = .4f; | ||||
|     [Tooltip("コーンが来なくなってから待つ時間")] | ||||
|     [SerializeField] private float waitDisappeared = 2f; | ||||
|     private static readonly string harvestedCountFormat = "+{0}"; | ||||
|     private static readonly string hasCountFormat = "{0}"; | ||||
|     private readonly Subject<Unit> playEffectObserve = new Subject<Unit>(); | ||||
|     private bool flag; | ||||
|     private int latestCount; | ||||
| 
 | ||||
|     public IObservable<int> EndObservable => endObservable; | ||||
|     private readonly Subject<int> endObservable = new Subject<int>(); | ||||
|     private Coroutine disapperCoroutine; | ||||
| 
 | ||||
|     private void Start() | ||||
|     { | ||||
|         playEffectObserve.AddTo(this); | ||||
|         playEffectObserve | ||||
|             .ThrottleFirst(TimeSpan.FromSeconds(triggerThrottle)) | ||||
|             .Subscribe(_ => | ||||
|             { | ||||
|                 this.SafeStopCoroutine(disapperCoroutine); | ||||
|                 if (flag) | ||||
|                 { | ||||
|                     counterAnimator.transform.SetLocalScale(1); | ||||
|                     counterAnimator.SetTrigger(Appear); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     counterAnimator.SetTrigger(Add); | ||||
|                 } | ||||
|                 flag = false; | ||||
|             }).AddTo(this); | ||||
|         // playEffectObserveが来なくなって0.15sで揺らすのを止める | ||||
|         playEffectObserve | ||||
|             .Throttle(TimeSpan.FromSeconds(.15f)) | ||||
|             .Subscribe(_ => | ||||
|             { | ||||
|                 counterAnimator.ResetTrigger(Add); | ||||
|                 counterAnimator.SetTrigger(Wait); | ||||
|             }).AddTo(this); | ||||
|         playEffectObserve | ||||
|             .Throttle(TimeSpan.FromSeconds(waitDisappeared)) | ||||
|             .Subscribe(_ => | ||||
|             { | ||||
|                 endObservable.OnNext(latestCount); | ||||
|                 SetHarvestedCount(0); | ||||
|                 Debug.Log($"corn:{GameDataManager.GameData.CornSeed} {latestCount}"); | ||||
|                 disapperCoroutine = this.CallWaitForSeconds(countDuration, () => | ||||
|                 { | ||||
|                     Reset(); | ||||
|                     counterAnimator.SetTrigger(Disappear); | ||||
|                     this.CallWaitForSeconds(.25f, () => | ||||
|                     { | ||||
|                         counterAnimator.transform.SetLocalScale(0); | ||||
|                     }); | ||||
|                 }); | ||||
|             }).AddTo(this); | ||||
|     } | ||||
|      | ||||
|     public void Initialize(int count) | ||||
|     { | ||||
|         counterAnimator.transform.SetLocalScale(0); | ||||
|         counterAnimator.SetTrigger(Disappear); | ||||
|         Reset(); | ||||
|     } | ||||
| 
 | ||||
|     private void Reset() | ||||
|     { | ||||
|         counter.ChangeValue(hasCountFormat, 0); | ||||
|         latestCount = 0; | ||||
|         flag = true; | ||||
|     } | ||||
| 
 | ||||
|     private void SetHarvestedCount(int count) | ||||
|     { | ||||
|         latestCount = count; | ||||
|         counter.CountUpAnimation($"{harvestedCountFormat}", latestCount, countDuration); | ||||
|     } | ||||
|      | ||||
|     public void AddHarvestedCount(int count) | ||||
|     { | ||||
|         latestCount += count; | ||||
|         counter.CountUpAnimation($"{harvestedCountFormat}", latestCount, countDuration); | ||||
|     } | ||||
| 
 | ||||
|     public void PlayEffect() | ||||
|     { | ||||
|         playEffectObserve.OnNext(default); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,3 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: 36e90b93a284494f950c1e35f9b68535 | ||||
| timeCreated: 1634295489 | ||||
		Loading…
	
		Reference in New Issue