TouhouLS/Assets/RealCode/Menu/LobbySetup.cs

79 lines
2.4 KiB
C#
Raw Normal View History

2020-08-22 05:41:26 +00:00
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();
2020-08-23 00:31:57 +00:00
GameBoardInstance.instance.ResetGame();
2020-08-22 05:41:26 +00:00
}
// 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;
}
2020-08-22 06:07:08 +00:00
var pready = PlayerProperties.lobbyStatus.Get(p2);
2020-08-22 07:34:54 +00:00
readyCheck2.localRotation = Quaternion.RotateTowards(readyCheck2.localRotation, pready ? Quaternion.identity : Quaternion.Euler(0f, 0f, 45f), delta);
2020-08-22 05:41:26 +00:00
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();
}
}
}
}