78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class LobbySetup : MonoBehaviour {
|
|
|
|
public static LobbySetup Instance { get; private set; }
|
|
|
|
public Transform readyCheck1, readyCheck2;
|
|
public Image readyImage1, readyImage2;
|
|
public TextMeshProUGUI readyStatus;
|
|
|
|
[Header("Messages")]
|
|
public string waitingKey;
|
|
|
|
public int dotMax = 3;
|
|
public float dotDuration = 1f;
|
|
|
|
|
|
private void Awake() {
|
|
Instance = this;
|
|
}
|
|
|
|
public void Setup(){
|
|
PlayerProperties.CreatePlayerHashtable();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update() {
|
|
var delta = Time.deltaTime * 180f;
|
|
|
|
if (NetworkManager.inRoom && GameTransition.Instance.state == GameState.Lobby){
|
|
// we setting player values by their id order
|
|
|
|
var players = NetworkManager.net.CurrentRoom.Players.Values.OrderBy(p => p.ID);
|
|
var p1 = players.ElementAtOrDefault(0);
|
|
var p2 = players.ElementAtOrDefault(1);
|
|
|
|
// displays
|
|
if (p1 != null){
|
|
if (p1.IsLocal){
|
|
PlayerProperties.playerCharacter.SetLocal(0);
|
|
GameBoardInstance.instance.player1.authorityID = p1.ID;
|
|
}
|
|
var pready = PlayerProperties.lobbyStatus.Get(p1);
|
|
readyCheck1.localRotation = Quaternion.RotateTowards(readyCheck1.localRotation, pready ? Quaternion.identity : Quaternion.Euler(0f, 0f, 45f), delta);
|
|
readyImage1.color = pready ? Color.green : Color.red;
|
|
}
|
|
|
|
// displays
|
|
if (p2 != null){
|
|
readyCheck2.gameObject.SetActive(true);
|
|
if (p2.IsLocal) {
|
|
PlayerProperties.playerCharacter.SetLocal(1);
|
|
GameBoardInstance.instance.player2.authorityID = p2.ID;
|
|
}
|
|
var pready = PlayerProperties.lobbyStatus.Get(p1);
|
|
readyCheck2.localRotation = Quaternion.RotateTowards(readyCheck1.localRotation, pready ? Quaternion.identity : Quaternion.Euler(0f, 0f, 45f), delta);
|
|
readyImage2.color = pready ? Color.green : Color.red;
|
|
} else {
|
|
GameBoardInstance.instance.player2.authorityID = -1;
|
|
readyCheck2.gameObject.SetActive(false);
|
|
}
|
|
|
|
readyStatus.text = Localization.GetString(waitingKey) + new string('.', Mathf.RoundToInt(Time.time / dotDuration) % dotMax);
|
|
|
|
if (PlayerProperties.GetAllLobbyStatus()){
|
|
GameBoardInstance.instance.SetupGame();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|