Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/ToolboxGame.cs
gamer147 fe146fde50 refactor(engine-ambient): ViewerId/RealTimeNetworkAgent/BattleRecoveryInfo read ambient first
Step 4 of multi-instancing migration. Three additional per-battle statics
front-fronted by BattleAmbient.Current, each with a static fallback for
unwrapped callers. ViewerId's SavedataManager-persisting setter is preserved
on the fallback path; inside a scope, the setter is a no-op (the per-battle
perspective is fixed at scope entry).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-06-07 21:37:58 -04:00

96 lines
2.3 KiB
C#

using System.Collections;
using UnityEngine;
namespace Wizard;
public static class ToolboxGame
{
private enum SYSTEM_INIT
{
SYSTEM_NOT_READY,
SYSTEM_READY
}
public static SetUp SetUp = null;
public static UIManager UIManager = null;
public static GameMgr GameManager = null;
public static bool isLoadFromLocal = false;
public static bool isLoadLocalSound = false;
public static bool bDebugLogMode = true;
private static Transform _gameTransform = null;
private static RealTimeNetworkAgent _realTimeNetworkAgentFallback;
public static RealTimeNetworkAgent RealTimeNetworkAgent
{
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.NetworkAgent ?? _realTimeNetworkAgentFallback;
}
public static Transform GameTransform
{
get
{
if (!_gameTransform)
{
GameObject gameObject = GameObject.Find("_Game");
if ((bool)gameObject)
{
_gameTransform = gameObject.transform;
}
}
return _gameTransform;
}
}
public static void Clear()
{
UIManager = null;
GameManager = null;
}
public static void ClearUIManager()
{
UIManager = null;
}
public static void SetRealTimeNetworkBattle(RealTimeNetworkAgent agent)
{
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
if (c != null) c.NetworkAgent = agent;
else _realTimeNetworkAgentFallback = agent;
}
public static void DestroyNetworkAgent()
{
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
var current = c?.NetworkAgent ?? _realTimeNetworkAgentFallback;
if (current != null)
{
Object.DestroyImmediate(current.gameObject);
if (c != null) c.NetworkAgent = null;
else _realTimeNetworkAgentFallback = null;
}
}
public static IEnumerator CreateRealTimeNetworkBattleAgent(Matching matching = null)
{
string loadObjectPath = "TurnBase/_TurnBaseManager";
if (GameMgr.GetIns().IsAINetwork)
{
loadObjectPath = "TurnBase/_AINetworkBaseManager";
}
yield return BattleCoroutine.GetInstance().StartCoroutine(GameMgr.GetIns().GetPrefabMgr().LoadAync(loadObjectPath));
NGUITools.AddChild(GameObject.Find("_Game"), GameMgr.GetIns().GetPrefabMgr().Get(loadObjectPath));
yield return null;
if (matching != null)
{
RealTimeNetworkAgent.SettingMatchingClass(matching);
}
}
}