|
|
|
using System;
|
|
|
|
using TMPro;
|
|
|
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
|
|
using Unity.BossRoom.Utils;
|
|
|
|
using Unity.Netcode;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Unity.BossRoom.Gameplay.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class containing references to UI children that we can display. Both are disabled by default on prefab.
|
|
|
|
/// </summary>
|
|
|
|
public class UIStateDisplay : MonoBehaviour
|
|
|
|
{
|
|
|
|
public SwapConfirmationPanel swapConfirmationPanel;
|
|
|
|
public string playerName;
|
|
|
|
[SerializeField]
|
|
|
|
UIName m_UIName;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
UIHealth m_UIHealth;
|
|
|
|
public FloatingScore floatingScorePrefab;
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
ScoreManager.OnScoreUpdated += OnScoreChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
ScoreManager.OnScoreUpdated -= OnScoreChanged;
|
|
|
|
}
|
|
|
|
public void DisplayName(NetworkVariable<FixedPlayerName> networkedName)
|
|
|
|
{
|
|
|
|
m_UIName.gameObject.SetActive(true);
|
|
|
|
m_UIName.Initialize(networkedName);
|
|
|
|
playerName=networkedName.Value.ToString();
|
|
|
|
//var servercharacterName = GetComponentInParent<ServerCharacter>();
|
|
|
|
//servercharacterName.name = playerName;
|
|
|
|
swapConfirmationPanel.gameObject.name += networkedName.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisplayHealth(NetworkVariable<int> networkedHealth, int maxValue)
|
|
|
|
{
|
|
|
|
m_UIHealth.gameObject.SetActive(true);
|
|
|
|
m_UIHealth.Initialize(networkedHealth, maxValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void HideHealth()
|
|
|
|
{
|
|
|
|
m_UIHealth.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
[SerializeField] private Transform scoreEffectSpawnPoint; // position above the head for the effect
|
|
|
|
private int previousScore = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Called when the NetworkVariable changes.
|
|
|
|
private void OnScoreChanged(ulong oldScore, int newScore)
|
|
|
|
{
|
|
|
|
// Trigger a floating effect on all clients.
|
|
|
|
// Using a ClientRpc so that every client sees the same effect.
|
|
|
|
// if (NetworkManager.Singleton.IsServer)
|
|
|
|
{
|
|
|
|
RpcPlayScoreAnimationClientRpc(newScore, scoreEffectSpawnPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This ClientRpc will be executed on all clients.
|
|
|
|
[ClientRpc]
|
|
|
|
private void RpcPlayScoreAnimationClientRpc(int change, UnityEngine.Transform spawnPosition)
|
|
|
|
{
|
|
|
|
// Instantiate the floating score effect prefab on each client.
|
|
|
|
FloatingScore effect = Instantiate(floatingScorePrefab, spawnPosition);
|
|
|
|
effect.transform.localPosition = Vector3.zero;
|
|
|
|
effect.transform.localEulerAngles= Vector3.zero;
|
|
|
|
effect.Initialize(change);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|