65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using asap.core;
|
|
using Game;
|
|
|
|
public class PinballUncountableGaugeAnimationView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Animation aniGauge;
|
|
[SerializeField] private PinballUncountableAddScoreFx addScoreFxPrefab;
|
|
[SerializeField] private Transform addScoreFxParent;
|
|
|
|
private const int POOL_CAPACITY = 20;
|
|
private readonly Stack<PinballUncountableAddScoreFx> _pool = new Stack<PinballUncountableAddScoreFx>(POOL_CAPACITY);
|
|
private readonly List<PinballUncountableAddScoreFx> _activeItems = new List<PinballUncountableAddScoreFx>(POOL_CAPACITY);
|
|
|
|
private void Awake()
|
|
{
|
|
for (int i = 0; i < POOL_CAPACITY; i++)
|
|
{
|
|
var instance = Instantiate(addScoreFxPrefab, addScoreFxParent);
|
|
instance.Hide();
|
|
_pool.Push(instance);
|
|
}
|
|
}
|
|
|
|
public void OnAddScore(int score2Add)
|
|
{
|
|
aniGauge.Play();
|
|
GContext.Publish(new EventUISound("audio_ui_eventUncountablePinball_cowboy_score_add"));
|
|
if (_pool.Count == 0)
|
|
return;
|
|
|
|
var fx = _pool.Pop();
|
|
_activeItems.Add(fx);
|
|
|
|
System.Action onComplete = () =>
|
|
{
|
|
_activeItems.Remove(fx);
|
|
_pool.Push(fx);
|
|
};
|
|
|
|
if (score2Add >= 10)
|
|
fx.PlayMax(onComplete);
|
|
else
|
|
fx.PlayNormal(score2Add, onComplete);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
foreach (var item in _activeItems)
|
|
{
|
|
if (item != null)
|
|
Destroy(item.gameObject);
|
|
}
|
|
_activeItems.Clear();
|
|
|
|
while (_pool.Count > 0)
|
|
{
|
|
var item = _pool.Pop();
|
|
if (item != null)
|
|
Destroy(item.gameObject);
|
|
}
|
|
}
|
|
|
|
} |