Pulver trash maze sequence

This commit is contained in:
Michal Pikulski
2025-12-19 15:26:13 +01:00
parent 15c9ba0127
commit f0905f92d3
36 changed files with 2372 additions and 842 deletions

View File

@@ -0,0 +1,180 @@
using System.Collections;
using Core;
using Input;
using Items;
using Minigames.TrashMaze.Core;
using Minigames.TrashMaze.Data;
using Unity.Cinemachine;
using UnityEngine;
namespace Minigames.TrashMaze.Objects
{
/// <summary>
/// Trash Maze specific controller switch that transitions FROM Pulver back TO Trafalgar (maze exit).
/// Handles camera blend back to gameplay view and re-enables follower mode.
/// </summary>
public class TrashMazeSwitchToTrafalgar : ControllerSwitchItem
{
[Header("Trash Maze - To Trafalgar Settings")]
[Tooltip("Camera state to blend to (Gameplay camera)")]
[SerializeField] private TrashMazeCameraState targetCameraState = TrashMazeCameraState.Gameplay;
protected override IEnumerator SwitchControllerSequence()
{
_isSwitching = true;
// Step 1: Get controllers
var currentController = InputManager.Instance.GetActiveController();
var targetController = InputManager.Instance.GetController("trafalgar");
if (currentController == null || targetController == null)
{
Debug.LogError($"[TrashMazeSwitchToTrafalgar] Failed to get controllers!");
_isSwitching = false;
yield break;
}
GameObject currentGameObject = (currentController as MonoBehaviour)?.gameObject;
GameObject targetGameObject = (targetController as MonoBehaviour)?.gameObject;
Logging.Debug($"[TrashMazeSwitchToTrafalgar] Switching from Pulver to {targetGameObject?.name}");
// Step 2: Deactivate current controller (Pulver)
DeactivateCurrentController(currentController, currentGameObject);
// Explicitly deactivate PulverController to ensure it stops receiving input
if (currentGameObject != null)
{
var pulverController = currentGameObject.GetComponent<PulverController>();
if (pulverController != null)
{
pulverController.DeactivateController();
Logging.Debug("[TrashMazeSwitchToTrafalgar] Explicitly deactivated PulverController");
}
}
// Step 3: Start camera blend back to gameplay
StartCameraBlend();
// Step 4: Wait for camera blend to complete
yield return WaitForCameraBlend();
// Step 5: Unset Pulver as tracking target and set Trafalgar for gameplay camera
SetTrafalgarAsTrackingTarget(targetGameObject);
// Step 6: Activate Pulver's follower mode (so it follows Trafalgar)
if (currentGameObject != null)
{
var pulverFollower = currentGameObject.GetComponent<FollowerController>();
if (pulverFollower != null)
{
pulverFollower.ActivateFollower();
}
}
// Step 7: Activate Trafalgar controller
if (targetController is BasePlayerMovementController targetPlayerController)
{
targetPlayerController.ActivateController();
}
// Step 8: Switch InputManager to Trafalgar controller
bool switchSuccess = InputManager.Instance.SwitchToController("trafalgar");
if (switchSuccess)
{
Logging.Debug($"[TrashMazeSwitchToTrafalgar] Successfully switched to Trafalgar controller");
OnCharacterSwitch.Invoke();
}
else
{
Debug.LogError($"[TrashMazeSwitchToTrafalgar] Failed to switch to Trafalgar controller");
}
// Step 8: Mark as used if one-time use
if (isOneTime)
{
DisableVisual();
}
_isSwitching = false;
}
private void StartCameraBlend()
{
if (TrashMazeCameraController.Instance != null)
{
Logging.Debug($"[TrashMazeSwitchToTrafalgar] Starting camera blend to {targetCameraState}");
if (targetCameraState == TrashMazeCameraState.Gameplay)
{
TrashMazeCameraController.Instance.SwitchToGameplay();
}
else
{
Logging.Warning($"[TrashMazeSwitchToTrafalgar] Unexpected camera state: {targetCameraState}");
}
}
else
{
Debug.LogError("[TrashMazeSwitchToTrafalgar] TrashMazeCameraController instance not found!");
}
}
private IEnumerator WaitForCameraBlend()
{
CinemachineBrain brain = Camera.main?.GetComponent<CinemachineBrain>();
if (brain != null)
{
// Wait until blend is complete
while (brain.IsBlending)
{
yield return null;
}
Logging.Debug("[TrashMazeSwitchToTrafalgar] Camera blend completed");
}
else
{
// Fallback: wait a brief moment
yield return new WaitForSeconds(0.5f);
}
}
private void SetTrafalgarAsTrackingTarget(GameObject trafalgarGameObject)
{
if (TrashMazeCameraController.Instance != null)
{
// Clear maze camera tracking target
var mazeCamera = TrashMazeCameraController.Instance.GetMazeCamera();
if (mazeCamera != null)
{
mazeCamera.Follow = null;
mazeCamera.LookAt = null;
Logging.Debug($"[TrashMazeSwitchToTrafalgar] Cleared Pulver as tracking target from maze camera");
}
// Set Trafalgar as tracking target for gameplay camera
if (trafalgarGameObject != null)
{
var gameplayCamera = TrashMazeCameraController.Instance.GetGameplayCamera();
if (gameplayCamera != null)
{
gameplayCamera.Follow = trafalgarGameObject.transform;
gameplayCamera.LookAt = trafalgarGameObject.transform;
Logging.Debug($"[TrashMazeSwitchToTrafalgar] Set Trafalgar as tracking target for gameplay camera");
}
}
}
}
#if UNITY_EDITOR
private void OnValidate()
{
name = "TrashMazeSwitch_ToTrafalgar";
}
#endif
}
}