120 lines
3.0 KiB
C#
120 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class VictoryScale : MonoBehaviour
|
|
{
|
|
public ParticleSystem winParticles; // надо заприватить и почистить вызовы
|
|
|
|
[SerializeField] List<Transform> medals;
|
|
[SerializeField] List<Transform> rings;
|
|
[SerializeField] Transform Prize;
|
|
[SerializeField] Vector3 nextMedalOffset;
|
|
[SerializeField] GameObject CollectEffect, RemoveEffect;
|
|
|
|
[SerializeField] Animator CommonAnimator;
|
|
[SerializeField] Animator PrizeAnimator;
|
|
|
|
[SerializeField] AudioClip plusMedal;
|
|
[SerializeField] AudioClip minusMedal;
|
|
|
|
private int count = 0;
|
|
|
|
private void OnEnable()
|
|
{
|
|
winParticles.Stop();
|
|
foreach (var medal in medals)
|
|
{
|
|
medal.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void SetIdleState()
|
|
{
|
|
CommonAnimator?.SetTrigger("Idle");
|
|
PrizeAnimator?.SetTrigger("Idle");
|
|
}
|
|
|
|
public void SetWinState()
|
|
{
|
|
CommonAnimator?.SetTrigger("Prize");
|
|
PrizeAnimator?.SetTrigger("Prize");
|
|
}
|
|
|
|
public void SetSlotsCount(int count)
|
|
{
|
|
foreach (var ring in rings)
|
|
{
|
|
ring.gameObject.SetActive(false);
|
|
}
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
rings[i].gameObject.SetActive(true);
|
|
}
|
|
Prize.position = rings[count - 1].position + nextMedalOffset;
|
|
}
|
|
|
|
public void SetMedalsCount(int requiredCount)
|
|
{
|
|
if (count == requiredCount ||
|
|
requiredCount > medals.Count ||
|
|
requiredCount < 0)
|
|
return;
|
|
|
|
if (requiredCount > count)//увеличиваем заполнение
|
|
{
|
|
for (int i = count; i < requiredCount; i++)
|
|
{
|
|
EnableMedal(i);
|
|
}
|
|
}
|
|
else if (requiredCount < count)
|
|
{
|
|
for (int i = count; i > requiredCount; i--)
|
|
{
|
|
DisableMedal(i-1);
|
|
}
|
|
}
|
|
count = requiredCount;
|
|
}
|
|
|
|
private void EnableMedal(int index)
|
|
{
|
|
GameObject effect = CollectEffect;
|
|
SoundManager.instance.playClip(plusMedal);
|
|
Instantiate(effect, medals[index].position, Quaternion.identity);
|
|
medals[index].gameObject.SetActive(true);
|
|
}
|
|
|
|
public void DisableMedal(int index)
|
|
{
|
|
GameObject effect = RemoveEffect;
|
|
SoundManager.instance.playClip(minusMedal);
|
|
Instantiate(effect, medals[index].position, Quaternion.identity);
|
|
medals[index].gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ResetScale()
|
|
{
|
|
count = 0;
|
|
foreach (var medal in medals)
|
|
{
|
|
medal.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void ClearScale()
|
|
{
|
|
StartCoroutine(ClearScaleAnimation());
|
|
}
|
|
|
|
IEnumerator ClearScaleAnimation()
|
|
{
|
|
for (int i = 4; i >= 0; i--)
|
|
{
|
|
medals[i].gameObject.SetActive(false);
|
|
yield return new WaitForSeconds(0.5f);
|
|
}
|
|
ResetScale();
|
|
}
|
|
} |