Dodanie skryptu MQTT

This commit is contained in:
Angelones12
2026-04-16 00:01:53 +02:00
parent 6863bba9ac
commit 3344421418
6 changed files with 154 additions and 20 deletions

View File

@@ -4,40 +4,56 @@ using UnityEngine.InputSystem.Utilities;
public class GameManager : MonoBehaviour
{
[Header("UI do ukrycia")]
public GameObject startCanvas;
[Header("Interfejs")]
public GameObject startUI; // Twój Canvas z napisem
[Header("Komponenty gracza")]
public PlayerMove movementScript;
public MouseLook lookScript;
[Header("Skrypty Gracza")]
public PlayerMove playerMove; // Skrypt poruszania fasolk¹
public MouseLook mouseLook; // Skrypt obracania kamer¹
// public MqttCollector mqttScript; // Odkomentujesz to póŸniej
[Header("Modu³ MQTT")]
public MqttCollector mqttCollector; // Skrypt MQTTnet
private bool hasStarted = false;
void Start()
{
// Blokada na starcie
if (movementScript != null) movementScript.enabled = false;
if (lookScript != null) lookScript.canLook = false;
// 1. Upewnij siê, ¿e na starcie wszystko jest zablokowane
if (playerMove != null) playerMove.enabled = false;
if (mouseLook != null) mouseLook.canLook = false;
// 2. Kursor musi byæ widoczny i wolny, ¿eby gracz wiedzia³, ¿e gra jeszcze nie ruszy³a
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
// Czekamy na dowolny klawisz
InputSystem.onAnyButtonPress.CallOnce(ctrl => Begin());
// 3. Czekamy na "Any Key" (dowolny przycisk klawiatury, myszy lub kontrolera VR)
InputSystem.onAnyButtonPress.CallOnce(ctrl => StartGame());
Debug.Log("GameManager: Oczekiwanie na start...");
}
void Begin()
void StartGame()
{
if (hasStarted) return;
hasStarted = true;
if (startCanvas != null) startCanvas.SetActive(false);
if (movementScript != null) movementScript.enabled = true;
if (lookScript != null) lookScript.EnableLooking();
// 1. Ukrywamy UI
if (startUI != null)
startUI.SetActive(false);
// if (mqttScript != null) mqttScript.BeginSession();
Debug.Log("Gra wystartowa³a!");
// 2. Odblokowujemy ruch i kamerê
if (playerMove != null)
playerMove.enabled = true;
if (mouseLook != null)
mouseLook.EnableLooking(); // Ta funkcja schowa te¿ kursor
// 3. Odpalamy zbieranie danych MQTT
if (mqttCollector != null)
{
mqttCollector.BeginSession();
}
Debug.Log("<color=green>SYSTEM: Gra i logowanie danych uruchomione!</color>");
}
}