maze_switching (#82)
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #82
This commit is contained in:
@@ -9,6 +9,7 @@ namespace Minigames.TrashMaze.Core
|
||||
/// Controls Pulver character movement in the Trash Maze.
|
||||
/// Inherits from BasePlayerMovementController for tap-to-move and hold-to-move.
|
||||
/// Updates global shader properties for vision radius system.
|
||||
/// Interaction capability (MoveToAndNotify) is provided by base class.
|
||||
/// </summary>
|
||||
public class PulverController : BasePlayerMovementController
|
||||
{
|
||||
@@ -51,6 +52,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()
|
||||
{
|
||||
@@ -86,6 +99,33 @@ namespace Minigames.TrashMaze.Core
|
||||
{
|
||||
_visionRadius = Mathf.Max(0.1f, radius);
|
||||
}
|
||||
|
||||
#region IInteractingCharacter Override
|
||||
|
||||
/// <summary>
|
||||
/// PulverController-specific interaction movement.
|
||||
/// Moves Pulver to the interactable using the main character's stop distance.
|
||||
/// No follower logic since Pulver is alone in the maze.
|
||||
/// </summary>
|
||||
public override async System.Threading.Tasks.Task<bool> MoveToInteractableAsync(Interactions.InteractableBase interactable)
|
||||
{
|
||||
// Use the same stop distance as main character for consistency
|
||||
float stopDistance = GameManager.Instance.PlayerStopDistance;
|
||||
|
||||
// Calculate stop position
|
||||
Vector3 stopPoint = Utils.MovementUtilities.CalculateStopPosition(
|
||||
interactable.transform.position,
|
||||
transform.position,
|
||||
stopDistance
|
||||
);
|
||||
|
||||
Logging.Debug($"[PulverController] Moving to interactable {interactable.gameObject.name} at stop distance {stopDistance}");
|
||||
|
||||
// Use MovementUtilities to handle movement
|
||||
return await Utils.MovementUtilities.MoveToPositionAsync(this, stopPoint);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d058b159d0aa43699eaba263b7b8c5a7
|
||||
timeCreated: 1765749988
|
||||
@@ -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>
|
||||
|
||||
3
Assets/Scripts/Minigames/TrashMaze/Data.meta
Normal file
3
Assets/Scripts/Minigames/TrashMaze/Data.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1c86c04b4dc4dd5add77ba3bb17f95e
|
||||
timeCreated: 1765749918
|
||||
19
Assets/Scripts/Minigames/TrashMaze/Data/TrashMazeEnums.cs
Normal file
19
Assets/Scripts/Minigames/TrashMaze/Data/TrashMazeEnums.cs
Normal 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e26aed52b5e4597b3cbba9191fe463b
|
||||
timeCreated: 1765749918
|
||||
Reference in New Issue
Block a user