Cleaned Scripts, added comments, added end scene

This commit is contained in:
Thorbjoern
2025-07-03 13:31:47 +02:00
parent 410166ba80
commit 9a54b4ee58
9 changed files with 461 additions and 31 deletions
+19
View File
@@ -0,0 +1,19 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 52a5761204929f34abe1c66ab2876c93, type: 3}
m_Name: End
m_EditorClassIdentifier:
sceneId: End
doors: 0
furniture: 0
portals: 0
enemies: 0
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 31664cbb4d885d140b5467c7a8f0cb29
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
@@ -43,14 +43,12 @@ namespace GhostSystem
{
SupabaseManager.OnSuperbaseReady += HandleSupabaseReady;
RoomManager.OnSceneIdReady += HandleSceneIdReady;
//StopRecordingTrigger.OnRecordStop += HandleRecordStop;
}
private void OnDisable()
{
SupabaseManager.OnSuperbaseReady -= HandleSupabaseReady;
RoomManager.OnSceneIdReady -= HandleSceneIdReady;
//StopRecordingTrigger.OnRecordStop -= HandleRecordStop;
}
private void Start()
@@ -83,15 +81,9 @@ namespace GhostSystem
doorCount++;
}
}
//StartRecording();
}
}
/*private void HandleRecordStop()
{
StopRecording();
}*/
private void Update()
{
if (!_isRecording) return;
@@ -105,6 +97,7 @@ namespace GhostSystem
RecordSample();
}
// Würde genutzt werden, um live in die Datenbank hochzuladen.
/*if (_frameBuffer.Count >= BatchSize || _flushTimer >= FlushInterval)
{
_flushTimer = 0f;
@@ -121,7 +114,7 @@ namespace GhostSystem
}
}
private async UniTaskVoid FlushBatchAsync()
private async UniTaskVoid FlushBatchAsync() // Die eigentliche Methode zum Hochladen eines Batches/leeren des Buffers.
{
if (_frameBuffer.Count == 0 || !supabaseReady) return;
@@ -131,13 +124,13 @@ namespace GhostSystem
try
{
var response = await SupabaseManager.instance.supabase.From<FrameModel>().Insert(batch);
var response = await SupabaseManager.instance.supabase.From<FrameModel>().Insert(batch); // Versucht, den Batch an Superbase hochzuladen
if (!response.ResponseMessage.IsSuccessStatusCode)
{
Debug.LogWarning($"Batch insert failed: {response.ResponseMessage.StatusCode}, fallback to offline.");
await FallbackToOfflineAsync(batch);
}
if(response.ResponseMessage.IsSuccessStatusCode && sceneIdReady)
if (response.ResponseMessage.IsSuccessStatusCode && sceneIdReady) // Löst Action aus, wenn der Upload geklappt hat und die neue Szene geladen ist.
{
OnUploadFinished?.Invoke();
Debug.Log("Upload Finished");
@@ -147,13 +140,13 @@ namespace GhostSystem
catch (Exception ex)
{
Debug.LogWarning($"Insert failed, fallback to offline: {ex.Message}");
await FallbackToOfflineAsync(batch);
OnUploadFinished?.Invoke();
await FallbackToOfflineAsync(batch); // Bei nicht erfolgtem Upload wird der Batch lokal gescpeichert.
OnUploadFinished?.Invoke(); // Die Action für das Ende des Ladescreens wird trotzdem ausgelöst.
Debug.Log("Upload Finished");
}
}
private async UniTask FallbackToOfflineAsync(List<FrameModel> batch)
private async UniTask FallbackToOfflineAsync(List<FrameModel> batch) // Schreibt den Buffer in eine Datei, falls Upload nicht möglich
{
try
{
@@ -193,10 +186,9 @@ namespace GhostSystem
doorCount = 0;
}
public void Flush()
public void Flush() // Manueller Flush
{
_flushTimer = 0f;
//FlushBatchAsync();
_ = FlushBatchAsync(); // Fire and forget
}
}
+22 -6
View File
@@ -3,14 +3,18 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using System.Collections.Generic;
using UnityEngine.UI;
public class FlushAndLoad : MonoBehaviour
{
public TMP_Text output;
public TMP_Text instruction;
public GhostRecorderBatch recorder;
public GameObject loadingScreen;
public GameObject canvas;
private string sceneId;
private void OnEnable()
{
GhostRecorderBatch.OnUploadFinished += HandleUploadFinished;
@@ -34,13 +38,17 @@ public class FlushAndLoad : MonoBehaviour
{
if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
{
output.text = "Flush...";
loadingScreen.SetActive(true);
canvas.SetActive(false);
recorder.Flush();
GetComponent<SceneLoader>().NewRoom();
if (sceneId == "End") Application.Quit();
else
{
output.text = "Flush...";
loadingScreen.SetActive(true);
canvas.SetActive(false);
recorder.Flush();
GetComponent<SceneLoader>().NewRoom();
}
}
}
@@ -48,10 +56,18 @@ public class FlushAndLoad : MonoBehaviour
{
loadingScreen.SetActive(false);
output.text = "";
if (sceneId == "End")
{
output.text = "Durchlauf beendet.";
instruction.text = "Drücke den rechten Trigger, um die Anwendung zu beenden.";
canvas.SetActive(true);
}
}
private void HandleSceneIdReady(string id, List<GameObject> doors)
{
sceneId = id;
if (id == "Room1")
{
loadingScreen.SetActive(false);
+11 -3
View File
@@ -52,7 +52,7 @@ public class SceneLoader : MonoBehaviour
LoadNewRoom();
}
private async UniTaskVoid LoadNewRoom()
private async UniTaskVoid LoadNewRoom() // Aktuelle Methode zum Laden von Szenen
{
int sceneCount = SceneManager.sceneCount;
@@ -65,7 +65,15 @@ public class SceneLoader : MonoBehaviour
await SceneManager.UnloadSceneAsync(myScene);
}
}
await SceneManager.LoadSceneAsync(currentScene + 1, LoadSceneMode.Additive);
Debug.Log("Loaded Room " + currentScene + 1);
if (currentScene == SceneManager.sceneCountInBuildSettings-1)
{
await SceneManager.LoadSceneAsync(baseSceneIndex); // Lädt die Basis-Szene komplett neu, falls vorherige Szene die letzte war.
}
else
{
await SceneManager.LoadSceneAsync(currentScene + 1, LoadSceneMode.Additive); // Lädt die nächste Szene additiv
Debug.Log("Loaded Room " + (currentScene + 1));
}
}
}