59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using QFSW.QC;
|
|
using TMPro;
|
|
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
|
|
public class FishLabelMarker : MonoBehaviour
|
|
{
|
|
private static bool isRendering = true;
|
|
|
|
[SerializeField]
|
|
private TMP_Text text;
|
|
|
|
[SerializeField]
|
|
private GameObject background;
|
|
|
|
[SerializeField]
|
|
private Vector3 positionOffset;
|
|
|
|
private FishEntity fishEntity;
|
|
|
|
private void Start()
|
|
{
|
|
fishEntity = GetComponentInParent<FishEntity>();
|
|
MultiplayerFishSpawner.GetNetworkedFish(fishEntity);
|
|
base.transform.localPosition = Vector3.zero;
|
|
base.transform.localRotation = Quaternion.identity;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!string.IsNullOrEmpty(text.text) && !(Camera.main == null))
|
|
{
|
|
GameWaterSystem.FindWaterLevelAtLocation(fishEntity.transform.position, out var waterLevel);
|
|
Vector3 position = fishEntity.transform.position;
|
|
position.y = waterLevel;
|
|
base.transform.position = position + positionOffset;
|
|
base.transform.LookAt(Camera.main.transform);
|
|
base.transform.rotation = Quaternion.Euler(0f, base.transform.rotation.eulerAngles.y, 0f);
|
|
text.gameObject.SetActive(isRendering);
|
|
background.gameObject.SetActive(isRendering);
|
|
UpdateText();
|
|
}
|
|
}
|
|
|
|
private void UpdateText()
|
|
{
|
|
string arg = fishEntity.Data.Species.ToString();
|
|
float weight = fishEntity.Weight;
|
|
float num = FishWeightToLength.Instance.ConvertWeightFishToLength(fishEntity.Data.Species, fishEntity.Weight);
|
|
text.text = $"{arg}\nW: {weight:F1}\nL: {num:F1}";
|
|
}
|
|
|
|
[Command("toggle-fish-label", MonoTargetType.Single, Platform.AllPlatforms)]
|
|
public void ToggleFishLabel()
|
|
{
|
|
isRendering = !isRendering;
|
|
}
|
|
}
|