| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class BIWLoadingPlaceHolder : MonoBehaviour |
| | 6 | | { |
| | 7 | | [SerializeField] private Animator placeHolderAnimator; |
| | 8 | | [SerializeField] private List<ParticleSystem> placeHolderParticleSystems; |
| | 9 | |
|
| 1 | 10 | | private static readonly int disspose = Animator.StringToHash(EXIT_TRIGGER_NAME); |
| | 11 | | private const string EXIT_TRIGGER_NAME = "Exit"; |
| | 12 | | private const string EXIT_ANIMATION_NAME = "Exit"; |
| | 13 | |
|
| | 14 | | private Coroutine checkCoroutine; |
| | 15 | | public void Dispose() |
| | 16 | | { |
| 16 | 17 | | if (checkCoroutine != null) |
| 1 | 18 | | CoroutineStarter.Stop(checkCoroutine); |
| | 19 | |
|
| 16 | 20 | | Destroy(gameObject); |
| 16 | 21 | | } |
| | 22 | |
|
| | 23 | | public void DestroyAfterAnimation() |
| | 24 | | { |
| 1 | 25 | | if (placeHolderAnimator == null) |
| 0 | 26 | | return; |
| 1 | 27 | | placeHolderAnimator.SetTrigger(disspose); |
| | 28 | |
|
| 8 | 29 | | foreach (ParticleSystem placeHolderParticleSystem in placeHolderParticleSystems) |
| | 30 | | { |
| 3 | 31 | | placeHolderParticleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting); |
| | 32 | | } |
| 1 | 33 | | checkCoroutine = CoroutineStarter.Start(CheckIfAnimationHasFinish()); |
| 1 | 34 | | } |
| | 35 | |
|
| | 36 | | IEnumerator CheckIfAnimationHasFinish() |
| | 37 | | { |
| 1 | 38 | | yield return null; |
| 1 | 39 | | if (placeHolderAnimator != null) |
| | 40 | | { |
| 1 | 41 | | bool isExitingAnimationActive = false; |
| 2 | 42 | | while (!isExitingAnimationActive) |
| | 43 | | { |
| 2 | 44 | | if (placeHolderAnimator != null) |
| 2 | 45 | | isExitingAnimationActive = placeHolderAnimator.GetCurrentAnimatorStateInfo(0).IsName(EXIT_ANIMATION_ |
| | 46 | | else |
| 0 | 47 | | isExitingAnimationActive = true; |
| 2 | 48 | | yield return null; |
| | 49 | | } |
| 0 | 50 | | if (this != null) |
| 0 | 51 | | Destroy(gameObject); |
| | 52 | | } |
| 0 | 53 | | } |
| | 54 | | } |