Files
2025-05-29 22:31:40 +03:00

166 lines
5.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DebugManager : MonoBehaviour
{
public bool showGUI = false;
private bool collapsed = false;
private Rect windowRect = new Rect(10, 10, 400, 360);
private Vector2 scrollPos;
private float sanitySliderValue = 500f;
private float candleLifeSliderValue = 100f;
private bool isAdjustingSanity = false;
private bool isAdjustingCandleLife = false;
private string pillsCollectedInput = "0";
public AudioSource debugAudioSource;
public AudioClip debugChoiceSoundEffect;
void Awake()
{
if (gameObject.GetComponent<AudioSource>() == null)
{
debugAudioSource = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
}
debugChoiceSoundEffect = Resources.Load<AudioClip>("DoorSounds/DoorOpenSoundEffect");
}
void Update()
{
if (Input.GetKeyDown(KeyCode.BackQuote)) // κουμπί `
{
showGUI = !showGUI;
}
if (!isAdjustingSanity && Sanity.GetInstance() != null)
sanitySliderValue = Sanity.GetInstance().currentSanity;
if (!isAdjustingCandleLife && CandleController.GetInstance() != null)
candleLifeSliderValue = CandleController.GetInstance().candleLife;
if (PlayerHealthManager.GetInstance() != null && !GUI.GetNameOfFocusedControl().Contains("Pills"))
pillsCollectedInput = PlayerHealthManager.GetInstance().pillsCollected.ToString();
}
void OnGUI()
{
if (!showGUI) return;
windowRect = GUI.Window(0, windowRect, DrawWindow, "Debug Tools");
}
void DrawWindow(int windowID)
{
GUI.DragWindow(new Rect(0, 0, windowRect.width, 20)); // draggable top area
GUIStyle labelStyle = new GUIStyle(GUI.skin.label) { fontSize = 14, normal = { textColor = Color.white } };
GUIStyle textFieldStyle = new GUIStyle(GUI.skin.textField) { fontSize = 14 };
GUIStyle buttonStyle = new GUIStyle(GUI.skin.button) { fontSize = 14 };
GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
boxStyle.normal.background = MakeTex(1, 1, new Color(0f, 0f, 0f, 0.6f));
GUI.backgroundColor = Color.gray;
if (GUI.Button(new Rect(windowRect.width - 25, 2, 20, 20), collapsed ? "▶" : "▼"))
{
collapsed = !collapsed;
}
if (collapsed) return;
GUILayout.BeginArea(new Rect(10, 25, windowRect.width - 20, windowRect.height - 35));
scrollPos = GUILayout.BeginScrollView(scrollPos);
GUILayout.Label("Sanity", labelStyle);
float newSanityValue = GUILayout.HorizontalSlider(sanitySliderValue, 0f, Sanity.GetInstance().SanityMaxValue);
GUILayout.Label($"Slider: {newSanityValue:F1}", labelStyle);
GUILayout.Label($"Current: {Sanity.GetInstance().currentSanity:F1}", labelStyle);
if (Mathf.Abs(newSanityValue - sanitySliderValue) > 0.01f)
{
isAdjustingSanity = true;
sanitySliderValue = newSanityValue;
Sanity.GetInstance().SetSanity(sanitySliderValue);
}
else if (Event.current.type == EventType.MouseUp)
{
isAdjustingSanity = false;
}
GUILayout.Space(10);
GUILayout.Label("Candle Life", labelStyle);
float newCandleValue = GUILayout.HorizontalSlider(candleLifeSliderValue, 0f, 100f);
GUILayout.Label($"Slider: {newCandleValue:F1}", labelStyle);
GUILayout.Label($"Current: {CandleController.GetInstance().candleLife:F1}", labelStyle);
if (Mathf.Abs(newCandleValue - candleLifeSliderValue) > 0.01f)
{
isAdjustingCandleLife = true;
candleLifeSliderValue = newCandleValue;
CandleController.GetInstance().RefillCandle(newCandleValue - CandleController.GetInstance().candleLife);
}
else if (Event.current.type == EventType.MouseUp)
{
isAdjustingCandleLife = false;
}
GUILayout.Space(10);
GUILayout.Label("Pills", labelStyle);
GUILayout.BeginHorizontal();
GUI.SetNextControlName("PillsInput");
pillsCollectedInput = GUILayout.TextField(pillsCollectedInput, 2, textFieldStyle, GUILayout.Width(50));
if (GUILayout.Button("+1", buttonStyle, GUILayout.Width(40)))
{
if (int.TryParse(pillsCollectedInput, out int pills))
{
pills = Mathf.Clamp(pills + 1, 0, 99);
pillsCollectedInput = pills.ToString();
PlayerHealthManager.GetInstance().pillsCollected = pills;
}
}
if (GUILayout.Button("-1", buttonStyle, GUILayout.Width(40)))
{
if (int.TryParse(pillsCollectedInput, out int pills))
{
pills = Mathf.Clamp(pills - 1, 0, 99);
pillsCollectedInput = pills.ToString();
PlayerHealthManager.GetInstance().pillsCollected = pills;
}
}
if (GUILayout.Button("Update Pills", buttonStyle, GUILayout.Width(120)))
{
if (int.TryParse(pillsCollectedInput, out int pills))
{
pills = Mathf.Clamp(pills, 0, 99);
PlayerHealthManager.GetInstance().pillsCollected = pills;
}
}
GUILayout.EndHorizontal();
GUILayout.Label($"Current: {PlayerHealthManager.GetInstance().pillsCollected}", labelStyle);
GUILayout.EndScrollView();
GUILayout.EndArea();
}
Texture2D MakeTex(int width, int height, Color col)
{
Color[] pix = new Color[width * height];
for (int i = 0; i < pix.Length; ++i)
pix[i] = col;
Texture2D result = new Texture2D(width, height);
result.SetPixels(pix);
result.Apply();
return result;
}
}