ZoeAppClass/Assets/Jogos/Jeopardy/Scripts/JPB_TeamController.cs

98 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class JPB_TeamController : MonoBehaviour
{
public List<JPB_TeamBehaviour> teams = new List<JPB_TeamBehaviour>();
public static JPB_TeamController instance;
public Button add;
public Button remove;
public Text countTeams;
public GameObject panelRef;
public GameObject parentPanel;
public int currentlyPlayingTeam = 0;
public class TeamNames
{
public string name;
public Color color;
public TeamNames(Color c, string n)
{
color = c;
name = n;
}
}
public List<TeamNames> tns;
private void Awake()
{
add.onClick.AddListener(AddTeam);
remove.onClick.AddListener(RemoveTeam);
GenerateColors();
instance = this;
}
public void GenerateColors()
{
TeamNames blue = new TeamNames(Color.blue, "Blue");
TeamNames red = new TeamNames(Color.red, "Red");
TeamNames yellow = new TeamNames(Color.yellow, "Yellow");
TeamNames cyan = new TeamNames(Color.cyan, "Cyan");
TeamNames green = new TeamNames(Color.green, "Green");
tns = new List<TeamNames>() { blue, red, yellow, cyan, green };
}
public void AddTeam()
{
SoundPlayer.instance.PlaySFX(4);
if (teams.Count < tns.Count)
{
TeamNames current = tns[teams.Count];
JPB_TeamBehaviour toAdd = new JPB_TeamBehaviour();
GameObject thisPanel = Instantiate(panelRef, parentPanel.transform, false);
thisPanel.GetComponent<Image>().color = current.color;
thisPanel.GetComponentsInChildren<Text>()[0].text = current.name;
toAdd.SetupTeam(current.name, current.color,thisPanel, thisPanel.GetComponent<Animator>(), thisPanel.GetComponentsInChildren<Text>()[1]);
teams.Add(toAdd);
countTeams.text = teams.Count.ToString();
}
}
public void RemoveTeam()
{
SoundPlayer.instance.PlaySFX(4);
if (teams.Count > 0)
{
Destroy(teams[teams.Count - 1].assignedPanel);
teams.RemoveAt(teams.Count - 1);
countTeams.text = teams.Count.ToString();
}
}
public void AddScore(int n)
{
teams[currentlyPlayingTeam].AddScore(n);
}
public void PassChance()
{
if (currentlyPlayingTeam < teams.Count - 1)
{
currentlyPlayingTeam++;
}
else
{
currentlyPlayingTeam = 0;
}
UpdateWhosPlaying();
}
public void UpdateWhosPlaying()
{
teams[currentlyPlayingTeam].anim.SetBool("Playing", true);
teams[currentlyPlayingTeam == 0 ? teams.Count - 1 : currentlyPlayingTeam - 1].anim.SetBool("Playing", false);
}
}