Files
AppleHillsProduction/Assets/Scripts/Minigames/TrashMaze/Objects/TrashMazeSwitchToPulver.cs
2025-12-19 15:35:35 +01:00

110 lines
4.0 KiB
C#

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 TO Pulver (maze entrance).
/// Handles camera blend with midway teleportation to create the illusion of entering the maze.
/// </summary>
public class TrashMazeSwitchToPulver : ControllerSwitchItem
{
[Header("Trash Maze - To Pulver Settings")]
[Tooltip("Transform where Pulver should be teleported to (maze entrance)")]
[SerializeField] private Transform teleportTarget;
[Tooltip("Camera state to blend to (Maze camera)")]
[SerializeField] private TrashMazeCameraState targetCameraState = TrashMazeCameraState.Maze;
protected override IEnumerator SwitchControllerSequence()
{
_isSwitching = true;
// Step 1: Get controllers
var currentController = InputManager.Instance.GetActiveController();
var targetController = InputManager.Instance.GetController("pulver");
if (currentController == null || targetController == null)
{
Debug.LogError($"[TrashMazeSwitchToPulver] Failed to get controllers!");
_isSwitching = false;
yield break;
}
GameObject currentGameObject = (currentController as MonoBehaviour)?.gameObject;
GameObject targetGameObject = (targetController as MonoBehaviour)?.gameObject;
Logging.Debug($"[TrashMazeSwitchToPulver] Switching from {currentGameObject?.name} to Pulver");
// Step 2: Deactivate current controller (Trafalgar)
DeactivateCurrentController(currentController, currentGameObject);
// Step 3: Deactivate Pulver's follower controller (will be teleported)
if (targetGameObject != null)
{
var pulverFollower = targetGameObject.GetComponent<FollowerController>();
if (pulverFollower != null)
{
pulverFollower.DeactivateFollower();
}
}
// Step 4: Start camera blend to maze
TeleportationHelper.StartCameraBlend(targetCameraState);
// Step 5: Wait for halfway through the blend, teleport Pulver, and set tracking target
yield return TeleportationHelper.TeleportMidBlendAndSetTracking(targetGameObject, teleportTarget, targetCameraState);
// Step 6: Wait for camera blend to complete
yield return TeleportationHelper.WaitForCameraBlend();
// Step 7: Activate Pulver controller
if (targetController is BasePlayerMovementController targetPlayerController)
{
targetPlayerController.ActivateController();
}
// Step 8: Switch InputManager to Pulver controller
bool switchSuccess = InputManager.Instance.SwitchToController("pulver");
if (switchSuccess)
{
Logging.Debug($"[TrashMazeSwitchToPulver] Successfully switched to Pulver controller");
OnCharacterSwitch.Invoke();
}
else
{
Debug.LogError($"[TrashMazeSwitchToPulver] Failed to switch to Pulver controller");
}
// Step 9: Mark as used if one-time use
if (isOneTime)
{
DisableVisual();
}
_isSwitching = false;
}
#if UNITY_EDITOR
private void OnValidate()
{
name = "TrashMazeSwitch_ToPulver";
// Default to Maze camera
if (targetCameraState != TrashMazeCameraState.Maze)
{
targetCameraState = TrashMazeCameraState.Maze;
}
}
#endif
}
}