Files

73 lines
3.4 KiB
C#
Raw Permalink Normal View History

2022-12-01 04:05:31 +02:00
using System;
2022-09-11 10:35:45 +03:00
using TMPro;
using UnityEngine;
2022-12-05 16:04:05 +02:00
using UnityEngine.UI;
2022-09-11 10:35:45 +03:00
public class DebugGameplayMenu : MonoBehaviour
{
2022-12-01 04:05:31 +02:00
[SerializeField] private TextAsset _versionTextAsset = default;
[SerializeField] private TextMeshProUGUI _fpsText = default;
[SerializeField] private TextMeshProUGUI _frameText = default;
[SerializeField] private TextMeshProUGUI _p1PositionText = default;
[SerializeField] private TextMeshProUGUI _p2PositionText = default;
2022-12-04 22:32:50 +02:00
[SerializeField] private TextMeshProUGUI _p1ConnectionText = default;
[SerializeField] private TextMeshProUGUI _p2ConnectionText = default;
2022-12-05 16:04:05 +02:00
[SerializeField] private Slider _p1ConnectionSlider = default;
[SerializeField] private Slider _p2ConnectionSlider = default;
2022-12-29 14:40:06 +02:00
[SerializeField] private Canvas _debugLocalCanvas = default;
[SerializeField] private Canvas _debugOnlineCanvas = default;
2022-12-01 04:05:31 +02:00
private readonly string _versionSplit = "Version:";
private readonly string _patchNotesSplit = "Patch Notes:";
private int _fpsFrame;
void Awake()
{
2022-12-29 14:40:06 +02:00
transform.parent.gameObject.SetActive(false);
2022-09-12 21:00:02 +03:00
#if UNITY_EDITOR
2022-12-29 14:40:06 +02:00
transform.parent.gameObject.SetActive(true);
2022-12-01 04:05:31 +02:00
string versionText = _versionTextAsset.text;
int versionTextPosition = versionText.IndexOf(_versionSplit) + _versionSplit.Length;
string versionNumber = " " + versionText[versionTextPosition..versionText.LastIndexOf(_patchNotesSplit)].Trim();
#endif
}
#if UNITY_EDITOR
private void Update()
{
2022-12-29 14:40:06 +02:00
if (Input.GetKeyDown(KeyCode.Alpha6))
{
_debugLocalCanvas.enabled = !_debugLocalCanvas.enabled;
_debugOnlineCanvas.enabled = !_debugOnlineCanvas.enabled;
}
2022-12-01 04:05:31 +02:00
if (_fpsFrame == 4)
{
_fpsText.text = "FPS: " + Mathf.FloorToInt(1f / Time.deltaTime);
}
_frameText.text = "Frame: " + DemonicsWorld.Frame;
}
private void FixedUpdate()
{
2022-12-04 21:35:31 +02:00
if (GameplayManager.Instance.PlayerOne != null)
2022-12-01 04:05:31 +02:00
{
2022-12-06 12:28:26 +02:00
_p1ConnectionSlider.value = GameplayManager.Instance.PlayerOne.ConnectionProgress;
_p2ConnectionSlider.value = GameplayManager.Instance.PlayerTwo.ConnectionProgress;
2023-01-26 18:52:03 +02:00
_p1ConnectionText.text = GameSimulation._players[0].health.ToString();
_p2ConnectionText.text = GameSimulation._players[1].health.ToString();
2022-12-05 03:15:48 +02:00
2023-01-26 18:52:03 +02:00
string p1X = (GameplayManager.Instance.PlayerTwo.OtherPlayerMovement.Physics.Position.x).ToString();
string p1Y = (GameplayManager.Instance.PlayerTwo.OtherPlayerMovement.Physics.Position.y).ToString();
string p2X = (GameplayManager.Instance.PlayerOne.OtherPlayerMovement.Physics.Position.x).ToString();
string p2Y = (GameplayManager.Instance.PlayerOne.OtherPlayerMovement.Physics.Position.y).ToString();
2022-12-04 22:32:50 +02:00
_p1PositionText.text = $"P1 ({p1X}, {p1Y})";
_p2PositionText.text = $"P2 ({p2X}, {p2Y})";
2022-12-04 21:35:31 +02:00
_fpsFrame++;
if (_fpsFrame == 6)
{
_fpsFrame = 0;
}
_p1PositionText.transform.parent.position = new Vector2(Camera.main.WorldToScreenPoint(GameplayManager.Instance.PlayerOne.transform.position).x, _p1PositionText.transform.parent.position.y);
_p2PositionText.transform.parent.position = new Vector2(Camera.main.WorldToScreenPoint(GameplayManager.Instance.PlayerTwo.transform.position).x, _p2PositionText.transform.parent.position.y);
2022-12-01 04:05:31 +02:00
}
}
2022-09-12 21:00:02 +03:00
#endif
2022-09-11 10:35:45 +03:00
}