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>
This commit is contained in:
@@ -176,7 +176,17 @@ public static class Data
|
||||
|
||||
public static ReplayDetailInfo ReplayBattleInfo { get; set; }
|
||||
|
||||
public static BattleRecoveryInfo BattleRecoveryInfo { get; set; }
|
||||
private static BattleRecoveryInfo _battleRecoveryInfoFallback;
|
||||
public static BattleRecoveryInfo BattleRecoveryInfo
|
||||
{
|
||||
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.RecoveryInfo ?? _battleRecoveryInfoFallback;
|
||||
set
|
||||
{
|
||||
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
|
||||
if (c != null) c.RecoveryInfo = value;
|
||||
else _battleRecoveryInfoFallback = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static VoteData VoteInfo { get; set; }
|
||||
|
||||
|
||||
@@ -25,7 +25,11 @@ public static class ToolboxGame
|
||||
|
||||
private static Transform _gameTransform = null;
|
||||
|
||||
public static RealTimeNetworkAgent RealTimeNetworkAgent { get; private set; }
|
||||
private static RealTimeNetworkAgent _realTimeNetworkAgentFallback;
|
||||
public static RealTimeNetworkAgent RealTimeNetworkAgent
|
||||
{
|
||||
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.NetworkAgent ?? _realTimeNetworkAgentFallback;
|
||||
}
|
||||
|
||||
public static Transform GameTransform
|
||||
{
|
||||
@@ -56,15 +60,20 @@ public static class ToolboxGame
|
||||
|
||||
public static void SetRealTimeNetworkBattle(RealTimeNetworkAgent agent)
|
||||
{
|
||||
RealTimeNetworkAgent = agent;
|
||||
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
|
||||
if (c != null) c.NetworkAgent = agent;
|
||||
else _realTimeNetworkAgentFallback = agent;
|
||||
}
|
||||
|
||||
public static void DestroyNetworkAgent()
|
||||
{
|
||||
if (RealTimeNetworkAgent != null)
|
||||
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
|
||||
var current = c?.NetworkAgent ?? _realTimeNetworkAgentFallback;
|
||||
if (current != null)
|
||||
{
|
||||
Object.DestroyImmediate(RealTimeNetworkAgent.gameObject);
|
||||
RealTimeNetworkAgent = null;
|
||||
Object.DestroyImmediate(current.gameObject);
|
||||
if (c != null) c.NetworkAgent = null;
|
||||
else _realTimeNetworkAgentFallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user