You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

84 lines
1.9 KiB

using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerSlot : MonoBehaviour {
public bool IsEmpty { get; private set; } = true;
private bool isReady;
public bool IsReady {
get => isReady;
set {
isReady = value;
readyCheckmarkImage.gameObject.SetActive(value);
}
}
private Player player;
public Player Player {
get => player;
set {
player = value;
if (value != null) {
activePlayer.SetActive(true);
IsEmpty = false;
playerNameText.text = value.NickName;
ApplyProperties();
} else {
activePlayer.SetActive(false);
IsEmpty = true;
IsReady = false;
}
}
}
private void ApplyProperties() {
if (TryGetColor(out int index)) {
Material material = ColorManager.GetUiBy(Player.ActorNumber);
playerImage.material = material;
readyCheckmarkHolderImage.material = material;
readyCheckmarkImage.material = material;
}
if (TryGetReady(out bool ready))
IsReady = ready;
}
private bool TryGetColor(out int index) {
bool success = Player.CustomProperties.TryGetValue("ColorIndex", out object objIndex);
if (success)
index = (int)objIndex;
else
index = 0;
return success;
}
private bool TryGetReady(out bool ready) {
bool success = Player.CustomProperties.TryGetValue("IsReady", out object objReady);
if (success)
ready = (bool)objReady;
else
ready = false;
return success;
}
public void OnPropertiesUpdate(Hashtable props) {
ApplyProperties();
}
public void TrySetReady(bool ready) {
if (Player != PhotonNetwork.LocalPlayer)
return;
Player.SetCustomProperties(new Hashtable() {["IsReady"] = ready});
}
public GameObject activePlayer;
public Text playerNameText;
public Image readyCheckmarkImage;
public Image readyCheckmarkHolderImage;
public Image playerImage;
}