Rework of base interactables and managed behaviors
This commit is contained in:
@@ -4,19 +4,16 @@ using Core;
|
||||
using Input;
|
||||
using Interactions;
|
||||
using System.Threading.Tasks;
|
||||
using Bootstrap;
|
||||
using PuzzleS;
|
||||
using UnityEngine;
|
||||
using Core.SaveLoad;
|
||||
|
||||
// Added for IInteractionSettings
|
||||
|
||||
namespace Levels
|
||||
{
|
||||
/// <summary>
|
||||
/// Saveable data for MinigameSwitch state
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public class MinigameSwitchSaveData
|
||||
{
|
||||
public bool isUnlocked;
|
||||
@@ -46,8 +43,6 @@ namespace Levels
|
||||
{
|
||||
base.Awake(); // Register with save system
|
||||
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
|
||||
switchActive = true;
|
||||
if (iconRenderer == null)
|
||||
iconRenderer = GetComponent<SpriteRenderer>();
|
||||
@@ -61,16 +56,25 @@ namespace Levels
|
||||
{
|
||||
base.Start(); // Register with save system
|
||||
|
||||
// Direct subscription - PuzzleManager available by this point
|
||||
if (PuzzleManager.Instance != null)
|
||||
{
|
||||
PuzzleManager.Instance.OnAllPuzzlesComplete += HandleAllPuzzlesComplete;
|
||||
}
|
||||
|
||||
// If not restoring from save, start inactive
|
||||
if (!IsRestoringFromSave && !isUnlocked)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
base.OnDestroy(); // Unregister from save system
|
||||
if (PuzzleManager.Instance != null)
|
||||
{
|
||||
PuzzleManager.Instance.OnAllPuzzlesComplete -= HandleAllPuzzlesComplete;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAllPuzzlesComplete(PuzzleS.PuzzleLevelDataSO _)
|
||||
@@ -109,34 +113,56 @@ namespace Levels
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the start of an interaction (shows confirmation menu and switches the level if confirmed).
|
||||
/// High-level validation: Only allow interaction if unlocked.
|
||||
/// </summary>
|
||||
protected override void OnCharacterArrived()
|
||||
protected override bool CanBeClicked()
|
||||
{
|
||||
if (switchData == null || string.IsNullOrEmpty(switchData.targetLevelSceneName) || !switchActive)
|
||||
return;
|
||||
return base.CanBeClicked() && isUnlocked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup: Prevent re-entry while interaction is in progress.
|
||||
/// </summary>
|
||||
protected override void OnInteractionStarted()
|
||||
{
|
||||
switchActive = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main interaction logic: Spawn menu and switch input mode.
|
||||
/// </summary>
|
||||
protected override bool DoInteraction()
|
||||
{
|
||||
if (switchData == null || string.IsNullOrEmpty(switchData.targetLevelSceneName))
|
||||
{
|
||||
Debug.LogWarning("MinigameSwitch has no valid switchData!");
|
||||
return false;
|
||||
}
|
||||
|
||||
var menuPrefab = interactionSettings?.MinigameSwitchMenuPrefab;
|
||||
if (menuPrefab == null)
|
||||
{
|
||||
Debug.LogError("MinigameSwitchMenu prefab not assigned in InteractionSettings!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// Spawn the menu overlay (assume Canvas parent is handled in prefab setup)
|
||||
|
||||
// Spawn the menu overlay
|
||||
var menuGo = Instantiate(menuPrefab);
|
||||
var menu = menuGo.GetComponent<MinigameSwitchMenu>();
|
||||
if (menu == null)
|
||||
{
|
||||
Debug.LogError("MinigameSwitchMenu component missing on prefab!");
|
||||
Destroy(menuGo);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup menu with data and callbacks
|
||||
menu.Setup(switchData, OnLevelSelectedWrapper, OnMenuCancel);
|
||||
switchActive = false; // Prevent re-triggering until menu is closed
|
||||
|
||||
|
||||
// Switch input mode to UI only
|
||||
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||
|
||||
return true; // Menu spawned successfully
|
||||
}
|
||||
|
||||
private void OnLevelSelectedWrapper()
|
||||
@@ -156,10 +182,6 @@ namespace Levels
|
||||
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
PuzzleManager.Instance.OnAllPuzzlesComplete += HandleAllPuzzlesComplete;
|
||||
}
|
||||
|
||||
#region Save/Load Implementation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user