Added UI and more
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MainMenuUIController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button hostButton;
|
||||
[SerializeField] private Button clientButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
hostButton.onClick.AddListener(HostGame);
|
||||
clientButton.onClick.AddListener(JoinGame);
|
||||
}
|
||||
|
||||
private void HostGame()
|
||||
{
|
||||
NetworkManager.Singleton.StartHost();
|
||||
NetworkManager.Singleton.SceneManager.LoadScene("DEV-Game", LoadSceneMode.Single);
|
||||
Debug.Log("Hosting game...");
|
||||
}
|
||||
|
||||
private void JoinGame()
|
||||
{
|
||||
NetworkManager.Singleton.StartClient();
|
||||
Debug.Log("Joining game...");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 959485f694d1b8a4bb1e7ca35b53c083
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealthUIController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private PlayerHealthView view;
|
||||
|
||||
private PlayerHealth playerHealth;
|
||||
|
||||
public void Bind(PlayerHealth _playerHealth)
|
||||
{
|
||||
playerHealth = _playerHealth;
|
||||
playerHealth.HealthChanged += OnHealthChanged;
|
||||
|
||||
playerHealth.PushCurrentHealthValue();
|
||||
}
|
||||
|
||||
public void OnHealthChanged(int _currentHealth, int _maxHealth)
|
||||
{
|
||||
view.UpdateHealth(_currentHealth, _maxHealth);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
playerHealth.HealthChanged -= OnHealthChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44d1556056dfc6f4da444f682c5a8de2
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerHealthView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text healthText;
|
||||
[SerializeField] private Image healthBar;
|
||||
|
||||
public void UpdateHealth(int _currentHealth, int _maxHealth)
|
||||
{
|
||||
healthText.text = $"{_currentHealth}/{_maxHealth}";
|
||||
healthBar.fillAmount = (float)_currentHealth / _maxHealth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59027e05b1e47d84d844ed542398d01a
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerUIController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private PlayerHealthUIController playerHealthUIController;
|
||||
[SerializeField] private RoundManagerUIController roundManagerUIController;
|
||||
|
||||
|
||||
private PlayerFacade playerFacade;
|
||||
|
||||
private bool isActive = false;
|
||||
|
||||
public void Init(PlayerFacade _playerFacade)
|
||||
{
|
||||
isActive = true;
|
||||
|
||||
playerFacade = _playerFacade;
|
||||
|
||||
playerHealthUIController.Bind(playerFacade.PlayerHealth);
|
||||
roundManagerUIController.Bind(RoundManager.Current, playerFacade.OwnerClientId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df6776ae1b2a9ea4faec1e9006289f29
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RoundManagerUIController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RoundManagerView view;
|
||||
|
||||
private RoundManager roundManager;
|
||||
private ulong localClientId;
|
||||
|
||||
public void Bind(RoundManager _roundManager, ulong _localClientId)
|
||||
{
|
||||
roundManager = _roundManager;
|
||||
localClientId = _localClientId;
|
||||
|
||||
roundManager.TimerChanged += OnTimerChanged;
|
||||
roundManager.RoundChanged += OnRoundChanged;
|
||||
roundManager.ScoresChanged += OnScoresChanged;
|
||||
|
||||
// События срабатывают только при изменении — сразу показываем текущее состояние
|
||||
OnRoundChanged(roundManager.CurrentRound);
|
||||
OnTimerChanged(roundManager.RoundTimeRemaining);
|
||||
OnScoresChanged();
|
||||
}
|
||||
|
||||
public void OnTimerChanged(float _timer)
|
||||
{
|
||||
view.UpdateTimer(_timer);
|
||||
}
|
||||
|
||||
public void OnRoundChanged(int _round)
|
||||
{
|
||||
view.UpdateCurrentRound(_round);
|
||||
}
|
||||
|
||||
public void OnScoresChanged()
|
||||
{
|
||||
view.UpdateOwnerScore(roundManager.GetScore(localClientId));
|
||||
view.UpdateEnemyScore(roundManager.GetEnemyScore(localClientId));
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (roundManager == null) return;
|
||||
|
||||
roundManager.TimerChanged -= OnTimerChanged;
|
||||
roundManager.RoundChanged -= OnRoundChanged;
|
||||
roundManager.ScoresChanged -= OnScoresChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b11f67053d8a873458049261618f5608
|
||||
@@ -0,0 +1,30 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class RoundManagerView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text timerText;
|
||||
[SerializeField] private TMP_Text currentRoundText;
|
||||
[SerializeField] private TMP_Text ownerScoreText;
|
||||
[SerializeField] private TMP_Text enemyScoreText;
|
||||
|
||||
public void UpdateTimer(float _timer)
|
||||
{
|
||||
timerText.text = $"{_timer:F0}";
|
||||
}
|
||||
|
||||
public void UpdateCurrentRound(int _round)
|
||||
{
|
||||
currentRoundText.text = $"Round {_round}";
|
||||
}
|
||||
|
||||
public void UpdateOwnerScore(int _score)
|
||||
{
|
||||
ownerScoreText.text = _score.ToString();
|
||||
}
|
||||
|
||||
public void UpdateEnemyScore(int _score)
|
||||
{
|
||||
enemyScoreText.text = _score.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 485b4248f7e4e1946bb88c47df8ffcbd
|
||||
Reference in New Issue
Block a user