Working MVP code for Valentines
This commit is contained in:
3
Assets/Scripts/Minigames/Airplane/Core.meta
Normal file
3
Assets/Scripts/Minigames/Airplane/Core.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48e6932cbd9645bfac8add678e705033
|
||||
timeCreated: 1764851249
|
||||
160
Assets/Scripts/Minigames/Airplane/Core/AirplaneCameraManager.cs
Normal file
160
Assets/Scripts/Minigames/Airplane/Core/AirplaneCameraManager.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using Common.Camera;
|
||||
using Core;
|
||||
using Minigames.Airplane.Data;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages camera states for the airplane minigame.
|
||||
/// Handles transitions between Intro, NextPerson, Aiming, and Flight cameras.
|
||||
/// Flight camera includes follow functionality for tracking airplanes.
|
||||
/// </summary>
|
||||
public class AirplaneCameraManager : CameraStateManager<AirplaneCameraState>
|
||||
{
|
||||
#region Singleton
|
||||
|
||||
private static AirplaneCameraManager _instance;
|
||||
public static AirplaneCameraManager Instance => _instance;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector References
|
||||
|
||||
[Header("Cinemachine Cameras")]
|
||||
[Tooltip("Camera for intro sequence")]
|
||||
[SerializeField] private CinemachineCamera introCamera;
|
||||
|
||||
[Tooltip("Camera for showing the next person")]
|
||||
[SerializeField] private CinemachineCamera nextPersonCamera;
|
||||
|
||||
[Tooltip("Camera for aiming view")]
|
||||
[SerializeField] private CinemachineCamera aimingCamera;
|
||||
|
||||
[Tooltip("Camera that follows the airplane (should have CinemachineFollow)")]
|
||||
[SerializeField] private CinemachineCamera flightCamera;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Set singleton
|
||||
if (_instance != null && _instance != this)
|
||||
{
|
||||
Logging.Warning("[AirplaneCameraManager] Multiple instances detected! Destroying duplicate.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
_instance = this;
|
||||
|
||||
// Register cameras
|
||||
RegisterCamera(AirplaneCameraState.Intro, introCamera);
|
||||
RegisterCamera(AirplaneCameraState.NextPerson, nextPersonCamera);
|
||||
RegisterCamera(AirplaneCameraState.Aiming, aimingCamera);
|
||||
RegisterCamera(AirplaneCameraState.Flight, flightCamera);
|
||||
|
||||
// Finalize initialization
|
||||
FinalizeInitialization();
|
||||
|
||||
// Validate
|
||||
ValidateCameras();
|
||||
}
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
if (_instance == this)
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation
|
||||
|
||||
protected override void ValidateCameras()
|
||||
{
|
||||
if (introCamera == null)
|
||||
{
|
||||
Logging.Error("[AirplaneCameraManager] Intro camera not assigned!");
|
||||
}
|
||||
|
||||
if (nextPersonCamera == null)
|
||||
{
|
||||
Logging.Error("[AirplaneCameraManager] Next person camera not assigned!");
|
||||
}
|
||||
|
||||
if (aimingCamera == null)
|
||||
{
|
||||
Logging.Error("[AirplaneCameraManager] Aiming camera not assigned!");
|
||||
}
|
||||
|
||||
if (flightCamera == null)
|
||||
{
|
||||
Logging.Error("[AirplaneCameraManager] Flight camera not assigned!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verify flight camera has follow component
|
||||
var followComponent = flightCamera.GetComponent<CinemachineFollow>();
|
||||
if (followComponent == null)
|
||||
{
|
||||
Logging.Warning("[AirplaneCameraManager] Flight camera missing CinemachineFollow component!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Flight Camera Follow
|
||||
|
||||
/// <summary>
|
||||
/// Start following an airplane with the flight camera
|
||||
/// </summary>
|
||||
public void StartFollowingAirplane(Transform airplaneTransform)
|
||||
{
|
||||
if (flightCamera == null)
|
||||
{
|
||||
Logging.Warning("[AirplaneCameraManager] Cannot follow airplane - flight camera not assigned!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (airplaneTransform == null)
|
||||
{
|
||||
Logging.Warning("[AirplaneCameraManager] Cannot follow null airplane transform!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the follow target on the flight camera
|
||||
flightCamera.Target.TrackingTarget = airplaneTransform;
|
||||
|
||||
// Switch to flight camera
|
||||
SwitchToState(AirplaneCameraState.Flight);
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneCameraManager] Now following airplane: {airplaneTransform.gameObject.name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop following the airplane and clear the target
|
||||
/// </summary>
|
||||
public void StopFollowingAirplane()
|
||||
{
|
||||
if (flightCamera == null) return;
|
||||
|
||||
// Clear the follow target
|
||||
flightCamera.Target.TrackingTarget = null;
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneCameraManager] Stopped following airplane");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34b856742e12475793b85a0a3019d67b
|
||||
timeCreated: 1764851249
|
||||
281
Assets/Scripts/Minigames/Airplane/Core/AirplaneController.cs
Normal file
281
Assets/Scripts/Minigames/Airplane/Core/AirplaneController.cs
Normal file
@@ -0,0 +1,281 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls airplane movement using calculated (non-physics-based) flight.
|
||||
/// Uses Rigidbody2D for velocity application but not for simulation.
|
||||
/// Follows an arc trajectory based on launch parameters.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody2D), typeof(Collider2D))]
|
||||
public class AirplaneController : ManagedBehaviour
|
||||
{
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when airplane is launched. Parameters: (AirplaneController airplane)
|
||||
/// </summary>
|
||||
public event Action<AirplaneController> OnLaunched;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when airplane lands/stops. Parameters: (AirplaneController airplane)
|
||||
/// </summary>
|
||||
public event Action<AirplaneController> OnLanded;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when airplane hits a target. Parameters: (AirplaneController airplane, string targetName)
|
||||
/// </summary>
|
||||
public event Action<AirplaneController, string> OnTargetHit;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when airplane times out. Parameters: (AirplaneController airplane)
|
||||
/// </summary>
|
||||
public event Action<AirplaneController> OnTimeout;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector Properties
|
||||
|
||||
[Header("Flight Settings")]
|
||||
[Tooltip("Gravity multiplier for arc calculation")]
|
||||
[SerializeField] private float gravity = 9.81f;
|
||||
|
||||
[Tooltip("Mass of the airplane")]
|
||||
[SerializeField] private float mass = 1f;
|
||||
|
||||
[Tooltip("Maximum flight time before timeout (seconds)")]
|
||||
[SerializeField] private float maxFlightTime = 10f;
|
||||
|
||||
[Header("Visual")]
|
||||
[Tooltip("Should airplane rotate to face velocity direction?")]
|
||||
[SerializeField] private bool rotateToVelocity = true;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] private bool showDebugLogs = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private Rigidbody2D rb2D;
|
||||
private Collider2D airplaneCollider;
|
||||
private Vector2 currentVelocity;
|
||||
private bool isFlying = false;
|
||||
private float flightTimer = 0f;
|
||||
private string lastHitTarget = null;
|
||||
|
||||
public bool IsFlying => isFlying;
|
||||
public Vector2 CurrentVelocity => currentVelocity;
|
||||
public string LastHitTarget => lastHitTarget;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Cache components
|
||||
rb2D = GetComponent<Rigidbody2D>();
|
||||
airplaneCollider = GetComponent<Collider2D>();
|
||||
|
||||
// Configure Rigidbody2D
|
||||
if (rb2D != null)
|
||||
{
|
||||
rb2D.isKinematic = true; // Not physics-simulated
|
||||
rb2D.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
|
||||
}
|
||||
|
||||
// Configure Collider2D as trigger
|
||||
if (airplaneCollider != null)
|
||||
{
|
||||
airplaneCollider.isTrigger = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Launch
|
||||
|
||||
/// <summary>
|
||||
/// Launch the airplane with calculated velocity
|
||||
/// </summary>
|
||||
public void Launch(Vector2 direction, float force)
|
||||
{
|
||||
if (isFlying)
|
||||
{
|
||||
Logging.Warning($"[AirplaneController] {gameObject.name} already flying!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate initial velocity from force and mass
|
||||
float initialSpeed = force / mass;
|
||||
currentVelocity = direction.normalized * initialSpeed;
|
||||
|
||||
isFlying = true;
|
||||
flightTimer = 0f;
|
||||
lastHitTarget = null;
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[AirplaneController] Launched - Force: {force:F2}, Mass: {mass:F2}, " +
|
||||
$"Initial Speed: {initialSpeed:F2}, Direction: {direction}");
|
||||
}
|
||||
|
||||
OnLaunched?.Invoke(this);
|
||||
|
||||
// Start flight update
|
||||
StartCoroutine(FlightUpdateCoroutine());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Flight Update
|
||||
|
||||
/// <summary>
|
||||
/// Update airplane flight physics each frame
|
||||
/// </summary>
|
||||
private IEnumerator FlightUpdateCoroutine()
|
||||
{
|
||||
while (isFlying)
|
||||
{
|
||||
float deltaTime = Time.fixedDeltaTime;
|
||||
|
||||
// Apply gravity to velocity
|
||||
currentVelocity.y -= gravity * deltaTime;
|
||||
|
||||
// Apply velocity to rigidbody
|
||||
if (rb2D != null)
|
||||
{
|
||||
rb2D.linearVelocity = currentVelocity;
|
||||
}
|
||||
|
||||
// Rotate to face velocity direction
|
||||
if (rotateToVelocity && currentVelocity.magnitude > 0.1f)
|
||||
{
|
||||
float angle = Mathf.Atan2(currentVelocity.y, currentVelocity.x) * Mathf.Rad2Deg;
|
||||
transform.rotation = Quaternion.Euler(0, 0, angle);
|
||||
}
|
||||
|
||||
// Update flight timer
|
||||
flightTimer += deltaTime;
|
||||
|
||||
// Check for timeout
|
||||
if (flightTimer >= maxFlightTime)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneController] Flight timeout reached");
|
||||
HandleTimeout();
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Check if airplane has landed (velocity near zero or hit ground)
|
||||
if (currentVelocity.y < -0.1f && transform.position.y < -10f) // Below screen
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneController] Airplane went off screen");
|
||||
HandleLanding();
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Collision Detection
|
||||
|
||||
/// <summary>
|
||||
/// Detect trigger collisions with targets
|
||||
/// </summary>
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!isFlying) return;
|
||||
|
||||
// Check if it's a target
|
||||
var target = other.GetComponent<Minigames.Airplane.Targets.AirplaneTarget>();
|
||||
if (target != null)
|
||||
{
|
||||
lastHitTarget = target.TargetName;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneController] Hit target: {lastHitTarget}");
|
||||
|
||||
OnTargetHit?.Invoke(this, lastHitTarget);
|
||||
|
||||
// Land after hitting target
|
||||
HandleLanding();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Landing and Timeout
|
||||
|
||||
/// <summary>
|
||||
/// Handle airplane landing
|
||||
/// </summary>
|
||||
private void HandleLanding()
|
||||
{
|
||||
if (!isFlying) return;
|
||||
|
||||
isFlying = false;
|
||||
currentVelocity = Vector2.zero;
|
||||
|
||||
if (rb2D != null)
|
||||
{
|
||||
rb2D.linearVelocity = Vector2.zero;
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneController] Airplane landed");
|
||||
|
||||
OnLanded?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle airplane timeout
|
||||
/// </summary>
|
||||
private void HandleTimeout()
|
||||
{
|
||||
if (!isFlying) return;
|
||||
|
||||
isFlying = false;
|
||||
currentVelocity = Vector2.zero;
|
||||
|
||||
if (rb2D != null)
|
||||
{
|
||||
rb2D.linearVelocity = Vector2.zero;
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneController] Airplane timed out");
|
||||
|
||||
OnTimeout?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Public method to force stop the airplane
|
||||
/// </summary>
|
||||
public void ForceStop()
|
||||
{
|
||||
HandleLanding();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cleanup
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
// Stop any coroutines
|
||||
StopAllCoroutines();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cdaac23e969495d8c0deeaf236c259e
|
||||
timeCreated: 1764851277
|
||||
553
Assets/Scripts/Minigames/Airplane/Core/AirplaneGameManager.cs
Normal file
553
Assets/Scripts/Minigames/Airplane/Core/AirplaneGameManager.cs
Normal file
@@ -0,0 +1,553 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.Airplane.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Main game manager for the airplane minigame.
|
||||
/// Orchestrates game flow through state machine with distinct phases:
|
||||
/// Intro -> NextPerson -> Aiming -> Flying -> Evaluating -> (repeat or GameOver)
|
||||
/// </summary>
|
||||
public class AirplaneGameManager : ManagedBehaviour
|
||||
{
|
||||
#region Singleton
|
||||
|
||||
private static AirplaneGameManager _instance;
|
||||
public static AirplaneGameManager Instance => _instance;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector References
|
||||
|
||||
[Header("Core Systems")]
|
||||
[SerializeField] private PersonQueue personQueue;
|
||||
[SerializeField] private AirplaneCameraManager cameraManager;
|
||||
[SerializeField] private AirplaneLaunchController launchController;
|
||||
[SerializeField] private AirplaneTargetValidator targetValidator;
|
||||
|
||||
[Header("Targets")]
|
||||
[Tooltip("All targets in the scene (for highlighting)")]
|
||||
[SerializeField] private Targets.AirplaneTarget[] allTargets;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] private bool showDebugLogs = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when game state changes. Parameters: (AirplaneGameState oldState, AirplaneGameState newState)
|
||||
/// </summary>
|
||||
public event Action<AirplaneGameState, AirplaneGameState> OnStateChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a person starts their turn. Parameters: (PersonData person)
|
||||
/// </summary>
|
||||
public event Action<PersonData> OnPersonStartTurn;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a person finishes their turn. Parameters: (PersonData person, bool success)
|
||||
/// </summary>
|
||||
public event Action<PersonData, bool> OnPersonFinishTurn;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when game completes
|
||||
/// </summary>
|
||||
public event Action OnGameComplete;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private AirplaneGameState _currentState = AirplaneGameState.Intro;
|
||||
private PersonData _currentPerson;
|
||||
private AirplaneController _currentAirplane;
|
||||
private int _successCount;
|
||||
private int _failCount;
|
||||
private int _totalTurns;
|
||||
|
||||
public AirplaneGameState CurrentState => _currentState;
|
||||
public PersonData CurrentPerson => _currentPerson;
|
||||
public int SuccessCount => _successCount;
|
||||
public int FailCount => _failCount;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Set singleton
|
||||
if (_instance != null && _instance != this)
|
||||
{
|
||||
Logging.Warning("[AirplaneGameManager] Multiple instances detected! Destroying duplicate.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
_instance = this;
|
||||
|
||||
// Validate references
|
||||
ValidateReferences();
|
||||
}
|
||||
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
// Subscribe to events
|
||||
if (launchController != null)
|
||||
{
|
||||
launchController.OnAirplaneLaunched += HandleAirplaneLaunched;
|
||||
}
|
||||
|
||||
if (targetValidator != null)
|
||||
{
|
||||
targetValidator.OnCorrectTargetHit += HandleCorrectTargetHit;
|
||||
targetValidator.OnWrongTargetHit += HandleWrongTargetHit;
|
||||
targetValidator.OnMissedAllTargets += HandleMissedTargets;
|
||||
}
|
||||
|
||||
// Start the game
|
||||
StartGame();
|
||||
}
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
// Unsubscribe from events
|
||||
if (launchController != null)
|
||||
{
|
||||
launchController.OnAirplaneLaunched -= HandleAirplaneLaunched;
|
||||
}
|
||||
|
||||
if (targetValidator != null)
|
||||
{
|
||||
targetValidator.OnCorrectTargetHit -= HandleCorrectTargetHit;
|
||||
targetValidator.OnWrongTargetHit -= HandleWrongTargetHit;
|
||||
targetValidator.OnMissedAllTargets -= HandleMissedTargets;
|
||||
}
|
||||
|
||||
if (_instance == this)
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation
|
||||
|
||||
private void ValidateReferences()
|
||||
{
|
||||
if (personQueue == null)
|
||||
{
|
||||
Logging.Error("[AirplaneGameManager] PersonQueue not assigned!");
|
||||
}
|
||||
|
||||
if (cameraManager == null)
|
||||
{
|
||||
Logging.Error("[AirplaneGameManager] AirplaneCameraManager not assigned!");
|
||||
}
|
||||
|
||||
if (launchController == null)
|
||||
{
|
||||
Logging.Error("[AirplaneGameManager] AirplaneLaunchController not assigned!");
|
||||
}
|
||||
|
||||
if (targetValidator == null)
|
||||
{
|
||||
Logging.Error("[AirplaneGameManager] AirplaneTargetValidator not assigned!");
|
||||
}
|
||||
|
||||
if (allTargets == null || allTargets.Length == 0)
|
||||
{
|
||||
Logging.Warning("[AirplaneGameManager] No targets assigned!");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region State Management
|
||||
|
||||
private void ChangeState(AirplaneGameState newState)
|
||||
{
|
||||
AirplaneGameState oldState = _currentState;
|
||||
_currentState = newState;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneGameManager] State: {oldState} -> {newState}");
|
||||
|
||||
OnStateChanged?.Invoke(oldState, newState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Game Flow
|
||||
|
||||
/// <summary>
|
||||
/// Start the game
|
||||
/// </summary>
|
||||
public void StartGame()
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] ===== GAME STARTING =====");
|
||||
|
||||
ChangeState(AirplaneGameState.Intro);
|
||||
StartCoroutine(IntroSequence());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intro sequence (stub for MVP)
|
||||
/// </summary>
|
||||
private IEnumerator IntroSequence()
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Playing intro sequence...");
|
||||
|
||||
// Switch to intro camera
|
||||
if (cameraManager != null)
|
||||
{
|
||||
cameraManager.SwitchToState(AirplaneCameraState.Intro);
|
||||
}
|
||||
|
||||
// Wait for intro duration (stub)
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Intro complete");
|
||||
|
||||
// Move to first person
|
||||
StartCoroutine(SetupNextPerson());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup the next person's turn
|
||||
/// </summary>
|
||||
private IEnumerator SetupNextPerson()
|
||||
{
|
||||
// Check if there are more people
|
||||
if (personQueue == null || !personQueue.HasMorePeople())
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] No more people, ending game");
|
||||
StartCoroutine(GameOver());
|
||||
yield break;
|
||||
}
|
||||
|
||||
ChangeState(AirplaneGameState.NextPerson);
|
||||
|
||||
// Pop next person
|
||||
_currentPerson = personQueue.PopNextPerson();
|
||||
_totalTurns++;
|
||||
|
||||
if (_currentPerson == null)
|
||||
{
|
||||
Logging.Error("[AirplaneGameManager] Failed to get next person!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[AirplaneGameManager] === Turn {_totalTurns}: {_currentPerson.personName} ===" +
|
||||
$"\n Target: {_currentPerson.targetName}");
|
||||
}
|
||||
|
||||
OnPersonStartTurn?.Invoke(_currentPerson);
|
||||
|
||||
// Switch to next person camera
|
||||
if (cameraManager != null)
|
||||
{
|
||||
cameraManager.SwitchToState(AirplaneCameraState.NextPerson);
|
||||
}
|
||||
|
||||
// Wait for person introduction (stub)
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
// Set expected target
|
||||
if (targetValidator != null)
|
||||
{
|
||||
targetValidator.SetExpectedTarget(_currentPerson.targetName);
|
||||
}
|
||||
|
||||
// Highlight the target
|
||||
HighlightTarget(_currentPerson.targetName);
|
||||
|
||||
// Enter aiming state
|
||||
EnterAimingState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enter aiming state - player can aim and launch
|
||||
/// </summary>
|
||||
private void EnterAimingState()
|
||||
{
|
||||
ChangeState(AirplaneGameState.Aiming);
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Ready to aim and launch!");
|
||||
|
||||
// Switch to aiming camera
|
||||
if (cameraManager != null)
|
||||
{
|
||||
cameraManager.SwitchToState(AirplaneCameraState.Aiming);
|
||||
}
|
||||
|
||||
// Enable launch controller
|
||||
if (launchController != null)
|
||||
{
|
||||
launchController.Enable();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Handle airplane launched event
|
||||
/// </summary>
|
||||
private void HandleAirplaneLaunched(AirplaneController airplane)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Airplane launched!");
|
||||
|
||||
_currentAirplane = airplane;
|
||||
|
||||
// Disable launch controller
|
||||
if (launchController != null)
|
||||
{
|
||||
launchController.Disable();
|
||||
}
|
||||
|
||||
ChangeState(AirplaneGameState.Flying);
|
||||
|
||||
// Start following airplane with camera
|
||||
if (cameraManager != null)
|
||||
{
|
||||
cameraManager.StartFollowingAirplane(airplane.transform);
|
||||
}
|
||||
|
||||
// Subscribe to airplane events
|
||||
airplane.OnTargetHit += HandleAirplaneHitTarget;
|
||||
airplane.OnLanded += HandleAirplaneLanded;
|
||||
airplane.OnTimeout += HandleAirplaneTimeout;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle airplane hitting a target
|
||||
/// </summary>
|
||||
private void HandleAirplaneHitTarget(AirplaneController airplane, string targetName)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneGameManager] Airplane hit target: {targetName}");
|
||||
|
||||
// Validate the hit
|
||||
if (targetValidator != null)
|
||||
{
|
||||
targetValidator.ValidateHit(targetName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle airplane landing
|
||||
/// </summary>
|
||||
private void HandleAirplaneLanded(AirplaneController airplane)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Airplane landed");
|
||||
|
||||
// If no target was hit, count as miss
|
||||
if (targetValidator != null && !targetValidator.HasValidated)
|
||||
{
|
||||
targetValidator.HandleMiss();
|
||||
}
|
||||
|
||||
// Evaluate result
|
||||
StartCoroutine(EvaluateResult());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle airplane timeout
|
||||
/// </summary>
|
||||
private void HandleAirplaneTimeout(AirplaneController airplane)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Airplane timed out");
|
||||
|
||||
// Count as miss
|
||||
if (targetValidator != null && !targetValidator.HasValidated)
|
||||
{
|
||||
targetValidator.HandleMiss();
|
||||
}
|
||||
|
||||
// Evaluate result
|
||||
StartCoroutine(EvaluateResult());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle correct target hit
|
||||
/// </summary>
|
||||
private void HandleCorrectTargetHit(string targetName)
|
||||
{
|
||||
_successCount++;
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneGameManager] ✓ SUCCESS! Hit correct target: {targetName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle wrong target hit
|
||||
/// </summary>
|
||||
private void HandleWrongTargetHit(string expectedTarget, string actualTarget)
|
||||
{
|
||||
_failCount++;
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneGameManager] ✗ FAIL! Expected: {expectedTarget}, Hit: {actualTarget}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle missed all targets
|
||||
/// </summary>
|
||||
private void HandleMissedTargets()
|
||||
{
|
||||
_failCount++;
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] ✗ MISS! Didn't hit any target");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Evaluation and Cleanup
|
||||
|
||||
/// <summary>
|
||||
/// Evaluate the result of the turn
|
||||
/// </summary>
|
||||
private IEnumerator EvaluateResult()
|
||||
{
|
||||
ChangeState(AirplaneGameState.Evaluating);
|
||||
|
||||
// Stop following airplane
|
||||
if (cameraManager != null)
|
||||
{
|
||||
cameraManager.StopFollowingAirplane();
|
||||
}
|
||||
|
||||
// Determine success/failure
|
||||
bool success = targetValidator != null &&
|
||||
targetValidator.HasValidated &&
|
||||
_currentAirplane != null &&
|
||||
!string.IsNullOrEmpty(_currentAirplane.LastHitTarget) &&
|
||||
targetValidator.IsExpectedTarget(_currentAirplane.LastHitTarget);
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[AirplaneGameManager] Turn result: {(success ? "SUCCESS" : "FAILURE")}" +
|
||||
$"\n Score: {_successCount} / {_totalTurns}");
|
||||
}
|
||||
|
||||
OnPersonFinishTurn?.Invoke(_currentPerson, success);
|
||||
|
||||
// Wait for evaluation display (stub)
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
// Clean up airplane
|
||||
if (_currentAirplane != null)
|
||||
{
|
||||
Destroy(_currentAirplane.gameObject);
|
||||
_currentAirplane = null;
|
||||
}
|
||||
|
||||
// Clear launch controller reference
|
||||
if (launchController != null)
|
||||
{
|
||||
launchController.ClearActiveAirplane();
|
||||
}
|
||||
|
||||
// Clear target highlighting
|
||||
ClearAllTargetHighlights();
|
||||
|
||||
// Move to next person
|
||||
StartCoroutine(SetupNextPerson());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Game over - no more people
|
||||
/// </summary>
|
||||
private IEnumerator GameOver()
|
||||
{
|
||||
ChangeState(AirplaneGameState.GameOver);
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[AirplaneGameManager] ===== GAME OVER =====" +
|
||||
$"\n Total Turns: {_totalTurns}" +
|
||||
$"\n Success: {_successCount}" +
|
||||
$"\n Failures: {_failCount}" +
|
||||
$"\n Success Rate: {(_totalTurns > 0 ? (_successCount * 100f / _totalTurns) : 0):F1}%");
|
||||
}
|
||||
|
||||
OnGameComplete?.Invoke();
|
||||
|
||||
// Stub: Show game over UI
|
||||
yield return new WaitForSeconds(2f);
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneGameManager] Game complete");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Target Management
|
||||
|
||||
/// <summary>
|
||||
/// Highlight a specific target by name
|
||||
/// </summary>
|
||||
private void HighlightTarget(string targetName)
|
||||
{
|
||||
if (allTargets == null) return;
|
||||
|
||||
foreach (var target in allTargets)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
bool isActive = string.Equals(target.TargetName, targetName, StringComparison.OrdinalIgnoreCase);
|
||||
target.SetAsActiveTarget(isActive);
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneGameManager] Highlighted target: {targetName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all target highlights
|
||||
/// </summary>
|
||||
private void ClearAllTargetHighlights()
|
||||
{
|
||||
if (allTargets == null) return;
|
||||
|
||||
foreach (var target in allTargets)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.SetAsActiveTarget(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Query Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get current game statistics
|
||||
/// </summary>
|
||||
public (int total, int success, int fail) GetStatistics()
|
||||
{
|
||||
return (_totalTurns, _successCount, _failCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if game is active
|
||||
/// </summary>
|
||||
public bool IsGameActive()
|
||||
{
|
||||
return _currentState != AirplaneGameState.Intro && _currentState != AirplaneGameState.GameOver;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd2c6d27dee546479b16d0dfd8c3b2ee
|
||||
timeCreated: 1764851399
|
||||
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using Common.Input;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.Airplane.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Launch controller for the airplane minigame.
|
||||
/// Extends DragLaunchController with airplane-specific behavior.
|
||||
/// Spawns and launches airplanes on release.
|
||||
/// </summary>
|
||||
public class AirplaneLaunchController : DragLaunchController
|
||||
{
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when airplane is launched. Parameters: (AirplaneController airplane)
|
||||
/// </summary>
|
||||
public event Action<AirplaneController> OnAirplaneLaunched;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
|
||||
protected override SlingshotConfig GetSlingshotConfig()
|
||||
{
|
||||
return GameManager.GetSettingsObject<IAirplaneSettings>()?.SlingshotSettings;
|
||||
}
|
||||
|
||||
protected override GameObject GetProjectilePrefab()
|
||||
{
|
||||
return airplanePrefab;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector Properties
|
||||
|
||||
[Header("Airplane Setup")]
|
||||
[Tooltip("Airplane prefab to spawn")]
|
||||
[SerializeField] private GameObject airplanePrefab;
|
||||
|
||||
[Header("Visual Feedback")]
|
||||
[Tooltip("Line renderer for trajectory preview (optional)")]
|
||||
[SerializeField] private LineRenderer trajectoryLine;
|
||||
|
||||
[Tooltip("Visual indicator for launch anchor (optional)")]
|
||||
[SerializeField] private GameObject anchorVisual;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private AirplaneController _activeAirplane;
|
||||
|
||||
public AirplaneController ActiveAirplane => _activeAirplane;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Validate airplane prefab
|
||||
if (airplanePrefab == null)
|
||||
{
|
||||
Logging.Error("[AirplaneLaunchController] Airplane prefab not assigned!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verify airplane has AirplaneController
|
||||
if (airplanePrefab.GetComponent<AirplaneController>() == null)
|
||||
{
|
||||
Logging.Error("[AirplaneLaunchController] Airplane prefab missing AirplaneController component!");
|
||||
}
|
||||
}
|
||||
|
||||
// Setup trajectory line
|
||||
if (trajectoryLine != null)
|
||||
{
|
||||
trajectoryLine.enabled = false;
|
||||
}
|
||||
|
||||
// Hide anchor visual initially
|
||||
if (anchorVisual != null)
|
||||
{
|
||||
anchorVisual.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Visual Feedback
|
||||
|
||||
protected override void ShowPreview()
|
||||
{
|
||||
// Show anchor visual
|
||||
if (anchorVisual != null)
|
||||
{
|
||||
anchorVisual.SetActive(true);
|
||||
}
|
||||
|
||||
// Show trajectory line (will be updated during drag)
|
||||
if (trajectoryLine != null)
|
||||
{
|
||||
trajectoryLine.enabled = false; // Only show during drag
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneLaunchController] Preview shown");
|
||||
}
|
||||
|
||||
protected override void HidePreview()
|
||||
{
|
||||
// Hide anchor visual
|
||||
if (anchorVisual != null)
|
||||
{
|
||||
anchorVisual.SetActive(false);
|
||||
}
|
||||
|
||||
// Hide trajectory line
|
||||
if (trajectoryLine != null)
|
||||
{
|
||||
trajectoryLine.enabled = false;
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneLaunchController] Preview hidden");
|
||||
}
|
||||
|
||||
protected override void UpdateVisuals(Vector2 currentPosition, Vector2 direction, float force, float dragDistance, float mass)
|
||||
{
|
||||
// Show trajectory line during drag
|
||||
if (trajectoryLine != null && trajectoryLine.enabled == false && dragDistance > 0.1f)
|
||||
{
|
||||
trajectoryLine.enabled = true;
|
||||
}
|
||||
|
||||
// Update trajectory preview
|
||||
if (trajectoryLine != null && trajectoryLine.enabled)
|
||||
{
|
||||
UpdateTrajectoryPreview(direction, force, mass);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the trajectory preview line
|
||||
/// </summary>
|
||||
private void UpdateTrajectoryPreview(Vector2 direction, float force, float mass)
|
||||
{
|
||||
if (trajectoryLine == null) return;
|
||||
|
||||
var config = Config;
|
||||
if (config == null) return;
|
||||
|
||||
if (mass <= 0f)
|
||||
{
|
||||
if (showDebugLogs) Logging.Warning("[AirplaneLaunchController] Cannot calculate trajectory with zero mass!");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 startPos = launchAnchor.position;
|
||||
float initialSpeed = force / mass;
|
||||
Vector2 velocity = direction * initialSpeed;
|
||||
|
||||
// Get gravity from prefab's Rigidbody2D (Physics2D.gravity.magnitude * rb.gravityScale)
|
||||
float gravity = GetGravity();
|
||||
|
||||
trajectoryLine.positionCount = config.trajectoryPoints;
|
||||
|
||||
// Calculate trajectory points using config values
|
||||
for (int i = 0; i < config.trajectoryPoints; i++)
|
||||
{
|
||||
float time = i * config.trajectoryTimeStep;
|
||||
|
||||
// Calculate position at this time
|
||||
float x = startPos.x + velocity.x * time;
|
||||
float y = startPos.y + velocity.y * time - 0.5f * gravity * time * time;
|
||||
|
||||
trajectoryLine.SetPosition(i, new Vector3(x, y, 0));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Launch
|
||||
|
||||
protected override void PerformLaunch(Vector2 direction, float force)
|
||||
{
|
||||
if (airplanePrefab == null)
|
||||
{
|
||||
Logging.Error("[AirplaneLaunchController] Cannot launch - airplane prefab not assigned!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Spawn airplane at launch anchor
|
||||
GameObject airplaneObj = Instantiate(airplanePrefab, launchAnchor.position, Quaternion.identity);
|
||||
_activeAirplane = airplaneObj.GetComponent<AirplaneController>();
|
||||
|
||||
if (_activeAirplane == null)
|
||||
{
|
||||
Logging.Error("[AirplaneLaunchController] Spawned airplane missing AirplaneController!");
|
||||
Destroy(airplaneObj);
|
||||
return;
|
||||
}
|
||||
|
||||
// Launch the airplane
|
||||
_activeAirplane.Launch(direction, force);
|
||||
|
||||
// Hide trajectory preview
|
||||
if (trajectoryLine != null)
|
||||
{
|
||||
trajectoryLine.enabled = false;
|
||||
}
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[AirplaneLaunchController] Launched airplane with force {force:F2}, direction {direction}");
|
||||
}
|
||||
|
||||
// Fire event
|
||||
OnAirplaneLaunched?.Invoke(_activeAirplane);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get reference to the currently active airplane (if any)
|
||||
/// </summary>
|
||||
public AirplaneController GetActiveAirplane()
|
||||
{
|
||||
return _activeAirplane;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear reference to active airplane (called after airplane is destroyed)
|
||||
/// </summary>
|
||||
public void ClearActiveAirplane()
|
||||
{
|
||||
_activeAirplane = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a819923cb68240d494bdcf6d5ecf6b9b
|
||||
timeCreated: 1764851349
|
||||
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates whether the airplane hit the correct target.
|
||||
/// Singleton for easy access throughout the minigame.
|
||||
/// </summary>
|
||||
public class AirplaneTargetValidator : ManagedBehaviour
|
||||
{
|
||||
#region Singleton
|
||||
|
||||
private static AirplaneTargetValidator _instance;
|
||||
public static AirplaneTargetValidator Instance => _instance;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when correct target is hit. Parameters: (string targetName)
|
||||
/// </summary>
|
||||
public event Action<string> OnCorrectTargetHit;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when wrong target is hit. Parameters: (string expectedTarget, string actualTarget)
|
||||
/// </summary>
|
||||
public event Action<string, string> OnWrongTargetHit;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when no target is hit
|
||||
/// </summary>
|
||||
public event Action OnMissedAllTargets;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private string _expectedTargetName = null;
|
||||
private bool _hasValidatedCurrentShot = false;
|
||||
|
||||
public string ExpectedTargetName => _expectedTargetName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Configuration
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] private bool showDebugLogs = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Set singleton
|
||||
if (_instance != null && _instance != this)
|
||||
{
|
||||
Logging.Warning("[AirplaneTargetValidator] Multiple instances detected! Destroying duplicate.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
if (_instance == this)
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Target Setting
|
||||
|
||||
/// <summary>
|
||||
/// Set the expected target for the current shot
|
||||
/// </summary>
|
||||
public void SetExpectedTarget(string targetName)
|
||||
{
|
||||
_expectedTargetName = targetName;
|
||||
_hasValidatedCurrentShot = false;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneTargetValidator] Expected target set to: {targetName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the expected target
|
||||
/// </summary>
|
||||
public void ClearExpectedTarget()
|
||||
{
|
||||
_expectedTargetName = null;
|
||||
_hasValidatedCurrentShot = false;
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneTargetValidator] Expected target cleared");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation
|
||||
|
||||
/// <summary>
|
||||
/// Validate if the hit target matches the expected target
|
||||
/// </summary>
|
||||
public bool ValidateHit(string hitTargetName)
|
||||
{
|
||||
// Prevent multiple validations for the same shot
|
||||
if (_hasValidatedCurrentShot)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[AirplaneTargetValidator] Already validated this shot");
|
||||
return false;
|
||||
}
|
||||
|
||||
_hasValidatedCurrentShot = true;
|
||||
|
||||
if (string.IsNullOrEmpty(_expectedTargetName))
|
||||
{
|
||||
Logging.Warning("[AirplaneTargetValidator] No expected target set!");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isCorrect = string.Equals(hitTargetName, _expectedTargetName, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (isCorrect)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneTargetValidator] ✓ Correct! Hit target: {hitTargetName}");
|
||||
OnCorrectTargetHit?.Invoke(hitTargetName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneTargetValidator] ✗ Wrong! Expected: {_expectedTargetName}, Hit: {hitTargetName}");
|
||||
OnWrongTargetHit?.Invoke(_expectedTargetName, hitTargetName);
|
||||
}
|
||||
|
||||
return isCorrect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle case where airplane didn't hit any target
|
||||
/// </summary>
|
||||
public void HandleMiss()
|
||||
{
|
||||
// Prevent multiple validations for the same shot
|
||||
if (_hasValidatedCurrentShot)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_hasValidatedCurrentShot = true;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneTargetValidator] ✗ Missed! Expected target: {_expectedTargetName}");
|
||||
|
||||
OnMissedAllTargets?.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Query Methods
|
||||
|
||||
/// <summary>
|
||||
/// Check if a target name matches the expected target
|
||||
/// </summary>
|
||||
public bool IsExpectedTarget(string targetName)
|
||||
{
|
||||
return string.Equals(targetName, _expectedTargetName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if validation has been done for current shot
|
||||
/// </summary>
|
||||
public bool HasValidated => _hasValidatedCurrentShot;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cf7815b220240e090fb5cba4fc7414f
|
||||
timeCreated: 1764851309
|
||||
197
Assets/Scripts/Minigames/Airplane/Core/PersonQueue.cs
Normal file
197
Assets/Scripts/Minigames/Airplane/Core/PersonQueue.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.Airplane.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the queue of people waiting to launch airplanes.
|
||||
/// Provides methods to pop the next person and track remaining people.
|
||||
/// </summary>
|
||||
public class PersonQueue : ManagedBehaviour
|
||||
{
|
||||
#region Inspector Properties
|
||||
|
||||
[Header("Person Setup")]
|
||||
[Tooltip("List of people in the queue (order matters)")]
|
||||
[SerializeField] private List<PersonData> peopleInQueue = new List<PersonData>();
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] private bool showDebugLogs = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private int _currentTurnNumber = 1;
|
||||
|
||||
public int TotalPeople => peopleInQueue.Count;
|
||||
public int RemainingPeople => peopleInQueue.Count;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
ValidateQueue();
|
||||
}
|
||||
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[PersonQueue] Initialized with {TotalPeople} people");
|
||||
foreach (var person in peopleInQueue)
|
||||
{
|
||||
Logging.Debug($" - {person.personName} -> Target: {person.targetName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation
|
||||
|
||||
/// <summary>
|
||||
/// Validate the queue setup
|
||||
/// </summary>
|
||||
private void ValidateQueue()
|
||||
{
|
||||
if (peopleInQueue.Count == 0)
|
||||
{
|
||||
Logging.Warning("[PersonQueue] No people in queue! Add people in the inspector.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for missing data
|
||||
for (int i = 0; i < peopleInQueue.Count; i++)
|
||||
{
|
||||
var person = peopleInQueue[i];
|
||||
|
||||
if (string.IsNullOrEmpty(person.personName))
|
||||
{
|
||||
Logging.Warning($"[PersonQueue] Person at index {i} has no name!");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(person.targetName))
|
||||
{
|
||||
Logging.Warning($"[PersonQueue] Person '{person.personName}' at index {i} has no target assigned!");
|
||||
}
|
||||
|
||||
if (person.personTransform == null)
|
||||
{
|
||||
Logging.Warning($"[PersonQueue] Person '{person.personName}' at index {i} has no transform reference!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Queue Management
|
||||
|
||||
/// <summary>
|
||||
/// Check if there are more people in the queue
|
||||
/// </summary>
|
||||
public bool HasMorePeople()
|
||||
{
|
||||
return peopleInQueue.Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the next person without removing them from the queue
|
||||
/// </summary>
|
||||
public PersonData PeekNextPerson()
|
||||
{
|
||||
if (peopleInQueue.Count == 0)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[PersonQueue] Queue is empty!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return peopleInQueue[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pop the next person from the queue
|
||||
/// </summary>
|
||||
public PersonData PopNextPerson()
|
||||
{
|
||||
if (peopleInQueue.Count == 0)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug("[PersonQueue] Queue is empty!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get first person
|
||||
PersonData nextPerson = peopleInQueue[0];
|
||||
|
||||
// Assign turn number
|
||||
nextPerson.turnNumber = _currentTurnNumber;
|
||||
_currentTurnNumber++;
|
||||
|
||||
// Remove from queue
|
||||
peopleInQueue.RemoveAt(0);
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[PersonQueue] Popped person: {nextPerson.personName} (Turn {nextPerson.turnNumber}), " +
|
||||
$"Remaining: {RemainingPeople}");
|
||||
}
|
||||
|
||||
return nextPerson;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the queue (for testing or replay)
|
||||
/// </summary>
|
||||
public void ResetQueue(List<PersonData> newQueue)
|
||||
{
|
||||
peopleInQueue.Clear();
|
||||
peopleInQueue.AddRange(newQueue);
|
||||
_currentTurnNumber = 1;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[PersonQueue] Reset queue with {TotalPeople} people");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the queue
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
peopleInQueue.Clear();
|
||||
_currentTurnNumber = 1;
|
||||
|
||||
if (showDebugLogs) Logging.Debug("[PersonQueue] Queue cleared");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Query Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get count of people still in queue
|
||||
/// </summary>
|
||||
public int GetRemainingCount()
|
||||
{
|
||||
return peopleInQueue.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current turn number
|
||||
/// </summary>
|
||||
public int GetCurrentTurnNumber()
|
||||
{
|
||||
return _currentTurnNumber;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77964ec3bd5848a6b947ed4ac9b0ee3f
|
||||
timeCreated: 1764851326
|
||||
3
Assets/Scripts/Minigames/Airplane/Data.meta
Normal file
3
Assets/Scripts/Minigames/Airplane/Data.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d58653664484f58be14ab8089e22ce3
|
||||
timeCreated: 1764851234
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Minigames.Airplane.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Camera states for the airplane minigame
|
||||
/// </summary>
|
||||
public enum AirplaneCameraState
|
||||
{
|
||||
Intro, // Intro sequence camera
|
||||
NextPerson, // Camera focusing on the next person
|
||||
Aiming, // Camera for aiming the airplane
|
||||
Flight // Camera following the airplane in flight
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5b6a3623e7040be9dfeac6ee8e195cf
|
||||
timeCreated: 1764851235
|
||||
16
Assets/Scripts/Minigames/Airplane/Data/AirplaneGameState.cs
Normal file
16
Assets/Scripts/Minigames/Airplane/Data/AirplaneGameState.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Minigames.Airplane.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Game states for the airplane minigame
|
||||
/// </summary>
|
||||
public enum AirplaneGameState
|
||||
{
|
||||
Intro, // Intro sequence
|
||||
NextPerson, // Introducing the next person
|
||||
Aiming, // Player is aiming the airplane
|
||||
Flying, // Airplane is in flight
|
||||
Evaluating, // Evaluating the result of the flight
|
||||
GameOver // All people have had their turn
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59636bd1dbca4575b431820510da201f
|
||||
timeCreated: 1764851235
|
||||
52
Assets/Scripts/Minigames/Airplane/Data/PersonData.cs
Normal file
52
Assets/Scripts/Minigames/Airplane/Data/PersonData.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Data for a person participating in the airplane minigame.
|
||||
/// Contains their name, target assignment, and scene reference.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class PersonData
|
||||
{
|
||||
[Tooltip("Name of the person")]
|
||||
public string personName;
|
||||
|
||||
[Tooltip("Target name they need to hit")]
|
||||
public string targetName;
|
||||
|
||||
[Tooltip("Transform reference to the person in the scene")]
|
||||
public Transform personTransform;
|
||||
|
||||
[Tooltip("Turn number (assigned at runtime)")]
|
||||
public int turnNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating person data
|
||||
/// </summary>
|
||||
public PersonData(string name, string target, Transform transform, int turn = 0)
|
||||
{
|
||||
personName = name;
|
||||
targetName = target;
|
||||
personTransform = transform;
|
||||
turnNumber = turn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor for serialization
|
||||
/// </summary>
|
||||
public PersonData()
|
||||
{
|
||||
personName = "Unknown";
|
||||
targetName = "Unknown";
|
||||
personTransform = null;
|
||||
turnNumber = 0;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Person: {personName}, Target: {targetName}, Turn: {turnNumber}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9a03de5cfa64dadaf6c53b8f3935d3e
|
||||
timeCreated: 1764851235
|
||||
3
Assets/Scripts/Minigames/Airplane/Settings.meta
Normal file
3
Assets/Scripts/Minigames/Airplane/Settings.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81b8f6aeeaf946cea5f5338a9127ae74
|
||||
timeCreated: 1764851415
|
||||
@@ -0,0 +1,70 @@
|
||||
using AppleHills.Core.Settings;
|
||||
using Common.Input;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for the airplane minigame.
|
||||
/// Create via Assets > Create > AppleHills > Settings > Airplane
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "AirplaneSettings", menuName = "AppleHills/Settings/Airplane", order = 9)]
|
||||
public class AirplaneSettings : BaseSettings, IAirplaneSettings
|
||||
{
|
||||
[Header("Slingshot Configuration")]
|
||||
[SerializeField] private SlingshotConfig slingshotSettings = new SlingshotConfig
|
||||
{
|
||||
maxDragDistance = 5f,
|
||||
baseLaunchForce = 20f,
|
||||
minForceMultiplier = 0.1f,
|
||||
maxForceMultiplier = 1f,
|
||||
trajectoryPoints = 20,
|
||||
trajectoryTimeStep = 0.1f,
|
||||
trajectoryLockDuration = 0f, // No locking for airplane
|
||||
autoRegisterInput = true // Direct registration
|
||||
};
|
||||
|
||||
[Header("Flight Settings")]
|
||||
[Tooltip("Mass of the airplane")]
|
||||
[SerializeField] private float airplaneMass = 1f;
|
||||
|
||||
[Tooltip("Maximum flight time before timeout (seconds)")]
|
||||
[SerializeField] private float maxFlightTime = 10f;
|
||||
|
||||
[Header("Camera Settings")]
|
||||
[Tooltip("Camera follow smoothness (higher = smoother but more lag)")]
|
||||
[SerializeField] private float cameraFollowSmoothing = 5f;
|
||||
|
||||
[Tooltip("Camera zoom level during flight")]
|
||||
[SerializeField] private float flightCameraZoom = 5f;
|
||||
|
||||
[Header("Timing")]
|
||||
[Tooltip("Duration of intro sequence (seconds)")]
|
||||
[SerializeField] private float introDuration = 1f;
|
||||
|
||||
[Tooltip("Duration of person introduction (seconds)")]
|
||||
[SerializeField] private float personIntroDuration = 1f;
|
||||
|
||||
[Tooltip("Duration of result evaluation (seconds)")]
|
||||
[SerializeField] private float evaluationDuration = 1f;
|
||||
|
||||
[Header("Debug")]
|
||||
[Tooltip("Show debug logs in console")]
|
||||
[SerializeField] private bool showDebugLogs;
|
||||
|
||||
#region IAirplaneSettings Implementation
|
||||
|
||||
public SlingshotConfig SlingshotSettings => slingshotSettings;
|
||||
public float AirplaneMass => airplaneMass;
|
||||
public float MaxFlightTime => maxFlightTime;
|
||||
public float CameraFollowSmoothing => cameraFollowSmoothing;
|
||||
public float FlightCameraZoom => flightCameraZoom;
|
||||
public float IntroDuration => introDuration;
|
||||
public float PersonIntroDuration => personIntroDuration;
|
||||
public float EvaluationDuration => evaluationDuration;
|
||||
public bool ShowDebugLogs => showDebugLogs;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c277e2fec3d42e2b3b0bed1b8a33beb
|
||||
timeCreated: 1764851415
|
||||
3
Assets/Scripts/Minigames/Airplane/Targets.meta
Normal file
3
Assets/Scripts/Minigames/Airplane/Targets.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef822469ac14cedad520c7d8f01562a
|
||||
timeCreated: 1764851291
|
||||
151
Assets/Scripts/Minigames/Airplane/Targets/AirplaneTarget.cs
Normal file
151
Assets/Scripts/Minigames/Airplane/Targets/AirplaneTarget.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Targets
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a target in the airplane minigame.
|
||||
/// Detects airplane collisions and can be highlighted when active.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class AirplaneTarget : ManagedBehaviour
|
||||
{
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when this target is hit. Parameters: (AirplaneTarget target, GameObject airplane)
|
||||
/// </summary>
|
||||
public event Action<AirplaneTarget, GameObject> OnTargetHit;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector Properties
|
||||
|
||||
[Header("Target Configuration")]
|
||||
[Tooltip("Name of this target (for validation)")]
|
||||
[SerializeField] private string targetName = "Target";
|
||||
|
||||
[Header("Visual Feedback")]
|
||||
[Tooltip("Sprite renderer for visual feedback (optional)")]
|
||||
[SerializeField] private SpriteRenderer spriteRenderer;
|
||||
|
||||
[Tooltip("Color when target is active")]
|
||||
[SerializeField] private Color activeColor = Color.yellow;
|
||||
|
||||
[Tooltip("Color when target is inactive")]
|
||||
[SerializeField] private Color inactiveColor = Color.white;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] private bool showDebugLogs = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string TargetName => targetName;
|
||||
|
||||
private bool _isActive = false;
|
||||
public bool IsActive => _isActive;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private Collider2D _targetCollider;
|
||||
private Color _originalColor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Cache components
|
||||
_targetCollider = GetComponent<Collider2D>();
|
||||
|
||||
// Configure collider as trigger
|
||||
if (_targetCollider != null)
|
||||
{
|
||||
_targetCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
// Cache sprite renderer if not assigned
|
||||
if (spriteRenderer == null)
|
||||
{
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
// Store original color
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
_originalColor = spriteRenderer.color;
|
||||
}
|
||||
}
|
||||
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
// Start as inactive
|
||||
SetAsActiveTarget(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Active State
|
||||
|
||||
/// <summary>
|
||||
/// Set this target as active (highlighted) or inactive
|
||||
/// </summary>
|
||||
public void SetAsActiveTarget(bool active)
|
||||
{
|
||||
_isActive = active;
|
||||
|
||||
// Update visual feedback
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
spriteRenderer.color = active ? activeColor : inactiveColor;
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneTarget] {targetName} set to {(active ? "active" : "inactive")}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Collision Detection
|
||||
|
||||
/// <summary>
|
||||
/// Detect when airplane enters trigger
|
||||
/// </summary>
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
// Check if it's an airplane
|
||||
var airplane = other.GetComponent<Core.AirplaneController>();
|
||||
if (airplane != null)
|
||||
{
|
||||
if (showDebugLogs) Logging.Debug($"[AirplaneTarget] {targetName} hit by airplane: {other.gameObject.name}");
|
||||
|
||||
OnTargetHit?.Invoke(this, other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Reset target to original state
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
SetAsActiveTarget(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53e3dae13bb14c109a038bb5a84bd941
|
||||
timeCreated: 1764851291
|
||||
Reference in New Issue
Block a user