103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
using DG.Tweening;
|
||
using PrizeSystem;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace CharacterSystem
|
||
{
|
||
public class CharactersController : MonoBehaviour
|
||
{
|
||
public static CharactersController I;
|
||
|
||
[SerializeField] private List<Character> characterPrefabs;
|
||
|
||
private Character[] characters;
|
||
|
||
public static int CharacterIndex { get; private set; } = -1;
|
||
public static int CharactersAmount => I.characters.Length;
|
||
public static Character CurrentCharacter => I.characters[CharacterIndex];
|
||
|
||
public void Initialize()
|
||
{
|
||
I = this;
|
||
SetupCharacters();
|
||
}
|
||
|
||
public void SetAllCharactersPrizeAvailable()
|
||
{
|
||
foreach (Character character in I.characters)
|
||
character.prizeModule.ResetModule();
|
||
}
|
||
|
||
public static void ResetAllCharactersDifficulty()
|
||
{
|
||
foreach (Character character in I.characters)
|
||
character.difficultyModule.ResetPresetIndex();
|
||
}
|
||
|
||
public static void ResetSystem()
|
||
{
|
||
ResetAllCharactersDifficulty();
|
||
CharacterIndex = -1;
|
||
}
|
||
|
||
public void HideCharacter()
|
||
=> CurrentCharacter.visualModule.GetHideSequence().PlayForward();
|
||
|
||
public static Character[] GetCharactersArray()
|
||
=> new List<Character>(I.characters).ToArray();
|
||
|
||
private void SetupCharacters()
|
||
{
|
||
if (characterPrefabs.Count <= 0)
|
||
throw new System.Exception("Не заданы боты в контроллере");
|
||
|
||
int amount = characterPrefabs.Count;
|
||
characters = new Character[amount];
|
||
|
||
for (int i = 0; i < amount; i++)
|
||
{
|
||
var character = Instantiate(characterPrefabs[i]);
|
||
characters[i] = character;
|
||
character.Initialize(i);
|
||
}
|
||
|
||
RefreshPrizes();
|
||
}
|
||
|
||
public void RefreshPrizes()
|
||
{
|
||
for (int i = 0; i < characters.Length; i++)
|
||
{
|
||
PrizeSet prizesSet = PrizeSystemManager.PrizeContainer.Sets[i];
|
||
characters[i].prizeModule.SetPrizes(prizesSet);
|
||
}
|
||
}
|
||
|
||
public void ShowCharacter(int newIndex)
|
||
{
|
||
int oldIndex = CharacterIndex;
|
||
CharacterIndex = newIndex;
|
||
|
||
if (newIndex == oldIndex)
|
||
return;
|
||
|
||
var oldCharacter = characters[oldIndex];
|
||
var newCharacter = characters[newIndex];
|
||
|
||
Sequence seq = DOTween.Sequence();
|
||
|
||
seq.Append(oldCharacter.visualModule.GetHideSequence());
|
||
seq.AppendInterval(0.1f);
|
||
seq.Append(newCharacter.visualModule.GetShowSequence());
|
||
|
||
seq.AppendCallback(() =>
|
||
{
|
||
if (newIndex < oldIndex)
|
||
EventBus.TriggerEvent(GameEvent.Return);
|
||
else
|
||
EventBus.TriggerEvent(GameEvent.Appear);
|
||
});
|
||
}
|
||
}
|
||
} |