Working item switcher

This commit is contained in:
Michal Pikulski
2025-12-15 00:05:35 +01:00
parent a78085adee
commit 8995dd1949
24 changed files with 2046 additions and 57 deletions

View File

@@ -51,6 +51,18 @@ namespace Minigames.TrashMaze.Core
_visionRadius = configs.FollowerMovement.TrashMazeVisionRadius;
Logging.Debug($"[PulverController] Loaded vision radius from settings: {_visionRadius}");
}
internal override void OnManagedStart()
{
base.OnManagedStart();
// Register with InputManager (not as default consumer)
if (InputManager.Instance != null)
{
InputManager.Instance.RegisterController("pulver", this, setAsDefaultConsumer: false);
Logging.Debug($"[PulverController] Registered controller '{gameObject.name}'");
}
}
protected override void Update()
{

View File

@@ -0,0 +1,106 @@
using Common.Camera;
using Core;
using Minigames.TrashMaze.Data;
using Unity.Cinemachine;
namespace Minigames.TrashMaze.Core
{
/// <summary>
/// Manages camera states for the Trash Maze minigame.
/// Handles transitions between Gameplay (level exploration) and Maze (inside maze exploration) cameras.
/// Provides singleton access for easy camera switching from items and other systems.
/// </summary>
public class TrashMazeCameraController : CameraStateManager<TrashMazeCameraState>
{
#region Singleton
private static TrashMazeCameraController _instance;
/// <summary>
/// Singleton instance of the camera controller
/// </summary>
public static TrashMazeCameraController Instance => _instance;
#endregion
#region Lifecycle
internal override void OnManagedAwake()
{
// Base class handles InitializeCameraMap() and ValidateCameras()
base.OnManagedAwake();
// Set singleton
if (_instance != null && _instance != this)
{
Logging.Warning("[TrashMazeCameraController] Multiple instances detected! Destroying duplicate.");
Destroy(gameObject);
return;
}
_instance = this;
}
internal override void OnManagedStart()
{
base.OnManagedStart();
// Start in gameplay camera by default
SwitchToGameplay();
}
internal override void OnManagedDestroy()
{
base.OnManagedDestroy();
if (_instance == this)
{
_instance = null;
}
}
#endregion
#region Public API
/// <summary>
/// Switch to the main gameplay camera (level exploration)
/// </summary>
public void SwitchToGameplay()
{
SwitchToState(TrashMazeCameraState.Gameplay);
if (showDebugLogs)
Logging.Debug("[TrashMazeCameraController] Switched to Gameplay camera");
}
/// <summary>
/// Switch to the maze camera (inside maze exploration)
/// </summary>
public void SwitchToMaze()
{
SwitchToState(TrashMazeCameraState.Maze);
if (showDebugLogs)
Logging.Debug("[TrashMazeCameraController] Switched to Maze camera");
}
/// <summary>
/// Get the gameplay camera
/// </summary>
public CinemachineCamera GetGameplayCamera()
{
return GetCamera(TrashMazeCameraState.Gameplay);
}
/// <summary>
/// Get the maze camera
/// </summary>
public CinemachineCamera GetMazeCamera()
{
return GetCamera(TrashMazeCameraState.Maze);
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d058b159d0aa43699eaba263b7b8c5a7
timeCreated: 1765749988

View File

@@ -13,8 +13,7 @@ namespace Minigames.TrashMaze.Core
public static TrashMazeController Instance { get; private set; }
[Header("Player")]
[SerializeField] private PulverController pulverPrefab;
[SerializeField] private Transform startPosition;
[SerializeField] private PulverController pulverController;
[Header("Background")]
[Tooltip("Background sprite renderer - world size and center are inferred from its bounds")]
@@ -27,7 +26,6 @@ namespace Minigames.TrashMaze.Core
private static readonly int WorldSizeID = Shader.PropertyToID("_WorldSize");
private static readonly int WorldCenterID = Shader.PropertyToID("_WorldCenter");
private PulverController _pulverInstance;
private bool _mazeCompleted;
internal override void OnManagedAwake()
@@ -59,8 +57,8 @@ namespace Minigames.TrashMaze.Core
// Infer world bounds from background renderer and set shader globals
ApplyBackgroundBoundsToShader();
// Spawn player
SpawnPulver();
// Validate player reference
InitializePulver();
Logging.Debug("[TrashMazeController] Trash Maze initialized");
}
@@ -108,18 +106,15 @@ namespace Minigames.TrashMaze.Core
$"Size=({worldSize.x:F2}, {worldSize.y:F2}), Center=({worldCenter.x:F2}, {worldCenter.y:F2})");
}
private void SpawnPulver()
private void InitializePulver()
{
if (pulverPrefab == null)
if (pulverController == null)
{
Logging.Error("[TrashMazeController] Pulver prefab not assigned!");
Logging.Error("[TrashMazeController] PulverController reference not assigned! Please assign it in the Inspector.");
return;
}
Vector3 spawnPosition = startPosition != null ? startPosition.position : Vector3.zero;
_pulverInstance = Instantiate(pulverPrefab, spawnPosition, Quaternion.identity);
Logging.Debug($"[TrashMazeController] Pulver spawned at {spawnPosition}");
Logging.Debug($"[TrashMazeController] Pulver controller initialized at {pulverController.transform.position}");
}
/// <summary>

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c1c86c04b4dc4dd5add77ba3bb17f95e
timeCreated: 1765749918

View File

@@ -0,0 +1,19 @@
namespace Minigames.TrashMaze.Data
{
/// <summary>
/// Camera states for Trash Maze minigame
/// </summary>
public enum TrashMazeCameraState
{
/// <summary>
/// Main gameplay camera following Trafalgar around the level
/// </summary>
Gameplay,
/// <summary>
/// Maze camera following Pulver when exploring the maze alone
/// </summary>
Maze
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e26aed52b5e4597b3cbba9191fe463b
timeCreated: 1765749918