108 lines
2.1 KiB
C#
108 lines
2.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HalloweenQuestManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Sprite[] prizesSprite;
|
|
|
|
[SerializeField]
|
|
private Image[] prizesImage;
|
|
|
|
[SerializeField]
|
|
private Image progressBar;
|
|
|
|
[SerializeField]
|
|
private GameObject prizesPrefab;
|
|
|
|
private HalloweenPrize currentShowPrize;
|
|
|
|
[SerializeField]
|
|
private int[] prizeFishTotal;
|
|
|
|
[SerializeField]
|
|
private int maxFishTotal = 50;
|
|
|
|
private bool isStarted;
|
|
|
|
private Animator animator;
|
|
|
|
private void Start()
|
|
{
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().TotalZombiesFish >= maxFishTotal)
|
|
{
|
|
QuestDestroy();
|
|
}
|
|
animator = GetComponent<Animator>();
|
|
Refresh();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isStarted)
|
|
{
|
|
animator.SetBool("isStarted", value: true);
|
|
}
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
int totalZombiesFish = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().TotalZombiesFish;
|
|
float fillAmount = (float)totalZombiesFish / (float)maxFishTotal;
|
|
progressBar.fillAmount = fillAmount;
|
|
for (int i = 0; i < prizeFishTotal.Length; i++)
|
|
{
|
|
if (prizeFishTotal[i] <= totalZombiesFish)
|
|
{
|
|
prizesImage[i].sprite = prizesSprite[1];
|
|
if (i == prizeFishTotal.Length - 1)
|
|
{
|
|
InvokeRepeating("DoneQuest", 2f, 2f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CheckHalloweenFish(GameManager.FishSpecies fishSpecies)
|
|
{
|
|
if (fishSpecies != GameManager.FishSpecies.ZombieBass)
|
|
{
|
|
return;
|
|
}
|
|
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().TotalZombiesFish++;
|
|
Refresh();
|
|
int totalZombiesFish = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().TotalZombiesFish;
|
|
for (int i = 0; i < prizeFishTotal.Length; i++)
|
|
{
|
|
if (prizeFishTotal[i] == totalZombiesFish)
|
|
{
|
|
ShowPrize(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowPrize(int indexPrize)
|
|
{
|
|
if (!currentShowPrize)
|
|
{
|
|
currentShowPrize = Object.Instantiate(prizesPrefab, base.transform.parent).GetComponent<HalloweenPrize>();
|
|
currentShowPrize.Setup(indexPrize);
|
|
}
|
|
}
|
|
|
|
private void DoneQuest()
|
|
{
|
|
animator.SetTrigger("Done");
|
|
}
|
|
|
|
private void QuestDestroy()
|
|
{
|
|
Object.Destroy(base.gameObject);
|
|
}
|
|
|
|
public void SetStarted()
|
|
{
|
|
isStarted = true;
|
|
}
|
|
}
|