feat: HTrace WSGI in der Lobby-Szene deaktivieren
Scene-Component HTraceLobbyToggle (in Main) hoert auf additive Szenen-Events und schaltet die HTraceWSGI-Component aus, solange die Lobby geladen ist, sonst an. Lobby-Szenenname im Inspector konfigurierbar. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
cdd9fa9532
commit
0128203160
3 files changed
+124
-62
No files matched your search
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Disables HTrace WSGI while the additively-loaded Lobby scene is present, and re-enables it everywhere else
|
||||
/// (Main-only, or the match map). HTraceWSGI lives permanently in the always-loaded Main scene, so it can't be
|
||||
/// authored per-scene; this watcher toggles it from Unity's additive scene load/unload events (NGO loads the
|
||||
/// gameplay scenes through the same SceneManager, so those events fire on every machine, host and client alike).
|
||||
///
|
||||
/// Authored on a plain GameObject in the always-loaded Main scene. It toggles the HTraceWSGI COMPONENT's `enabled`
|
||||
/// (not the GameObject), so its own host stays alive and can turn the GI back on. HTraceWSGI.OnDisable/OnEnable
|
||||
/// cleanly unregister/re-register the renderer feature, so flipping `enabled` fully stops and restarts the GI.
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public class HTraceLobbyToggle : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Name of the additively-loaded scene during which HTrace WSGI is disabled. Matches MatchManager.lobbySceneName.")]
|
||||
[SerializeField] private string lobbySceneName = "Lobby";
|
||||
|
||||
private HTraceWSGI.Scripts.HTraceWSGI _gi;
|
||||
|
||||
private void Awake() => Resolve();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
Apply();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) => Apply();
|
||||
private void OnSceneUnloaded(Scene scene) => Apply();
|
||||
|
||||
private void Resolve()
|
||||
{
|
||||
// Include inactive: the HTrace object may have been toggled off by DirectionalLightForHTrace's one-frame
|
||||
// re-init, and once we disable the component a plain search would still find it (component-level toggle),
|
||||
// but caching once is cheaper than re-scanning per event.
|
||||
if (!_gi) _gi = FindAnyObjectByType<HTraceWSGI.Scripts.HTraceWSGI>(FindObjectsInactive.Include);
|
||||
}
|
||||
|
||||
private void Apply()
|
||||
{
|
||||
Resolve();
|
||||
if (!_gi) return;
|
||||
|
||||
bool disableForLobby = IsLobbyLoaded();
|
||||
if (_gi.enabled == !disableForLobby) return; // already in the desired state
|
||||
_gi.enabled = !disableForLobby;
|
||||
}
|
||||
|
||||
private bool IsLobbyLoaded()
|
||||
{
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
Scene s = SceneManager.GetSceneAt(i);
|
||||
if (s.isLoaded && s.name == lobbySceneName) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57dab8a6b4fe83c4fa79b6acf54bf25b
|
||||
Reference in new issue
Block a user