109 lines
3.3 KiB
C#
109 lines
3.3 KiB
C#
using asap.core;
|
|
using PinballUncountable;
|
|
using UnityEngine;
|
|
using UniRx;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using Game;
|
|
|
|
public class PinballUncountableDiscView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image bar;
|
|
[SerializeField] private RewardItemNew rewardView, getRewardFx;
|
|
[SerializeField] private GameObject goGetReward;
|
|
[SerializeField] private Animation normalAni;
|
|
private int _logicPoint, _maxPoint, _idx, _displayPoint;
|
|
private bool _isCompleting = false;
|
|
private float TargetAmount => (float)_displayPoint / _maxPoint;
|
|
// private Tween _tween = null;
|
|
private readonly string _disc1 = "Disc_01", _disc2 = "Disc_02";
|
|
private readonly float _fillTime = 0.3f;
|
|
private GameCore.ItemData _lastRewardItemData = null;
|
|
|
|
private void Awake()
|
|
{
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
manager.EventAggregator.GetEvent<EventHitDisc>().Subscribe(OnHitDisc).AddTo(this);
|
|
// fx.SetActive(false);
|
|
}
|
|
|
|
public void Init(int idx = 0, int currentPoint = 0, int maxCount = 10)
|
|
{
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
_idx = idx;
|
|
_logicPoint = currentPoint;
|
|
_maxPoint = maxCount;
|
|
_displayPoint = currentPoint % maxCount;
|
|
_isCompleting = false;
|
|
bar.fillAmount = (float)_displayPoint / _maxPoint;
|
|
_lastRewardItemData = manager.TableContext.GetItemFromHitCount(_logicPoint, idx, manager.InflationRate);
|
|
rewardView.SetData(_lastRewardItemData);
|
|
getRewardFx.SetData(_lastRewardItemData);
|
|
}
|
|
|
|
private void OnHitDisc(EventHitDisc e)
|
|
{
|
|
int idx;
|
|
if (e.DiscName == _disc1)
|
|
idx = 0;
|
|
else if (e.DiscName == _disc2)
|
|
idx = 1;
|
|
else
|
|
// Collider name is not matched.
|
|
return;
|
|
|
|
if (idx != _idx)
|
|
// Disc name is not matched.
|
|
return;
|
|
|
|
_logicPoint++;
|
|
// Debug.Log($"[PinballUncountable] Hit {e.DiscName} to {_logicPoint}");
|
|
GContext.Publish(new EventUISound("audio_ui_eventUncountablePinball_cowboy_reward_add"));
|
|
if (_isCompleting)
|
|
// Is final phase.
|
|
return;
|
|
_displayPoint = _logicPoint % _maxPoint;
|
|
|
|
|
|
if (_displayPoint <= 0)
|
|
{
|
|
StartCoroutine(PlayFinal());
|
|
}
|
|
else
|
|
{
|
|
PlayNormal(TargetAmount);
|
|
}
|
|
}
|
|
|
|
private IEnumerator PlayFinal()
|
|
{
|
|
_isCompleting = true;
|
|
// fx.SetActive(false);
|
|
// fx.SetActive(true);
|
|
bar.fillAmount = 1f;
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
var item = manager.TableContext.GetItemFromHitCount(_logicPoint, _idx, manager.InflationRate);
|
|
|
|
goGetReward.SetActive(false);
|
|
goGetReward.SetActive(true);
|
|
rewardView.SetData(item);
|
|
yield return Awaiters.Seconds(130f / 60);
|
|
|
|
goGetReward.SetActive(false);
|
|
getRewardFx.SetData(item);
|
|
|
|
// yield return Awaiters.Seconds(_fillTime - 1);
|
|
_isCompleting = false;
|
|
bar.fillAmount = 0f;
|
|
_displayPoint = _logicPoint % _maxPoint;
|
|
PlayNormal(TargetAmount);
|
|
}
|
|
|
|
private void PlayNormal(float target)
|
|
{
|
|
bar.fillAmount = target;
|
|
normalAni.Play();
|
|
// _tween?.Kill();
|
|
// _tween = bar.DOFillAmount(target, _fillTime);
|
|
}
|
|
} |