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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using Mirror;
|
||||
|
||||
public class GameManager : NetworkBehaviour
|
||||
{
|
||||
public static Team MyTeam { get; set; }
|
||||
public static MatchmadePlayer RedPlayer { get; set; }
|
||||
public static MatchmadePlayer BluePlayer { get; set; }
|
||||
/// <summary>Set by dedicated server startup (e.g. CupidConnector parsing <c>-matchId</c>). PATCH is skipped if id ≤ 0 or secret is empty.</summary>
|
||||
|
||||
+16
-17
@@ -11,30 +11,29 @@ public class NetPlayer : NetworkBehaviour
|
||||
{
|
||||
base.OnStartLocalPlayer();
|
||||
// Count current NetPlayers in the scene
|
||||
NetPlayer[] players = FindObjectsOfType<NetPlayer>();
|
||||
if (players.Length <= 1)
|
||||
{
|
||||
myTeam = Team.Red;
|
||||
CmdSetTeam(Team.Red);
|
||||
}
|
||||
else
|
||||
{
|
||||
myTeam = Team.Blue;
|
||||
CmdSetTeam(Team.Blue);
|
||||
}
|
||||
|
||||
SetMyTeam(GameManager.MyTeam);
|
||||
TeamSpecificEffects.instance.SetTeamSpecificEffects(myTeam);
|
||||
}
|
||||
|
||||
if(myTeam == Team.Blue){
|
||||
CameraEffects.instance.SetUpsideDown(true);
|
||||
void SetMyTeam(Team team){
|
||||
if(isServer){
|
||||
setMyTeam(team);
|
||||
}else{
|
||||
CameraEffects.instance.SetUpsideDown(false);
|
||||
CmdSetTeam(team);
|
||||
setMyTeam(team);
|
||||
}
|
||||
}
|
||||
|
||||
void setMyTeam(Team team){
|
||||
myTeam = team;
|
||||
if (GameManager.instance != null)
|
||||
GameManager.instance.OnMatchPlayerTeamAssigned(team);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetTeam(Team team){
|
||||
myTeam = team;
|
||||
if (GameManager.instance != null)
|
||||
GameManager.instance.OnMatchPlayerTeamAssigned(team);
|
||||
setMyTeam(team);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TeamSpecificEffects : MonoBehaviour
|
||||
{
|
||||
public static TeamSpecificEffects instance;
|
||||
|
||||
public Transform[] flipY;
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void SetTeamSpecificEffects(Team team){
|
||||
foreach(Transform t in flipY){
|
||||
float y = Mathf.Abs(t.localScale.y);
|
||||
t.localScale = new Vector3(t.localScale.x, team == Team.Blue ? -y : y, t.localScale.z);
|
||||
}
|
||||
|
||||
if(team == Team.Blue){
|
||||
CameraEffects.instance.SetUpsideDown(true);
|
||||
}else{
|
||||
CameraEffects.instance.SetUpsideDown(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 370d8135f2d97da4194a41598ce8c4a9
|
||||
Reference in New Issue
Block a user