P2P host lobby: CONTINUE own save or NEW GAME (previous save backed up to MSCO_Saves, new world saved and sent to waiting players)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,53 @@ namespace MSCO
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Neues Spiel starten (der Spielstand wurde vorher geleert): über die Logik des NEW-GAME-Knopfs des Spiels,
|
||||
/// sonst wie CONTINUE - ohne Spielstand legt das Spiel dann eine frische Welt an.
|
||||
/// </summary>
|
||||
public static void StartNewGame()
|
||||
{
|
||||
PlayMakerFSM fsm;
|
||||
FsmState state;
|
||||
if (switchState != null && FindLoadState("newgame", out fsm, out state))
|
||||
{
|
||||
MscoLog.Info("[MSCO] Starting a new game via NEW GAME (" + fsm.name + " / " + state.Name + ")");
|
||||
switchState.Invoke(fsm.Fsm, new object[] { state });
|
||||
return;
|
||||
}
|
||||
MscoLog.Info("[MSCO] NEW GAME button not found - starting with an empty save");
|
||||
StartGame();
|
||||
}
|
||||
|
||||
/// <summary>FSM unter einem Objekt, dessen Name "hint" enthält, mit einem Zustand, der eine Szene lädt.</summary>
|
||||
static bool FindLoadState(string hint, out PlayMakerFSM fsm, out FsmState state)
|
||||
{
|
||||
fsm = null;
|
||||
state = null;
|
||||
// Nur aktive Objekte der Menü-Szene (die Spiel-Knöpfe sind nur unsichtbar, nicht abgeschaltet)
|
||||
foreach (Object o in Object.FindObjectsOfType(typeof(PlayMakerFSM)))
|
||||
{
|
||||
var candidate = (PlayMakerFSM)o;
|
||||
if (!HierarchyContains(candidate.transform, hint)) continue;
|
||||
foreach (FsmState s in candidate.FsmStates)
|
||||
{
|
||||
if (!s.ActionsLoaded) s.LoadActions();
|
||||
if (s.Actions == null) continue;
|
||||
foreach (FsmStateAction action in s.Actions)
|
||||
{
|
||||
var load = action as LoadLevel;
|
||||
if (load != null && load.levelName != null && !string.IsNullOrEmpty(load.levelName.Value))
|
||||
{
|
||||
fsm = candidate;
|
||||
state = s;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HierarchyContains(Transform t, string text)
|
||||
{
|
||||
for (; t != null; t = t.parent)
|
||||
|
||||
Reference in New Issue
Block a user