rc 0.71
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
using System.Collections;
|
||||
using Mirror;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -9,6 +10,12 @@ using DG.Tweening;
|
||||
public class GameCanvas : MonoBehaviour
|
||||
{
|
||||
public static GameCanvas instance;
|
||||
const int OpponentWaitTimeoutSeconds = 15;
|
||||
static readonly WaitForSeconds WaitOneSecond = new WaitForSeconds(1f);
|
||||
int opponentWaitSecondsElapsed;
|
||||
bool hasShownOpponentTimeout;
|
||||
Coroutine opponentWaitRoutine;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
@@ -16,6 +23,11 @@ public class GameCanvas : MonoBehaviour
|
||||
ShowWaitingForOpponentPanel();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
StopOpponentWaitRoutine();
|
||||
}
|
||||
|
||||
public EventTrigger gameInputPanel;
|
||||
|
||||
public Image turnTimerSliderTransform;
|
||||
@@ -29,18 +41,52 @@ public class GameCanvas : MonoBehaviour
|
||||
[FormerlySerializedAs("turnTimerRound")] public Image redTurnTimerRound;
|
||||
|
||||
public GameObject waitingForOpponentPanel;
|
||||
public GameObject timeoutForOpponentPanel;
|
||||
public Button btnLeaveGame;
|
||||
|
||||
|
||||
void Start(){
|
||||
if (btnLeaveGame != null)
|
||||
btnLeaveGame.onClick.AddListener(OnLeaveGamePressed);
|
||||
|
||||
|
||||
redName.text = GameManager.RedPlayer.Name;
|
||||
blueName.text = GameManager.BluePlayer.Name;
|
||||
|
||||
}
|
||||
|
||||
void OnLeaveGamePressed()
|
||||
{
|
||||
if (CupidLobby.instance != null)
|
||||
CupidLobby.instance.Cancel();
|
||||
LoginManager.ClearMatchYourTeam();
|
||||
|
||||
if (NetworkManager.singleton != null && NetworkClient.active)
|
||||
NetworkManager.singleton.StopClient();
|
||||
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
public void ShowWaitingForOpponentPanel(){
|
||||
waitingForOpponentPanel.SetActive(true);
|
||||
ResetOpponentTimeoutState();
|
||||
StopOpponentWaitRoutine();
|
||||
opponentWaitRoutine = StartCoroutine(OpponentWaitingTimeoutRoutine());
|
||||
}
|
||||
public void HideWaitingForOpponentPanel(){
|
||||
StopOpponentWaitRoutine();
|
||||
waitingForOpponentPanel.SetActive(false);
|
||||
timeoutForOpponentPanel.SetActive(false);
|
||||
ResetOpponentTimeoutState();
|
||||
}
|
||||
|
||||
void StopOpponentWaitRoutine()
|
||||
{
|
||||
if (opponentWaitRoutine != null)
|
||||
{
|
||||
StopCoroutine(opponentWaitRoutine);
|
||||
opponentWaitRoutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
void Update(){
|
||||
@@ -101,4 +147,49 @@ public class GameCanvas : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator OpponentWaitingTimeoutRoutine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return WaitOneSecond;
|
||||
|
||||
if (waitingForOpponentPanel == null || timeoutForOpponentPanel == null)
|
||||
yield break;
|
||||
|
||||
if (!waitingForOpponentPanel.activeSelf)
|
||||
{
|
||||
timeoutForOpponentPanel.SetActive(false);
|
||||
ResetOpponentTimeoutState();
|
||||
yield break;
|
||||
}
|
||||
|
||||
bool isSoloPlayer = FindObjectsByType<NetPlayer>(FindObjectsSortMode.None).Length <= 1;
|
||||
if (!isSoloPlayer)
|
||||
{
|
||||
timeoutForOpponentPanel.SetActive(false);
|
||||
ResetOpponentTimeoutState();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasShownOpponentTimeout)
|
||||
continue;
|
||||
|
||||
opponentWaitSecondsElapsed++;
|
||||
if (opponentWaitSecondsElapsed >= OpponentWaitTimeoutSeconds)
|
||||
{
|
||||
timeoutForOpponentPanel.transform.localScale = new Vector3(1, 0, 1);
|
||||
timeoutForOpponentPanel.transform.DOScaleY(1,0.1f).SetEase(Ease.InOutBounce);
|
||||
timeoutForOpponentPanel.SetActive(true);
|
||||
hasShownOpponentTimeout = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResetOpponentTimeoutState()
|
||||
{
|
||||
opponentWaitSecondsElapsed = 0;
|
||||
hasShownOpponentTimeout = false;
|
||||
timeoutForOpponentPanel.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user