105 lines
3.3 KiB
C#
105 lines
3.3 KiB
C#
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
public class GameCanvas : MonoBehaviour
|
|
{
|
|
public static GameCanvas instance;
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
|
|
ShowWaitingForOpponentPanel();
|
|
}
|
|
|
|
public EventTrigger gameInputPanel;
|
|
|
|
public Image turnTimerSliderTransform;
|
|
public Color redColor = Color.red;
|
|
public Color blueColor = Color.blue;
|
|
public TMP_Text blueTurnTimer;
|
|
[FormerlySerializedAs("txtTurnTimer")] public TMP_Text redTurnTimer;
|
|
public TMP_Text redName,blueName;
|
|
public TMP_Text txtWhosTurn;
|
|
public Image blueTurnTimerRound;
|
|
[FormerlySerializedAs("turnTimerRound")] public Image redTurnTimerRound;
|
|
|
|
public GameObject waitingForOpponentPanel;
|
|
|
|
|
|
void Start(){
|
|
redName.text = GameManager.RedPlayer.Name;
|
|
blueName.text = GameManager.BluePlayer.Name;
|
|
}
|
|
|
|
public void ShowWaitingForOpponentPanel(){
|
|
waitingForOpponentPanel.SetActive(true);
|
|
}
|
|
public void HideWaitingForOpponentPanel(){
|
|
waitingForOpponentPanel.SetActive(false);
|
|
}
|
|
|
|
void Update(){
|
|
UpdateTurnTimer();
|
|
}
|
|
Team prevTeam = Team.Red;
|
|
|
|
bool init=false;
|
|
void UpdateTurnTimer(){
|
|
if(NetPlayer.localPlayer == null){return;}
|
|
if(!init){
|
|
init=true;
|
|
SwitchTeams();
|
|
}
|
|
|
|
float turnTimerFillAmount = 1 - (GameManager.instance.turnTimerCounter / GameManager.instance.turnTimer);
|
|
if(prevTeam != GameManager.instance.SelectedTeam){
|
|
SwitchTeams();
|
|
prevTeam = GameManager.instance.SelectedTeam;
|
|
}
|
|
|
|
turnTimerSliderTransform.transform.localScale = new Vector3(turnTimerFillAmount, 1, 1);
|
|
string timerString = (GameManager.instance.turnTimer - GameManager.instance.turnTimerCounter).ToString("F0");
|
|
if (GameManager.instance.SelectedTeam == Team.Red)
|
|
{
|
|
if (redTurnTimer != null) redTurnTimer.text = ":"+timerString;
|
|
if (blueTurnTimer != null) blueTurnTimer.text = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (blueTurnTimer != null) blueTurnTimer.text = ":"+timerString;
|
|
if (redTurnTimer != null) redTurnTimer.text = string.Empty;
|
|
}
|
|
if (GameManager.instance.SelectedTeam == Team.Red)
|
|
{
|
|
if (redTurnTimerRound != null) redTurnTimerRound.fillAmount = turnTimerFillAmount;
|
|
if (blueTurnTimerRound != null) blueTurnTimerRound.fillAmount = 0f;
|
|
}
|
|
else
|
|
{
|
|
if (blueTurnTimerRound != null) blueTurnTimerRound.fillAmount = turnTimerFillAmount;
|
|
if (redTurnTimerRound != null) redTurnTimerRound.fillAmount = 0f;
|
|
}
|
|
}
|
|
|
|
void SwitchTeams(){
|
|
bool isMyTurn = GameManager.instance.SelectedTeam == NetPlayer.localPlayer.myTeam;
|
|
|
|
Color newColor = GameManager.instance.SelectedTeam == Team.Red ? redColor : blueColor;
|
|
turnTimerSliderTransform.DOColor(newColor, 0.5f);
|
|
|
|
if (txtWhosTurn != null)
|
|
{
|
|
txtWhosTurn.DOFade(0, 0.25f).OnComplete(() => {
|
|
txtWhosTurn.text = isMyTurn ? "Your Turn" : "Opponent's Turn";
|
|
txtWhosTurn.DOFade(1, 0.25f);
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|