Compare commits
5 Commits
ec64e6f4f7
...
fort_fight
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a463e099b4 | ||
|
|
9b71b00441 | ||
|
|
88049ac97c | ||
|
|
0b8d2a279f | ||
|
|
d5ab69d944 |
@@ -15,7 +15,7 @@ MonoBehaviour:
|
||||
m_DefaultGroup: 6f3207429a65b3e4b83935ac19791077
|
||||
m_currentHash:
|
||||
serializedVersion: 2
|
||||
Hash: 00000000000000000000000000000000
|
||||
Hash: ab5e2545873f5b7934dc716832e70d83
|
||||
m_OptimizeCatalogSize: 0
|
||||
m_BuildRemoteCatalog: 0
|
||||
m_CatalogRequestsTimeout: 0
|
||||
@@ -108,7 +108,6 @@ MonoBehaviour:
|
||||
m_LabelNames:
|
||||
- default
|
||||
- BlokkemonCard
|
||||
- StatueDecorations
|
||||
m_SchemaTemplates: []
|
||||
m_GroupTemplateObjects:
|
||||
- {fileID: 11400000, guid: ea0a5135f5495eb4693a23d94617fe92, type: 2}
|
||||
|
||||
@@ -106,8 +106,8 @@ Rigidbody2D:
|
||||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDamping: 1
|
||||
m_AngularDamping: 1
|
||||
m_LinearDamping: 0
|
||||
m_AngularDamping: 0.05
|
||||
m_GravityScale: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
|
||||
@@ -2712,7 +2712,7 @@ GameObject:
|
||||
- component: {fileID: 841922114}
|
||||
- component: {fileID: 841922117}
|
||||
- component: {fileID: 841922116}
|
||||
- component: {fileID: 841922118}
|
||||
- component: {fileID: 841922115}
|
||||
m_Layer: 0
|
||||
m_Name: SlingShot
|
||||
m_TagString: Untagged
|
||||
@@ -2737,6 +2737,21 @@ Transform:
|
||||
- {fileID: 1448546925}
|
||||
m_Father: {fileID: 1009687014}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &841922115
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 841922113}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b1e26667c6d4415f8dc51e4a58ba9479, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Minigames.FortFight.Core.TrajectoryPreview
|
||||
simulationSteps: 50
|
||||
lineColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
||||
lineWidth: 0.1
|
||||
--- !u!120 &841922116
|
||||
LineRenderer:
|
||||
serializedVersion: 2
|
||||
@@ -2859,28 +2874,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: fc81b72132764f09a0ba180c90b432cf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Minigames.FortFight.Core.SlingshotController
|
||||
maxDragDistanceOverride: 0
|
||||
maxForceOverride: 0
|
||||
launchAnchor: {fileID: 1668202570}
|
||||
trajectoryPreview: {fileID: 841922118}
|
||||
showDebugLogs: 1
|
||||
--- !u!114 &841922118
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 841922113}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b86a4cd82d4a47de9d1e4d97ffd01f5e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Common.Visual.TrajectoryPreview
|
||||
trajectoryPoints: 50
|
||||
timeStep: 0.1
|
||||
groundLevel: -10
|
||||
lineColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
||||
lineWidth: 0.1
|
||||
maxDragDistance: 5
|
||||
projectileSpawnPoint: {fileID: 1668202570}
|
||||
trajectoryPreview: {fileID: 0}
|
||||
--- !u!1 &846792101
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -4367,7 +4363,7 @@ GameObject:
|
||||
- component: {fileID: 1460473367}
|
||||
- component: {fileID: 1460473370}
|
||||
- component: {fileID: 1460473369}
|
||||
- component: {fileID: 1460473371}
|
||||
- component: {fileID: 1460473368}
|
||||
m_Layer: 0
|
||||
m_Name: SlingShot
|
||||
m_TagString: Untagged
|
||||
@@ -4392,6 +4388,21 @@ Transform:
|
||||
- {fileID: 56461670}
|
||||
m_Father: {fileID: 799036564}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1460473368
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1460473366}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b1e26667c6d4415f8dc51e4a58ba9479, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Minigames.FortFight.Core.TrajectoryPreview
|
||||
simulationSteps: 30
|
||||
lineColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
||||
lineWidth: 0.1
|
||||
--- !u!120 &1460473369
|
||||
LineRenderer:
|
||||
serializedVersion: 2
|
||||
@@ -4514,28 +4525,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: fc81b72132764f09a0ba180c90b432cf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Minigames.FortFight.Core.SlingshotController
|
||||
maxDragDistanceOverride: 0
|
||||
maxForceOverride: 0
|
||||
launchAnchor: {fileID: 497509525}
|
||||
trajectoryPreview: {fileID: 1460473371}
|
||||
showDebugLogs: 1
|
||||
--- !u!114 &1460473371
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1460473366}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b86a4cd82d4a47de9d1e4d97ffd01f5e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Common.Visual.TrajectoryPreview
|
||||
trajectoryPoints: 50
|
||||
timeStep: 0.1
|
||||
groundLevel: -10
|
||||
lineColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
||||
lineWidth: 0.1
|
||||
maxDragDistance: 5
|
||||
projectileSpawnPoint: {fileID: 497509525}
|
||||
trajectoryPreview: {fileID: 0}
|
||||
--- !u!1 &1543340062
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -119,6 +119,85 @@ NavMeshSettings:
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &580848252
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 580848255}
|
||||
- component: {fileID: 580848254}
|
||||
- component: {fileID: 580848253}
|
||||
m_Layer: 0
|
||||
m_Name: EventSystem
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &580848253
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 580848252}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_MoveRepeatDelay: 0.5
|
||||
m_MoveRepeatRate: 0.1
|
||||
m_XRTrackingOrigin: {fileID: 0}
|
||||
m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_PointAction: {fileID: -1654692200621890270, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_MoveAction: {fileID: -8784545083839296357, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_SubmitAction: {fileID: 392368643174621059, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_CancelAction: {fileID: 7727032971491509709, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_LeftClickAction: {fileID: 3001919216989983466, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_MiddleClickAction: {fileID: -2185481485913320682, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_RightClickAction: {fileID: -4090225696740746782, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_ScrollWheelAction: {fileID: 6240969308177333660, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_TrackedDevicePositionAction: {fileID: 6564999863303420839, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_TrackedDeviceOrientationAction: {fileID: 7970375526676320489, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
|
||||
m_DeselectOnBackgroundClick: 1
|
||||
m_PointerBehavior: 0
|
||||
m_CursorLockBehavior: 0
|
||||
m_ScrollDeltaPerTick: 6
|
||||
--- !u!114 &580848254
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 580848252}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_FirstSelected: {fileID: 0}
|
||||
m_sendNavigationEvents: 1
|
||||
m_DragThreshold: 10
|
||||
--- !u!4 &580848255
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 580848252}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1810521056
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -283,7 +362,7 @@ Transform:
|
||||
m_GameObject: {fileID: 1810521056}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalPosition: {x: -34.3, y: -36.3, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -299,6 +378,8 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 2103114178}
|
||||
- component: {fileID: 2103114177}
|
||||
- component: {fileID: 2103114176}
|
||||
- component: {fileID: 2103114175}
|
||||
m_Layer: 0
|
||||
m_Name: CinemachineCamera
|
||||
m_TagString: Untagged
|
||||
@@ -306,6 +387,45 @@ GameObject:
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &2103114175
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2103114174}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f453f694addf4275988fac205bc91968, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
BoundingShape2D: {fileID: 0}
|
||||
Damping: 3
|
||||
SlowingDistance: 20
|
||||
OversizeWindow:
|
||||
Enabled: 0
|
||||
MaxWindowSize: 0
|
||||
Padding: 0
|
||||
m_LegacyMaxWindowSize: -2
|
||||
--- !u!114 &2103114176
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2103114174}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b617507da6d07e749b7efdb34e1173e1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
TrackerSettings:
|
||||
BindingMode: 4
|
||||
PositionDamping: {x: 2, y: 0.5, z: 1}
|
||||
AngularDampingMode: 0
|
||||
RotationDamping: {x: 1, y: 1, z: 1}
|
||||
QuaternionDamping: 1
|
||||
FollowOffset: {x: 0, y: 0, z: -10}
|
||||
--- !u!114 &2103114177
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -358,7 +478,7 @@ Transform:
|
||||
m_GameObject: {fileID: 2103114174}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalPosition: {x: -34.3, y: -36.3, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -369,4 +489,5 @@ SceneRoots:
|
||||
m_ObjectHideFlags: 0
|
||||
m_Roots:
|
||||
- {fileID: 1810521061}
|
||||
- {fileID: 580848255}
|
||||
- {fileID: 2103114178}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70833f6496d94acab58cfe981c757d2d
|
||||
timeCreated: 1764851204
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44c4b5c8fcd54d1887fb05ca65a9bb20
|
||||
timeCreated: 1764851223
|
||||
@@ -1,169 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Common.Camera
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic state-based camera controller using Cinemachine.
|
||||
/// Manages camera transitions by setting priorities on virtual cameras.
|
||||
/// Type parameter TState must be an enum representing camera states.
|
||||
/// </summary>
|
||||
public abstract class CameraStateManager<TState> : ManagedBehaviour where TState : Enum
|
||||
{
|
||||
#region Configuration
|
||||
|
||||
[Header("Camera Priority Settings")]
|
||||
[Tooltip("Priority for inactive cameras")]
|
||||
[SerializeField] protected int inactivePriority = 10;
|
||||
|
||||
[Tooltip("Priority for the active camera")]
|
||||
[SerializeField] protected int activePriority = 20;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] protected bool showDebugLogs = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private Dictionary<TState, CinemachineCamera> _cameraMap = new Dictionary<TState, CinemachineCamera>();
|
||||
private TState _currentState;
|
||||
private bool _isInitialized = false;
|
||||
|
||||
public TState CurrentState => _currentState;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when camera state changes. Parameters: (TState oldState, TState newState)
|
||||
/// </summary>
|
||||
public event Action<TState, TState> OnStateChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
|
||||
/// <summary>
|
||||
/// Register a camera for a specific state.
|
||||
/// Call this in subclass OnManagedAwake to set up the camera map.
|
||||
/// </summary>
|
||||
protected void RegisterCamera(TState state, CinemachineCamera pCamera)
|
||||
{
|
||||
if (pCamera == null)
|
||||
{
|
||||
Logging.Warning($"[{GetType().Name}] Attempted to register null camera for state {state}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cameraMap.ContainsKey(state))
|
||||
{
|
||||
Logging.Warning($"[{GetType().Name}] Camera for state {state} already registered, overwriting");
|
||||
}
|
||||
|
||||
_cameraMap[state] = pCamera;
|
||||
|
||||
// Set all cameras to inactive priority initially
|
||||
pCamera.Priority.Value = inactivePriority;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Registered camera '{pCamera.gameObject.name}' for state {state}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalize initialization after all cameras are registered.
|
||||
/// Call this at the end of subclass OnManagedAwake.
|
||||
/// </summary>
|
||||
protected void FinalizeInitialization()
|
||||
{
|
||||
_isInitialized = true;
|
||||
|
||||
if (_cameraMap.Count == 0)
|
||||
{
|
||||
Logging.Warning($"[{GetType().Name}] No cameras registered!");
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Initialized with {_cameraMap.Count} cameras");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region State Management
|
||||
|
||||
/// <summary>
|
||||
/// Switch to a specific camera state
|
||||
/// </summary>
|
||||
public virtual void SwitchToState(TState newState)
|
||||
{
|
||||
if (!_isInitialized)
|
||||
{
|
||||
Logging.Error($"[{GetType().Name}] Cannot switch state - not initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_cameraMap.ContainsKey(newState))
|
||||
{
|
||||
Logging.Error($"[{GetType().Name}] No camera registered for state {newState}!");
|
||||
return;
|
||||
}
|
||||
|
||||
TState oldState = _currentState;
|
||||
_currentState = newState;
|
||||
|
||||
// Set all cameras to inactive priority
|
||||
foreach (var kvp in _cameraMap)
|
||||
{
|
||||
kvp.Value.Priority.Value = inactivePriority;
|
||||
}
|
||||
|
||||
// Set target camera to active priority
|
||||
_cameraMap[newState].Priority.Value = activePriority;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Switched from {oldState} to {newState} (camera: {_cameraMap[newState].gameObject.name})");
|
||||
|
||||
OnStateChanged?.Invoke(oldState, newState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the camera for a specific state
|
||||
/// </summary>
|
||||
public CinemachineCamera GetCamera(TState state)
|
||||
{
|
||||
if (_cameraMap.TryGetValue(state, out CinemachineCamera pCamera))
|
||||
{
|
||||
return pCamera;
|
||||
}
|
||||
|
||||
Logging.Warning($"[{GetType().Name}] No camera found for state {state}");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a camera is registered for a state
|
||||
/// </summary>
|
||||
public bool HasCamera(TState state)
|
||||
{
|
||||
return _cameraMap.ContainsKey(state);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation
|
||||
|
||||
/// <summary>
|
||||
/// Validate that all required states have cameras registered.
|
||||
/// Subclasses can override to add custom validation.
|
||||
/// </summary>
|
||||
protected virtual void ValidateCameras()
|
||||
{
|
||||
// Subclasses should implement specific validation
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4fc438e61b94c529f7d1e8fe9fb70fa
|
||||
timeCreated: 1764851223
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35838202f1ac4fa4b606b0582fa4e439
|
||||
timeCreated: 1764851204
|
||||
@@ -1,400 +0,0 @@
|
||||
using System;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Input;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Common.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Cached launch parameters calculated during drag.
|
||||
/// Avoids recalculating force/direction multiple times.
|
||||
/// </summary>
|
||||
public struct LaunchParameters
|
||||
{
|
||||
public Vector2 Direction;
|
||||
public float Force;
|
||||
public float DragDistance;
|
||||
public float DragRatio;
|
||||
public float Mass;
|
||||
|
||||
public bool IsValid => Force > 0f && DragDistance > 0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for drag-to-launch mechanics (Angry Birds style).
|
||||
/// Provides core drag logic, force calculation, and input handling.
|
||||
/// Uses SlingshotConfig for all settings - fully configuration-driven.
|
||||
/// Subclasses implement visual feedback and specific launch behavior.
|
||||
/// </summary>
|
||||
public abstract class DragLaunchController : ManagedBehaviour, ITouchInputConsumer
|
||||
{
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Fired when drag starts. Parameters: (Vector2 startPosition)
|
||||
/// </summary>
|
||||
public event Action<Vector2> OnDragStart;
|
||||
|
||||
/// <summary>
|
||||
/// Fired during drag update. Parameters: (Vector2 currentPosition, Vector2 direction, float force)
|
||||
/// </summary>
|
||||
public event Action<Vector2, Vector2, float> OnDragUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when drag ends. Parameters: (Vector2 endPosition, Vector2 direction, float force)
|
||||
/// </summary>
|
||||
public event Action<Vector2, Vector2, float> OnDragEnd;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when launch occurs. Parameters: (Vector2 direction, float force)
|
||||
/// </summary>
|
||||
public event Action<Vector2, float> OnLaunch;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
|
||||
private SlingshotConfig _config;
|
||||
|
||||
protected SlingshotConfig Config
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_config == null)
|
||||
{
|
||||
_config = GetSlingshotConfig();
|
||||
}
|
||||
return _config;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subclasses implement to return their slingshot configuration
|
||||
/// from their specific settings object
|
||||
/// </summary>
|
||||
protected abstract SlingshotConfig GetSlingshotConfig();
|
||||
|
||||
/// <summary>
|
||||
/// Subclasses implement to return the projectile prefab that will be launched.
|
||||
/// Used for reading Rigidbody2D properties (mass, gravityScale) for trajectory calculations.
|
||||
/// </summary>
|
||||
protected abstract GameObject GetProjectilePrefab();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector Properties
|
||||
|
||||
[Header("Launch Settings Overrides (leave 0 to use config)")]
|
||||
[Tooltip("Override max drag distance (0 = use config)")]
|
||||
[SerializeField] protected float maxDragDistanceOverride = 0f;
|
||||
|
||||
[Tooltip("Override max force (0 = use config)")]
|
||||
[SerializeField] protected float maxForceOverride = 0f;
|
||||
|
||||
[Header("References")]
|
||||
[Tooltip("Launch anchor point (spawn/slingshot position)")]
|
||||
[SerializeField] protected Transform launchAnchor;
|
||||
|
||||
[Tooltip("Trajectory preview component (auto-found if not assigned)")]
|
||||
[SerializeField] protected Common.Visual.TrajectoryPreview trajectoryPreview;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] protected bool showDebugLogs;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Computed Properties
|
||||
|
||||
protected float MaxDragDistance => maxDragDistanceOverride > 0 ? maxDragDistanceOverride : Config?.maxDragDistance ?? 5f;
|
||||
protected float MaxForce => maxForceOverride > 0 ? maxForceOverride : Config?.baseLaunchForce ?? 20f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private bool _isDragging;
|
||||
private Vector2 _dragStartPosition;
|
||||
private bool _isEnabled = false;
|
||||
private bool _isRegisteredForInput = false;
|
||||
|
||||
// Cached launch parameters - calculated once during drag, used for both preview and launch
|
||||
private LaunchParameters _cachedLaunchParams;
|
||||
|
||||
public bool IsDragging => _isDragging;
|
||||
public bool IsEnabled => _isEnabled;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
if (launchAnchor == null)
|
||||
{
|
||||
launchAnchor = transform;
|
||||
}
|
||||
|
||||
// Auto-find trajectory preview if not assigned
|
||||
if (trajectoryPreview == null)
|
||||
{
|
||||
trajectoryPreview = GetComponent<Common.Visual.TrajectoryPreview>();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enable/Disable
|
||||
|
||||
/// <summary>
|
||||
/// Enable the launch controller and register with InputManager
|
||||
/// </summary>
|
||||
public virtual void Enable()
|
||||
{
|
||||
_isEnabled = true;
|
||||
|
||||
// Register with InputManager as override consumer
|
||||
if (InputManager.Instance != null && !_isRegisteredForInput)
|
||||
{
|
||||
InputManager.Instance.RegisterOverrideConsumer(this);
|
||||
_isRegisteredForInput = true;
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Registered with InputManager");
|
||||
}
|
||||
|
||||
// Show preview visuals
|
||||
ShowPreview();
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Enabled");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable the launch controller and unregister from InputManager
|
||||
/// </summary>
|
||||
public virtual void Disable()
|
||||
{
|
||||
_isEnabled = false;
|
||||
_isDragging = false;
|
||||
|
||||
// Unregister from InputManager
|
||||
if (InputManager.Instance != null && _isRegisteredForInput)
|
||||
{
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
_isRegisteredForInput = false;
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Unregistered from InputManager");
|
||||
}
|
||||
|
||||
// Hide preview visuals
|
||||
HidePreview();
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Disabled");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITouchInputConsumer Implementation
|
||||
|
||||
public void OnTap(Vector2 worldPosition)
|
||||
{
|
||||
// Drag-to-launch uses hold/drag, not tap
|
||||
}
|
||||
|
||||
public void OnHoldStart(Vector2 worldPosition)
|
||||
{
|
||||
if (!_isEnabled) return;
|
||||
StartDrag(worldPosition);
|
||||
}
|
||||
|
||||
public void OnHoldMove(Vector2 worldPosition)
|
||||
{
|
||||
if (!_isEnabled || !_isDragging) return;
|
||||
UpdateDrag(worldPosition);
|
||||
}
|
||||
|
||||
public void OnHoldEnd(Vector2 worldPosition)
|
||||
{
|
||||
if (!_isEnabled || !_isDragging) return;
|
||||
EndDrag(worldPosition);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Drag Handling
|
||||
|
||||
/// <summary>
|
||||
/// Start drag operation
|
||||
/// </summary>
|
||||
protected virtual void StartDrag(Vector2 worldPosition)
|
||||
{
|
||||
_isDragging = true;
|
||||
// Use launch anchor as the reference point (like Angry Birds)
|
||||
_dragStartPosition = launchAnchor.position;
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[{GetType().Name}] Started drag at {worldPosition}, anchor at {_dragStartPosition}");
|
||||
|
||||
OnDragStart?.Invoke(worldPosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update drag operation
|
||||
/// </summary>
|
||||
protected virtual void UpdateDrag(Vector2 currentWorldPosition)
|
||||
{
|
||||
// Calculate launch parameters once and cache
|
||||
_cachedLaunchParams = CalculateLaunchParameters(currentWorldPosition);
|
||||
|
||||
// Warn if mass is zero or invalid
|
||||
if (_cachedLaunchParams.Mass <= 0f && showDebugLogs)
|
||||
{
|
||||
Logging.Warning($"[{GetType().Name}] Projectile mass is {_cachedLaunchParams.Mass}! Trajectory calculation will be inaccurate. Override GetProjectileMass().");
|
||||
}
|
||||
|
||||
// Update visuals with cached parameters
|
||||
UpdateVisuals(currentWorldPosition, _cachedLaunchParams);
|
||||
|
||||
OnDragUpdate?.Invoke(currentWorldPosition, _cachedLaunchParams.Direction, _cachedLaunchParams.Force);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End drag operation and potentially launch
|
||||
/// </summary>
|
||||
protected virtual void EndDrag(Vector2 currentWorldPosition)
|
||||
{
|
||||
_isDragging = false;
|
||||
|
||||
// Hide preview
|
||||
HidePreview();
|
||||
|
||||
// Recalculate final parameters (position may have changed since last UpdateDrag)
|
||||
_cachedLaunchParams = CalculateLaunchParameters(currentWorldPosition);
|
||||
|
||||
OnDragEnd?.Invoke(currentWorldPosition, _cachedLaunchParams.Direction, _cachedLaunchParams.Force);
|
||||
|
||||
if (showDebugLogs)
|
||||
Logging.Debug($"[{GetType().Name}] Launching with force {_cachedLaunchParams.Force:F2}");
|
||||
PerformLaunch(_cachedLaunchParams.Direction, _cachedLaunchParams.Force);
|
||||
OnLaunch?.Invoke(_cachedLaunchParams.Direction, _cachedLaunchParams.Force);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate launch parameters from current drag position.
|
||||
/// Caches results to avoid recalculating force multiple times.
|
||||
/// </summary>
|
||||
private LaunchParameters CalculateLaunchParameters(Vector2 currentWorldPosition)
|
||||
{
|
||||
// Calculate drag vector from anchor to current drag position
|
||||
// Pull back (away from anchor) = launch forward (toward anchor direction)
|
||||
Vector2 dragVector = _dragStartPosition - currentWorldPosition;
|
||||
|
||||
// Calculate distance and ratio
|
||||
float dragDistance = dragVector.magnitude;
|
||||
float dragRatio = Mathf.Clamp01(dragDistance / MaxDragDistance);
|
||||
|
||||
// Calculate force using config
|
||||
float force = Config?.CalculateForce(dragDistance, dragRatio) ?? (dragRatio * MaxForce);
|
||||
|
||||
// Normalize direction
|
||||
Vector2 direction = dragDistance > 0.01f ? dragVector.normalized : Vector2.zero;
|
||||
|
||||
// Get mass from projectile
|
||||
float mass = GetProjectileMass();
|
||||
|
||||
return new LaunchParameters
|
||||
{
|
||||
Direction = direction,
|
||||
Force = force,
|
||||
DragDistance = dragDistance,
|
||||
DragRatio = dragRatio,
|
||||
Mass = mass
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Abstract Methods - Subclass Implementation
|
||||
|
||||
/// <summary>
|
||||
/// Perform the actual launch (spawn projectile/airplane, apply force, etc.)
|
||||
/// </summary>
|
||||
protected abstract void PerformLaunch(Vector2 direction, float force);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Virtual Methods - Visual Feedback (Override if needed)
|
||||
|
||||
/// <summary>
|
||||
/// Update visual feedback during drag (trajectory preview, rubber band, etc.)
|
||||
/// Default: Updates trajectory preview using prefab's physics properties.
|
||||
/// Override for custom visuals.
|
||||
/// </summary>
|
||||
/// <param name="currentPosition">Current drag position</param>
|
||||
/// <param name="launchParams">Cached launch parameters (direction, force, etc.)</param>
|
||||
protected virtual void UpdateVisuals(Vector2 currentPosition, LaunchParameters launchParams)
|
||||
{
|
||||
if (trajectoryPreview != null && launchParams.DragDistance > 0.1f)
|
||||
{
|
||||
GameObject prefab = GetProjectilePrefab();
|
||||
if (prefab == null) return;
|
||||
|
||||
// Get gravity from prefab's Rigidbody2D gravityScale
|
||||
var rb = prefab.GetComponent<Rigidbody2D>();
|
||||
float gravityScale = rb != null ? rb.gravityScale : 1f;
|
||||
float gravity = Physics2D.gravity.magnitude * gravityScale;
|
||||
|
||||
// Use mass from settings (already in launchParams)
|
||||
trajectoryPreview.UpdateTrajectory(launchAnchor.position, launchParams.Direction,
|
||||
launchParams.Force, launchParams.Mass, gravity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show preview visuals when controller is enabled.
|
||||
/// Default: Shows trajectory preview.
|
||||
/// Override for custom visuals.
|
||||
/// </summary>
|
||||
protected virtual void ShowPreview()
|
||||
{
|
||||
trajectoryPreview?.Show();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide preview visuals when controller is disabled.
|
||||
/// Default: Hides trajectory preview.
|
||||
/// Override for custom visuals.
|
||||
/// </summary>
|
||||
protected virtual void HidePreview()
|
||||
{
|
||||
trajectoryPreview?.Hide();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Abstract Methods - Physics Configuration
|
||||
|
||||
/// <summary>
|
||||
/// Get projectile mass for trajectory calculation.
|
||||
/// MUST read from settings - the same source that Initialize() uses.
|
||||
/// Subclasses implement to return the actual runtime mass.
|
||||
/// </summary>
|
||||
protected abstract float GetProjectileMass();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cleanup
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
// Ensure we unregister from InputManager
|
||||
if (_isRegisteredForInput && InputManager.Instance != null)
|
||||
{
|
||||
InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44e042d1338149f6bb8adf6129e1c6c2
|
||||
timeCreated: 1764851204
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Common.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration for slingshot launch mechanics.
|
||||
/// Can be embedded in any minigame settings that use drag-to-launch.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SlingshotConfig
|
||||
{
|
||||
[Header("Drag & Force Settings")]
|
||||
[Tooltip("Distance to reach max force")]
|
||||
public float maxDragDistance = 5f;
|
||||
|
||||
[Tooltip("Base force value")]
|
||||
public float baseLaunchForce = 20f;
|
||||
|
||||
[Tooltip("Minimum threshold (0-1)")]
|
||||
[Range(0f, 1f)]
|
||||
public float minForceMultiplier = 0.1f;
|
||||
|
||||
[Tooltip("Maximum cap (0-2, usually 1)")]
|
||||
[Range(0f, 2f)]
|
||||
public float maxForceMultiplier = 1f;
|
||||
|
||||
[Header("Trajectory Settings")]
|
||||
[Tooltip("Number of preview points")]
|
||||
public int trajectoryPoints = 50;
|
||||
|
||||
[Tooltip("Time between points")]
|
||||
public float trajectoryTimeStep = 0.1f;
|
||||
|
||||
[Tooltip("Show trajectory after launch (seconds, 0 = no lock)")]
|
||||
public float trajectoryLockDuration = 2f;
|
||||
|
||||
[Header("Input")]
|
||||
[Tooltip("Auto-register with InputManager on Enable()")]
|
||||
public bool autoRegisterInput = true;
|
||||
|
||||
/// <summary>
|
||||
/// Calculate force from drag parameters using configured multipliers
|
||||
/// </summary>
|
||||
public float CalculateForce(float dragDistance, float dragRatio)
|
||||
{
|
||||
return dragRatio * maxForceMultiplier * baseLaunchForce;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate minimum force threshold
|
||||
/// </summary>
|
||||
public float GetMinForce()
|
||||
{
|
||||
return baseLaunchForce * minForceMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be4f5d5fd7084425a7bf28a1fadf125e
|
||||
timeCreated: 1764854225
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8315fa927ac4db4a53e985fac95c178
|
||||
timeCreated: 1764857542
|
||||
@@ -1,237 +0,0 @@
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Common.Visual
|
||||
{
|
||||
/// <summary>
|
||||
/// Common trajectory preview component for slingshot-style mechanics.
|
||||
/// Displays a line showing the predicted arc of a launched projectile.
|
||||
/// Supports multiple API overloads for different use cases.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(LineRenderer))]
|
||||
public class TrajectoryPreview : MonoBehaviour
|
||||
{
|
||||
[Header("Trajectory Settings")]
|
||||
[Tooltip("Number of points in trajectory line")]
|
||||
[SerializeField] private int trajectoryPoints = 50;
|
||||
|
||||
[Tooltip("Time step between trajectory points (seconds)")]
|
||||
[SerializeField] private float timeStep = 0.1f;
|
||||
|
||||
[Tooltip("Ground level Y position (trajectory stops here)")]
|
||||
[SerializeField] private float groundLevel = -10f;
|
||||
|
||||
[Header("Visual")]
|
||||
[Tooltip("Color of trajectory line")]
|
||||
[SerializeField] private Color lineColor = Color.yellow;
|
||||
|
||||
[Tooltip("Width of trajectory line")]
|
||||
[SerializeField] private float lineWidth = 0.1f;
|
||||
|
||||
private LineRenderer _lineRenderer;
|
||||
private bool _isLocked;
|
||||
private float _lockTimer;
|
||||
private float _lockDuration;
|
||||
|
||||
#region Unity Lifecycle
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_lineRenderer = GetComponent<LineRenderer>();
|
||||
|
||||
if (_lineRenderer != null)
|
||||
{
|
||||
_lineRenderer.startWidth = lineWidth;
|
||||
_lineRenderer.endWidth = lineWidth;
|
||||
_lineRenderer.startColor = lineColor;
|
||||
_lineRenderer.endColor = lineColor;
|
||||
_lineRenderer.positionCount = trajectoryPoints;
|
||||
_lineRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isLocked)
|
||||
{
|
||||
_lockTimer += Time.deltaTime;
|
||||
if (_lockTimer >= _lockDuration)
|
||||
{
|
||||
_isLocked = false;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public API - Visibility
|
||||
|
||||
/// <summary>
|
||||
/// Show the trajectory preview line
|
||||
/// </summary>
|
||||
public void Show()
|
||||
{
|
||||
if (_lineRenderer != null)
|
||||
{
|
||||
_lineRenderer.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide the trajectory preview line (unless locked)
|
||||
/// </summary>
|
||||
public void Hide()
|
||||
{
|
||||
if (_isLocked) return;
|
||||
|
||||
if (_lineRenderer != null)
|
||||
{
|
||||
_lineRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lock the trajectory display for a duration (keeps showing after launch)
|
||||
/// </summary>
|
||||
public void LockTrajectory(float duration)
|
||||
{
|
||||
_isLocked = true;
|
||||
_lockTimer = 0f;
|
||||
_lockDuration = duration;
|
||||
|
||||
if (_lineRenderer != null)
|
||||
{
|
||||
_lineRenderer.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public API - Update Trajectory (Multiple Overloads)
|
||||
|
||||
/// <summary>
|
||||
/// Update trajectory from velocity and gravity directly.
|
||||
/// Most explicit - caller calculates everything.
|
||||
/// </summary>
|
||||
public void UpdateTrajectory(Vector2 startPos, Vector2 velocity, float gravity)
|
||||
{
|
||||
if (_lineRenderer == null) return;
|
||||
|
||||
CalculateAndSetTrajectory(startPos, velocity, gravity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update trajectory from launch force and mass.
|
||||
/// Calculates velocity as: v = (direction * force) / mass
|
||||
/// </summary>
|
||||
public void UpdateTrajectory(Vector2 startPos, Vector2 direction, float force, float mass, float gravity)
|
||||
{
|
||||
if (_lineRenderer == null) return;
|
||||
|
||||
if (mass <= 0f)
|
||||
{
|
||||
Logging.Warning("[TrajectoryPreview] Cannot calculate trajectory with zero or negative mass!");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 velocity = (direction * force) / mass;
|
||||
CalculateAndSetTrajectory(startPos, velocity, gravity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update trajectory from prefab's Rigidbody2D properties.
|
||||
/// Reads mass and gravityScale from prefab, calculates gravity automatically.
|
||||
/// </summary>
|
||||
public void UpdateTrajectory(Vector2 startPos, Vector2 direction, float force, GameObject prefab)
|
||||
{
|
||||
if (_lineRenderer == null || prefab == null) return;
|
||||
|
||||
var rb = prefab.GetComponent<Rigidbody2D>();
|
||||
if (rb == null)
|
||||
{
|
||||
Logging.Warning($"[TrajectoryPreview] Prefab '{prefab.name}' has no Rigidbody2D!");
|
||||
return;
|
||||
}
|
||||
|
||||
float mass = rb.mass;
|
||||
float gravity = Physics2D.gravity.magnitude * rb.gravityScale;
|
||||
|
||||
if (mass <= 0f)
|
||||
{
|
||||
Logging.Warning($"[TrajectoryPreview] Prefab '{prefab.name}' has zero mass!");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 velocity = (direction * force) / mass;
|
||||
CalculateAndSetTrajectory(startPos, velocity, gravity);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Calculation
|
||||
|
||||
/// <summary>
|
||||
/// Calculate and set trajectory points using kinematic formula.
|
||||
/// Uses: y = y0 + v*t - 0.5*g*t^2
|
||||
/// </summary>
|
||||
private void CalculateAndSetTrajectory(Vector2 startPos, Vector2 velocity, float gravity)
|
||||
{
|
||||
Vector3[] points = new Vector3[trajectoryPoints];
|
||||
|
||||
for (int i = 0; i < trajectoryPoints; i++)
|
||||
{
|
||||
float time = i * timeStep;
|
||||
|
||||
// Kinematic equations
|
||||
float x = startPos.x + velocity.x * time;
|
||||
float y = startPos.y + velocity.y * time - 0.5f * gravity * time * time;
|
||||
|
||||
points[i] = new Vector3(x, y, 0);
|
||||
|
||||
// Stop at ground level
|
||||
if (y <= groundLevel)
|
||||
{
|
||||
// Fill remaining points at ground level
|
||||
for (int j = i; j < trajectoryPoints; j++)
|
||||
{
|
||||
float tGround = j * timeStep;
|
||||
float xGround = startPos.x + velocity.x * tGround;
|
||||
points[j] = new Vector3(xGround, groundLevel, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_lineRenderer.positionCount = trajectoryPoints;
|
||||
_lineRenderer.SetPositions(points);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Configuration
|
||||
|
||||
/// <summary>
|
||||
/// Set the number of trajectory points (for performance tuning)
|
||||
/// </summary>
|
||||
public void SetTrajectoryPoints(int points)
|
||||
{
|
||||
trajectoryPoints = Mathf.Max(5, points);
|
||||
if (_lineRenderer != null)
|
||||
{
|
||||
_lineRenderer.positionCount = trajectoryPoints;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the time step between points
|
||||
/// </summary>
|
||||
public void SetTimeStep(float step)
|
||||
{
|
||||
timeStep = Mathf.Max(0.01f, step);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b86a4cd82d4a47de9d1e4d97ffd01f5e
|
||||
timeCreated: 1764857542
|
||||
@@ -5,7 +5,6 @@ using AppleHills.Core.Settings;
|
||||
using Core.Lifecycle;
|
||||
using Core.Settings;
|
||||
using Input;
|
||||
using Minigames.Airplane.Settings;
|
||||
using Minigames.FortFight.Core;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -176,7 +175,6 @@ namespace Core
|
||||
var birdPooperSettings = SettingsProvider.Instance.LoadSettingsSynchronous<BirdPooperSettings>();
|
||||
var statueDressupSettings = SettingsProvider.Instance.LoadSettingsSynchronous<StatueDressupSettings>();
|
||||
var fortFightSettings = SettingsProvider.Instance.LoadSettingsSynchronous<FortFightSettings>();
|
||||
var airplaneSettings = SettingsProvider.Instance.LoadSettingsSynchronous<AirplaneSettings>();
|
||||
|
||||
|
||||
// Register settings with service locator
|
||||
@@ -259,21 +257,11 @@ namespace Core
|
||||
{
|
||||
Debug.LogError("Failed to load FortFightSettings");
|
||||
}
|
||||
|
||||
if (airplaneSettings != null)
|
||||
{
|
||||
ServiceLocator.Register<IAirplaneSettings>(airplaneSettings);
|
||||
Logging.Debug("AirplaneSettings registered successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Failed to load AirplaneSettings");
|
||||
}
|
||||
|
||||
// Log success
|
||||
_settingsLoaded = playerSettings != null && interactionSettings != null && minigameSettings != null
|
||||
&& cardSystemSettings != null && birdPooperSettings != null && statueDressupSettings != null
|
||||
&& fortFightSettings != null && sortingGameSettings != null && airplaneSettings != null;
|
||||
&& fortFightSettings != null;
|
||||
if (_settingsLoaded)
|
||||
{
|
||||
Logging.Debug("All settings loaded and registered with ServiceLocator");
|
||||
|
||||
@@ -219,9 +219,6 @@ namespace AppleHills.Core.Settings
|
||||
/// </summary>
|
||||
public interface IFortFightSettings
|
||||
{
|
||||
// Slingshot Configuration
|
||||
Common.Input.SlingshotConfig SlingshotSettings { get; }
|
||||
|
||||
// Block configurations
|
||||
System.Collections.Generic.List<Minigames.FortFight.Settings.BlockMaterialConfig> MaterialConfigs { get; }
|
||||
System.Collections.Generic.List<Minigames.FortFight.Settings.BlockSizeConfig> SizeConfigs { get; }
|
||||
@@ -251,6 +248,12 @@ namespace AppleHills.Core.Settings
|
||||
int FortBlockLayer { get; } // Layer index for fort blocks
|
||||
int ProjectileLayer { get; } // Layer index for projectiles
|
||||
|
||||
// Slingshot Settings
|
||||
float BaseLaunchForce { get; } // Base launch force multiplier
|
||||
float MinForceMultiplier { get; } // Minimum force required to launch (0-1)
|
||||
float MaxForceMultiplier { get; } // Maximum force cap (0-2, usually 1)
|
||||
float TrajectoryLockDuration { get; } // How long to show trajectory after launch
|
||||
|
||||
// Projectile Abilities
|
||||
float VacuumSlideSpeed { get; } // Constant velocity for vacuum sliding (m/s)
|
||||
int VacuumDestroyBlockCount { get; } // Blocks to destroy while sliding
|
||||
@@ -276,29 +279,4 @@ namespace AppleHills.Core.Settings
|
||||
Minigames.FortFight.Settings.BlockMaterialConfig GetMaterialConfig(Minigames.FortFight.Data.BlockMaterial material);
|
||||
Minigames.FortFight.Settings.BlockSizeConfig GetSizeConfig(Minigames.FortFight.Data.BlockSize size);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for Airplane minigame settings
|
||||
/// </summary>
|
||||
public interface IAirplaneSettings
|
||||
{
|
||||
// Slingshot Configuration
|
||||
Common.Input.SlingshotConfig SlingshotSettings { get; }
|
||||
|
||||
// Flight Settings
|
||||
float AirplaneMass { get; }
|
||||
float MaxFlightTime { get; }
|
||||
|
||||
// Camera Settings
|
||||
float CameraFollowSmoothing { get; }
|
||||
float FlightCameraZoom { get; }
|
||||
|
||||
// Timing
|
||||
float IntroDuration { get; }
|
||||
float PersonIntroDuration { get; }
|
||||
float EvaluationDuration { get; }
|
||||
|
||||
// Debug
|
||||
bool ShowDebugLogs { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Input
|
||||
UI,
|
||||
GameAndUI,
|
||||
InputDisabled
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles input events and dispatches them to the appropriate ITouchInputConsumer.
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cdcfc21e5ec473dafc45f1ae16624b2
|
||||
timeCreated: 1764851234
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48e6932cbd9645bfac8add678e705033
|
||||
timeCreated: 1764851249
|
||||
@@ -1,160 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34b856742e12475793b85a0a3019d67b
|
||||
timeCreated: 1764851249
|
||||
@@ -1,293 +0,0 @@
|
||||
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;
|
||||
|
||||
[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;
|
||||
|
||||
// Runtime values loaded from settings
|
||||
private float mass;
|
||||
private float maxFlightTime;
|
||||
|
||||
public bool IsFlying => isFlying;
|
||||
public Vector2 CurrentVelocity => currentVelocity;
|
||||
public string LastHitTarget => lastHitTarget;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Load settings
|
||||
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IAirplaneSettings>();
|
||||
if (settings != null)
|
||||
{
|
||||
mass = settings.AirplaneMass;
|
||||
maxFlightTime = settings.MaxFlightTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Warning("[AirplaneController] AirplaneSettings not found, using defaults!");
|
||||
mass = 1f;
|
||||
maxFlightTime = 10f;
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cdaac23e969495d8c0deeaf236c259e
|
||||
timeCreated: 1764851277
|
||||
@@ -1,553 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd2c6d27dee546479b16d0dfd8c3b2ee
|
||||
timeCreated: 1764851399
|
||||
@@ -1,164 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
protected override float GetProjectileMass()
|
||||
{
|
||||
var settings = GameManager.GetSettingsObject<IAirplaneSettings>();
|
||||
if (settings == null)
|
||||
{
|
||||
if (showDebugLogs)
|
||||
Logging.Warning("[AirplaneLaunchController] AirplaneSettings not found!");
|
||||
return 1f; // Default fallback
|
||||
}
|
||||
|
||||
// Read from AirplaneSettings - same mass that AirplaneController uses
|
||||
return settings.AirplaneMass;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector Properties
|
||||
|
||||
[Header("Airplane Setup")]
|
||||
[Tooltip("Airplane prefab to spawn")]
|
||||
[SerializeField] private GameObject airplanePrefab;
|
||||
|
||||
// Note: Trajectory preview is handled by base DragLaunchController class
|
||||
// It will auto-find TrajectoryPreview component on this GameObject
|
||||
|
||||
#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!");
|
||||
}
|
||||
}
|
||||
|
||||
// Base class handles trajectory preview setup
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Visual Feedback
|
||||
|
||||
// Base class handles trajectory preview via TrajectoryPreview component
|
||||
// No custom visual feedback needed for airplane - using default implementation
|
||||
|
||||
#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);
|
||||
|
||||
// Trajectory preview is automatically hidden by base class
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a819923cb68240d494bdcf6d5ecf6b9b
|
||||
timeCreated: 1764851349
|
||||
@@ -1,186 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cf7815b220240e090fb5cba4fc7414f
|
||||
timeCreated: 1764851309
|
||||
@@ -1,197 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77964ec3bd5848a6b947ed4ac9b0ee3f
|
||||
timeCreated: 1764851326
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d58653664484f58be14ab8089e22ce3
|
||||
timeCreated: 1764851234
|
||||
@@ -1,14 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5b6a3623e7040be9dfeac6ee8e195cf
|
||||
timeCreated: 1764851235
|
||||
@@ -1,16 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59636bd1dbca4575b431820510da201f
|
||||
timeCreated: 1764851235
|
||||
@@ -1,52 +0,0 @@
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9a03de5cfa64dadaf6c53b8f3935d3e
|
||||
timeCreated: 1764851235
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81b8f6aeeaf946cea5f5338a9127ae74
|
||||
timeCreated: 1764851415
|
||||
@@ -1,70 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c277e2fec3d42e2b3b0bed1b8a33beb
|
||||
timeCreated: 1764851415
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef822469ac14cedad520c7d8f01562a
|
||||
timeCreated: 1764851291
|
||||
@@ -1,151 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53e3dae13bb14c109a038bb5a84bd941
|
||||
timeCreated: 1764851291
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AppleHills.Core.Settings;
|
||||
using Common.Input;
|
||||
using Minigames.FortFight.Data;
|
||||
using Minigames.FortFight.Settings;
|
||||
using UnityEngine;
|
||||
@@ -15,19 +14,6 @@ namespace Minigames.FortFight.Core
|
||||
[CreateAssetMenu(fileName = "FortFightSettings", menuName = "AppleHills/Settings/Fort Fight", order = 8)]
|
||||
public class FortFightSettings : BaseSettings, IFortFightSettings
|
||||
{
|
||||
[Header("Slingshot Configuration")]
|
||||
[SerializeField] private SlingshotConfig slingshotSettings = new SlingshotConfig
|
||||
{
|
||||
maxDragDistance = 5f,
|
||||
baseLaunchForce = 20f,
|
||||
minForceMultiplier = 0.1f,
|
||||
maxForceMultiplier = 1f,
|
||||
trajectoryPoints = 50,
|
||||
trajectoryTimeStep = 0.1f,
|
||||
trajectoryLockDuration = 2f,
|
||||
autoRegisterInput = false // TurnManager handles registration
|
||||
};
|
||||
|
||||
[Header("Block Material Configurations")]
|
||||
[Tooltip("HP and mass configurations for each material type")]
|
||||
[SerializeField] private List<BlockMaterialConfig> materialConfigs = new List<BlockMaterialConfig>
|
||||
@@ -126,6 +112,21 @@ namespace Minigames.FortFight.Core
|
||||
[Tooltip("Downward velocity when dropping (m/s)")]
|
||||
[SerializeField] private float ceilingFanDropSpeed = 20f;
|
||||
|
||||
[Header("Slingshot Settings")]
|
||||
[Tooltip("Base launch force multiplier - higher values = projectiles fly farther")]
|
||||
[SerializeField] private float baseLaunchForce = 20f;
|
||||
|
||||
[Tooltip("Minimum force multiplier (0-1, e.g. 0.1 = 10% of max force required to launch)")]
|
||||
[Range(0f, 1f)]
|
||||
[SerializeField] private float minForceMultiplier = 0.1f;
|
||||
|
||||
[Tooltip("Maximum force multiplier (0-1, e.g. 1.0 = 100% at max drag distance)")]
|
||||
[Range(0f, 2f)]
|
||||
[SerializeField] private float maxForceMultiplier = 1f;
|
||||
|
||||
[Tooltip("How long to keep trajectory visible after launching (seconds)")]
|
||||
[SerializeField] private float trajectoryLockDuration = 2f;
|
||||
|
||||
[Header("Physics Layers")]
|
||||
[Tooltip("Layer for fort blocks - projectiles will collide with these (Default: Layer 8 'FortBlock')")]
|
||||
[AppleHills.Core.Settings.Layer]
|
||||
@@ -141,8 +142,6 @@ namespace Minigames.FortFight.Core
|
||||
|
||||
#region IFortFightSettings Implementation
|
||||
|
||||
public SlingshotConfig SlingshotSettings => slingshotSettings;
|
||||
|
||||
public List<BlockMaterialConfig> MaterialConfigs => materialConfigs;
|
||||
public List<BlockSizeConfig> SizeConfigs => sizeConfigs;
|
||||
|
||||
@@ -165,6 +164,11 @@ namespace Minigames.FortFight.Core
|
||||
|
||||
public Color DamageColorTint => damageColorTint;
|
||||
|
||||
public float BaseLaunchForce => baseLaunchForce;
|
||||
public float MinForceMultiplier => minForceMultiplier;
|
||||
public float MaxForceMultiplier => maxForceMultiplier;
|
||||
public float TrajectoryLockDuration => trajectoryLockDuration;
|
||||
|
||||
public float VacuumSlideSpeed => vacuumSlideSpeed;
|
||||
public int VacuumDestroyBlockCount => vacuumDestroyBlockCount;
|
||||
public float VacuumBlockDamage => vacuumBlockDamage;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using Common.Input;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.FortFight.Data;
|
||||
using Minigames.FortFight.Projectiles;
|
||||
using UnityEngine;
|
||||
@@ -9,14 +9,24 @@ using UnityEngine;
|
||||
namespace Minigames.FortFight.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls slingshot aiming and projectile launching for FortFight.
|
||||
/// Extends DragLaunchController with FortFight-specific ammo management and trajectory preview.
|
||||
/// Controls slingshot aiming and projectile launching.
|
||||
/// Angry Birds-style drag-to-aim mechanic with trajectory preview.
|
||||
/// Implements ITouchInputConsumer for InputManager integration.
|
||||
/// </summary>
|
||||
public class SlingshotController : DragLaunchController
|
||||
public class SlingshotController : ManagedBehaviour, ITouchInputConsumer
|
||||
{
|
||||
#region Inspector Properties
|
||||
|
||||
// Note: trajectoryPreview is inherited from DragLaunchController base class
|
||||
[Header("Launch Settings")]
|
||||
[Tooltip("Drag distance to reach max force")]
|
||||
[SerializeField] private float maxDragDistance = 5f;
|
||||
|
||||
[Tooltip("Spawn point for projectiles")]
|
||||
[SerializeField] private Transform projectileSpawnPoint;
|
||||
|
||||
[Header("References")]
|
||||
[Tooltip("Trajectory preview component")]
|
||||
[SerializeField] private TrajectoryPreview trajectoryPreview;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -48,15 +58,8 @@ namespace Minigames.FortFight.Core
|
||||
}
|
||||
}
|
||||
|
||||
protected override SlingshotConfig GetSlingshotConfig()
|
||||
{
|
||||
return CachedSettings?.SlingshotSettings;
|
||||
}
|
||||
|
||||
protected override GameObject GetProjectilePrefab()
|
||||
{
|
||||
return _currentAmmo?.prefab;
|
||||
}
|
||||
private float MaxForce => CachedSettings?.BaseLaunchForce ?? 20f;
|
||||
private bool ShowDebugLogs => CachedDevSettings?.SlingshotShowDebugLogs ?? false;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -71,10 +74,13 @@ namespace Minigames.FortFight.Core
|
||||
|
||||
#region State
|
||||
|
||||
private bool _isDragging;
|
||||
private Vector2 _dragStartPosition;
|
||||
private ProjectileConfig _currentAmmo;
|
||||
private ProjectileBase _activeProjectile;
|
||||
|
||||
public ProjectileBase ActiveProjectile => _activeProjectile;
|
||||
public bool IsDragging => _isDragging;
|
||||
public bool IsEnabled { get; private set; } = true;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -84,45 +90,156 @@ namespace Minigames.FortFight.Core
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Base class handles launchAnchor and trajectoryPreview
|
||||
if (projectileSpawnPoint == null)
|
||||
{
|
||||
projectileSpawnPoint = transform;
|
||||
}
|
||||
|
||||
// Set debug logging from developer settings
|
||||
showDebugLogs = CachedDevSettings?.SlingshotShowDebugLogs ?? false;
|
||||
if (trajectoryPreview == null)
|
||||
{
|
||||
trajectoryPreview = GetComponent<TrajectoryPreview>();
|
||||
}
|
||||
}
|
||||
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
// Hide trajectory by default
|
||||
if (trajectoryPreview != null)
|
||||
{
|
||||
trajectoryPreview.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override Methods
|
||||
#region ITouchInputConsumer Implementation
|
||||
|
||||
protected override void StartDrag(Vector2 worldPosition)
|
||||
public void OnTap(Vector2 worldPosition)
|
||||
{
|
||||
// Slingshot uses hold/drag, not tap
|
||||
}
|
||||
|
||||
public void OnHoldStart(Vector2 worldPosition)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
StartDrag(worldPosition);
|
||||
}
|
||||
|
||||
public void OnHoldMove(Vector2 worldPosition)
|
||||
{
|
||||
if (!IsEnabled || !_isDragging) return;
|
||||
UpdateDrag(worldPosition);
|
||||
}
|
||||
|
||||
public void OnHoldEnd(Vector2 worldPosition)
|
||||
{
|
||||
if (!IsEnabled || !_isDragging) return;
|
||||
EndDrag(worldPosition);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Drag Handling
|
||||
|
||||
private void StartDrag(Vector2 worldPosition)
|
||||
{
|
||||
// Check ammo before starting drag
|
||||
if (_currentAmmo == null)
|
||||
{
|
||||
if (showDebugLogs) Logging.Warning("[SlingshotController] No ammo selected!");
|
||||
if (ShowDebugLogs) Logging.Warning("[SlingshotController] No ammo selected!");
|
||||
return;
|
||||
}
|
||||
|
||||
base.StartDrag(worldPosition);
|
||||
}
|
||||
|
||||
protected override void PerformLaunch(Vector2 direction, float force)
|
||||
{
|
||||
LaunchProjectile(direction, force);
|
||||
}
|
||||
|
||||
protected override float GetProjectileMass()
|
||||
{
|
||||
if (_currentAmmo == null)
|
||||
_isDragging = true;
|
||||
// Use the projectile spawn point as the anchor, not the touch position
|
||||
// This makes it work like Angry Birds - pull back from slingshot to launch forward
|
||||
_dragStartPosition = projectileSpawnPoint.position;
|
||||
|
||||
// Show trajectory preview
|
||||
if (trajectoryPreview != null)
|
||||
{
|
||||
if (showDebugLogs)
|
||||
Logging.Warning("[SlingshotController] No ammo selected, cannot get mass!");
|
||||
return 1f; // Default fallback
|
||||
trajectoryPreview.Show();
|
||||
}
|
||||
|
||||
// Read from ProjectileConfig settings - same source as ProjectileBase.Initialize()
|
||||
return _currentAmmo.mass;
|
||||
if (ShowDebugLogs) Logging.Debug($"[SlingshotController] Started drag at {worldPosition}, anchor at spawn point {_dragStartPosition}");
|
||||
}
|
||||
|
||||
private void UpdateDrag(Vector2 currentWorldPosition)
|
||||
{
|
||||
// Calculate drag vector from spawn point to current drag position
|
||||
// Pull back (away from spawn) = launch forward (toward spawn direction)
|
||||
Vector2 dragVector = _dragStartPosition - currentWorldPosition;
|
||||
|
||||
// Calculate force and direction
|
||||
float dragDistance = dragVector.magnitude;
|
||||
float dragRatio = Mathf.Clamp01(dragDistance / maxDragDistance);
|
||||
|
||||
// Apply configurable max force multiplier
|
||||
float maxMultiplier = CachedSettings?.MaxForceMultiplier ?? 1f;
|
||||
float forceMultiplier = dragRatio * maxMultiplier;
|
||||
float force = forceMultiplier * MaxForce;
|
||||
|
||||
Vector2 direction = dragVector.normalized;
|
||||
|
||||
// Update trajectory preview with projectile mass
|
||||
if (trajectoryPreview != null && _currentAmmo != null)
|
||||
{
|
||||
Vector2 worldStartPos = projectileSpawnPoint.position;
|
||||
float mass = _currentAmmo.GetMass();
|
||||
|
||||
// Debug: Log trajectory calculation (uncomment for debugging)
|
||||
// if (showDebugLogs && Time.frameCount % 30 == 0) // Log every 30 frames to avoid spam
|
||||
// {
|
||||
// Logging.Debug($"[Slingshot] Preview - Force: {force:F2}, Mass: {mass:F2}, Velocity: {force/mass:F2}, Dir: {direction}");
|
||||
// }
|
||||
|
||||
trajectoryPreview.UpdateTrajectory(worldStartPos, direction, force, mass);
|
||||
}
|
||||
}
|
||||
|
||||
private void EndDrag(Vector2 currentWorldPosition)
|
||||
{
|
||||
_isDragging = false;
|
||||
|
||||
// Hide trajectory
|
||||
if (trajectoryPreview != null)
|
||||
{
|
||||
trajectoryPreview.Hide();
|
||||
}
|
||||
|
||||
// Calculate final launch parameters from spawn point to final drag position
|
||||
Vector2 dragVector = _dragStartPosition - currentWorldPosition;
|
||||
float dragDistance = dragVector.magnitude;
|
||||
float dragRatio = Mathf.Clamp01(dragDistance / maxDragDistance);
|
||||
|
||||
// Apply configurable max force multiplier
|
||||
float maxMultiplier = CachedSettings?.MaxForceMultiplier ?? 1f;
|
||||
float forceMultiplier = dragRatio * maxMultiplier;
|
||||
float force = forceMultiplier * MaxForce;
|
||||
|
||||
Vector2 direction = dragVector.normalized;
|
||||
|
||||
// Check against configurable minimum force threshold
|
||||
float minMultiplier = CachedSettings?.MinForceMultiplier ?? 0.1f;
|
||||
float minForce = minMultiplier * MaxForce;
|
||||
|
||||
// Launch projectile if force exceeds minimum
|
||||
if (force >= minForce)
|
||||
{
|
||||
if (ShowDebugLogs && _currentAmmo != null)
|
||||
{
|
||||
float mass = _currentAmmo.GetMass();
|
||||
float velocity = force / mass;
|
||||
Logging.Debug($"[Slingshot] Launch - Force: {force:F2}, Mass: {mass:F2}, Velocity: {velocity:F2}, Dir: {direction}");
|
||||
}
|
||||
|
||||
LaunchProjectile(direction, force);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ShowDebugLogs) Logging.Debug($"[SlingshotController] Drag too short - force {force:F2} < min {minForce:F2}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -135,7 +252,7 @@ namespace Minigames.FortFight.Core
|
||||
public void SetAmmo(ProjectileConfig ammoConfig)
|
||||
{
|
||||
_currentAmmo = ammoConfig;
|
||||
if (showDebugLogs) Logging.Debug($"[SlingshotController] Ammo set to: {ammoConfig?.displayName ?? "null"}");
|
||||
if (ShowDebugLogs) Logging.Debug($"[SlingshotController] Ammo set to: {ammoConfig?.displayName ?? "null"}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -149,8 +266,8 @@ namespace Minigames.FortFight.Core
|
||||
return;
|
||||
}
|
||||
|
||||
// Spawn projectile at launch anchor
|
||||
GameObject projectileObj = Instantiate(_currentAmmo.prefab, launchAnchor.position, Quaternion.identity);
|
||||
// Spawn projectile
|
||||
GameObject projectileObj = Instantiate(_currentAmmo.prefab, projectileSpawnPoint.position, Quaternion.identity);
|
||||
_activeProjectile = projectileObj.GetComponent<ProjectileBase>();
|
||||
|
||||
if (_activeProjectile == null)
|
||||
@@ -169,11 +286,11 @@ namespace Minigames.FortFight.Core
|
||||
// Lock trajectory to show the shot path
|
||||
if (trajectoryPreview != null)
|
||||
{
|
||||
float lockDuration = Config?.trajectoryLockDuration ?? 2f;
|
||||
float lockDuration = CachedSettings?.TrajectoryLockDuration ?? 2f;
|
||||
trajectoryPreview.LockTrajectory(lockDuration);
|
||||
}
|
||||
|
||||
if (showDebugLogs) Logging.Debug($"[SlingshotController] Launched {_currentAmmo?.displayName ?? "projectile"} with force {force}");
|
||||
if (ShowDebugLogs) Logging.Debug($"[SlingshotController] Launched {_currentAmmo?.displayName ?? "projectile"} with force {force}");
|
||||
|
||||
// Fire event
|
||||
OnProjectileLaunched?.Invoke(_activeProjectile);
|
||||
@@ -207,7 +324,7 @@ namespace Minigames.FortFight.Core
|
||||
float speed = velocity.magnitude;
|
||||
float force = mass * speed;
|
||||
|
||||
if (showDebugLogs)
|
||||
if (ShowDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[Slingshot] LaunchWithVelocity - Velocity: {velocity}, Mass: {mass:F2}, Force: {force:F2}");
|
||||
}
|
||||
@@ -224,7 +341,34 @@ namespace Minigames.FortFight.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enable/Disable
|
||||
|
||||
// Note: Enable/Disable methods now handled by base DragLaunchController class
|
||||
/// <summary>
|
||||
/// Enable slingshot (allow aiming/launching)
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
IsEnabled = true;
|
||||
if (ShowDebugLogs) Logging.Debug("[SlingshotController] Enabled");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable slingshot (prevent aiming/launching)
|
||||
/// </summary>
|
||||
public void Disable()
|
||||
{
|
||||
IsEnabled = false;
|
||||
_isDragging = false;
|
||||
|
||||
if (trajectoryPreview != null)
|
||||
{
|
||||
trajectoryPreview.Hide();
|
||||
}
|
||||
|
||||
if (ShowDebugLogs) Logging.Debug("[SlingshotController] Disabled");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
153
Assets/Scripts/Minigames/FortFight/Core/TrajectoryPreview.cs
Normal file
153
Assets/Scripts/Minigames/FortFight/Core/TrajectoryPreview.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.FortFight.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays trajectory prediction line for projectile launches.
|
||||
/// Shows dotted line preview of projectile arc.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(LineRenderer))]
|
||||
public class TrajectoryPreview : MonoBehaviour
|
||||
{
|
||||
[Header("Trajectory Settings")]
|
||||
[Tooltip("Number of points to simulate (physics steps)")]
|
||||
[SerializeField] private int simulationSteps = 50;
|
||||
|
||||
[Header("Visual")]
|
||||
[Tooltip("Color of trajectory line")]
|
||||
[SerializeField] private Color lineColor = Color.yellow;
|
||||
|
||||
[Tooltip("Width of trajectory line")]
|
||||
[SerializeField] private float lineWidth = 0.1f;
|
||||
|
||||
private LineRenderer lineRenderer;
|
||||
private bool isLocked = false;
|
||||
private float lockTimer = 0f;
|
||||
private float lockDuration = 0f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
lineRenderer = GetComponent<LineRenderer>();
|
||||
|
||||
// Configure line renderer
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.startWidth = lineWidth;
|
||||
lineRenderer.endWidth = lineWidth;
|
||||
lineRenderer.startColor = lineColor;
|
||||
lineRenderer.endColor = lineColor;
|
||||
lineRenderer.positionCount = simulationSteps;
|
||||
lineRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isLocked)
|
||||
{
|
||||
lockTimer += Time.deltaTime;
|
||||
if (lockTimer >= lockDuration)
|
||||
{
|
||||
isLocked = false;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the trajectory preview
|
||||
/// </summary>
|
||||
public void Show()
|
||||
{
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide the trajectory preview (unless locked)
|
||||
/// </summary>
|
||||
public void Hide()
|
||||
{
|
||||
// Don't hide if trajectory is locked
|
||||
if (isLocked)
|
||||
return;
|
||||
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lock the current trajectory display for a duration
|
||||
/// </summary>
|
||||
public void LockTrajectory(float duration)
|
||||
{
|
||||
isLocked = true;
|
||||
lockTimer = 0f;
|
||||
lockDuration = duration;
|
||||
|
||||
// Ensure line is visible
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the trajectory preview with new parameters.
|
||||
/// Uses Physics.fixedDeltaTime for accurate simulation matching Unity's physics.
|
||||
/// </summary>
|
||||
/// <param name="startPosition">Starting position of trajectory</param>
|
||||
/// <param name="direction">Launch direction (normalized)</param>
|
||||
/// <param name="force">Launch force (impulse)</param>
|
||||
/// <param name="mass">Projectile mass</param>
|
||||
public void UpdateTrajectory(Vector2 startPosition, Vector2 direction, float force, float mass = 1f)
|
||||
{
|
||||
if (lineRenderer == null) return;
|
||||
|
||||
// Calculate initial velocity: impulse force F gives velocity v = F/m
|
||||
Vector2 startVelocity = (direction * force) / mass;
|
||||
|
||||
// Get gravity with projectile gravity scale from settings
|
||||
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
|
||||
float gravityScale = settings?.ProjectileGravityScale ?? 1f;
|
||||
Vector2 gravity = new Vector2(Physics2D.gravity.x, Physics2D.gravity.y) * gravityScale;
|
||||
|
||||
// Simulate trajectory using Unity's physics time step
|
||||
Vector3[] points = new Vector3[simulationSteps];
|
||||
Vector2 pos = startPosition;
|
||||
Vector2 vel = startVelocity;
|
||||
|
||||
for (int i = 0; i < simulationSteps; i++)
|
||||
{
|
||||
// Set current position
|
||||
points[i] = new Vector3(pos.x, pos.y, 0);
|
||||
|
||||
// Update velocity (gravity applied over fixedDeltaTime)
|
||||
vel = vel + gravity * Time.fixedDeltaTime;
|
||||
|
||||
// Update position (velocity applied over fixedDeltaTime)
|
||||
pos = pos + vel * Time.fixedDeltaTime;
|
||||
|
||||
// Optional: Stop if hits ground (y < threshold)
|
||||
if (pos.y < -10f)
|
||||
{
|
||||
// Fill remaining points at ground level
|
||||
for (int j = i + 1; j < simulationSteps; j++)
|
||||
{
|
||||
points[j] = new Vector3(pos.x, -10f, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lineRenderer.positionCount = simulationSteps;
|
||||
lineRenderer.SetPositions(points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1e26667c6d4415f8dc51e4a58ba9479
|
||||
timeCreated: 1764682615
|
||||
@@ -12,15 +12,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: eaaa527529c5438f80d27ff95c7c7930, type: 3}
|
||||
m_Name: FortFightSettings
|
||||
m_EditorClassIdentifier: AppleHillsScripts::Minigames.FortFight.Core.FortFightSettings
|
||||
slingshotSettings:
|
||||
maxDragDistance: 10
|
||||
baseLaunchForce: 125
|
||||
minForceMultiplier: 0.1
|
||||
maxForceMultiplier: 1
|
||||
trajectoryPoints: 50
|
||||
trajectoryTimeStep: 0.1
|
||||
trajectoryLockDuration: 2
|
||||
autoRegisterInput: 0
|
||||
materialConfigs:
|
||||
- material: 0
|
||||
baseHp: 20
|
||||
@@ -117,6 +108,10 @@ MonoBehaviour:
|
||||
ceilingFanActivationDelay: 1
|
||||
ceilingFanDropDelay: 0.2
|
||||
ceilingFanDropSpeed: 20
|
||||
baseLaunchForce: 150
|
||||
minForceMultiplier: 0.1
|
||||
maxForceMultiplier: 1
|
||||
trajectoryLockDuration: 2
|
||||
fortBlockLayer: 16
|
||||
projectileLayer: 15
|
||||
damageColorTint: {r: 1, g: 0, b: 0, a: 1}
|
||||
|
||||
@@ -1,350 +0,0 @@
|
||||
# ✅ Common Trajectory Preview Implementation Complete
|
||||
|
||||
## Summary
|
||||
|
||||
Created a **single common `TrajectoryPreview` component** that both FortFight and Airplane minigames now use. The base `DragLaunchController` class holds the trajectory preview reference and handles all visual feedback automatically.
|
||||
|
||||
---
|
||||
|
||||
## What Was Accomplished
|
||||
|
||||
### 1. Created Common TrajectoryPreview Component ✅
|
||||
|
||||
**File:** `Assets/Scripts/Common/Visual/TrajectoryPreview.cs`
|
||||
|
||||
**Features:**
|
||||
- Single, reusable component for all slingshot mechanics
|
||||
- Multiple API overloads for different use cases
|
||||
- LineRenderer-based visualization
|
||||
- Trajectory locking support (show path after launch)
|
||||
- Ground detection
|
||||
- Configurable appearance (color, width, points, timeStep)
|
||||
|
||||
**API Overloads:**
|
||||
```csharp
|
||||
// 1. Most explicit - pass everything
|
||||
UpdateTrajectory(Vector2 startPos, Vector2 velocity, float gravity)
|
||||
|
||||
// 2. From launch parameters
|
||||
UpdateTrajectory(Vector2 startPos, Vector2 direction, float force, float mass, float gravity)
|
||||
|
||||
// 3. From prefab Rigidbody2D (RECOMMENDED - auto-reads physics)
|
||||
UpdateTrajectory(Vector2 startPos, Vector2 direction, float force, GameObject prefab)
|
||||
```
|
||||
|
||||
### 2. Updated DragLaunchController Base Class ✅
|
||||
|
||||
**Added:**
|
||||
- `protected TrajectoryPreview trajectoryPreview` field
|
||||
- Auto-finds TrajectoryPreview component if not assigned
|
||||
- Default implementations of ShowPreview(), HidePreview(), UpdateVisuals()
|
||||
- Base class handles ALL trajectory logic automatically
|
||||
|
||||
**How It Works:**
|
||||
```csharp
|
||||
// Base class in UpdateDrag():
|
||||
UpdateVisuals(currentPosition, direction, force, dragDistance, mass);
|
||||
|
||||
// Default UpdateVisuals implementation:
|
||||
protected virtual void UpdateVisuals(...)
|
||||
{
|
||||
if (trajectoryPreview != null && dragDistance > 0.1f)
|
||||
{
|
||||
GameObject prefab = GetProjectilePrefab();
|
||||
trajectoryPreview.UpdateTrajectory(launchAnchor.position, direction, force, prefab);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Simplified FortFight SlingshotController ✅
|
||||
|
||||
**Removed:**
|
||||
- `private TrajectoryPreview trajectoryPreview` field (now in base)
|
||||
- `ShowPreview()` override (base handles it)
|
||||
- `HidePreview()` override (base handles it)
|
||||
- `UpdateVisuals()` override (base handles it)
|
||||
- `OnManagedStart()` method (base handles trajectory init)
|
||||
|
||||
**Code Reduction:** ~50 lines removed
|
||||
|
||||
**Still Has:**
|
||||
- Ammo system
|
||||
- AI methods
|
||||
- Trajectory locking (calls `trajectoryPreview.LockTrajectory()` after launch)
|
||||
|
||||
### 4. Simplified Airplane LaunchController ✅
|
||||
|
||||
**Removed:**
|
||||
- `private LineRenderer trajectoryLine` field
|
||||
- `private GameObject anchorVisual` field
|
||||
- Entire `Visual Feedback` region (~100 lines)
|
||||
- `UpdateTrajectoryPreview()` private method (~30 lines)
|
||||
- `ShowPreview()` override
|
||||
- `HidePreview()` override
|
||||
- `UpdateVisuals()` override
|
||||
|
||||
**Code Reduction:** ~130 lines removed
|
||||
|
||||
**Now Uses:** Base class default implementations exclusively
|
||||
|
||||
---
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
TrajectoryPreview (Common.Visual)
|
||||
├── LineRenderer component
|
||||
├── Multiple UpdateTrajectory() overloads
|
||||
├── Show() / Hide() / LockTrajectory()
|
||||
└── Kinematic trajectory calculation
|
||||
|
||||
DragLaunchController (Common.Input)
|
||||
├── protected TrajectoryPreview trajectoryPreview
|
||||
├── Auto-finds component
|
||||
├── Default implementations:
|
||||
│ ├── ShowPreview() → trajectoryPreview?.Show()
|
||||
│ ├── HidePreview() → trajectoryPreview?.Hide()
|
||||
│ └── UpdateVisuals() → trajectoryPreview.UpdateTrajectory(...)
|
||||
└── Children can override if needed
|
||||
|
||||
SlingshotController (FortFight)
|
||||
├── Uses inherited trajectoryPreview
|
||||
├── No trajectory code needed
|
||||
└── Just implements PerformLaunch()
|
||||
|
||||
AirplaneLaunchController (Airplane)
|
||||
├── Uses inherited trajectoryPreview
|
||||
├── No trajectory code needed
|
||||
└── Just implements PerformLaunch()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files Modified
|
||||
|
||||
1. ✅ **Created:** `Common/Visual/TrajectoryPreview.cs` - Common component (~220 lines)
|
||||
2. ✅ **Modified:** `Common/Input/DragLaunchController.cs` - Added trajectory field and default implementations
|
||||
3. ✅ **Modified:** `Minigames/FortFight/Core/SlingshotController.cs` - Removed ~50 lines
|
||||
4. ✅ **Modified:** `Minigames/Airplane/Core/AirplaneLaunchController.cs` - Removed ~130 lines
|
||||
|
||||
**Total Code Reduction:** ~180 lines removed, common implementation added (~220 lines)
|
||||
|
||||
**Net Change:** +40 lines total, but **-360 lines of duplicate code** consolidated into one place
|
||||
|
||||
---
|
||||
|
||||
## Compilation Status
|
||||
|
||||
✅ **Zero errors!** All files compile successfully.
|
||||
|
||||
**Minor Warnings:**
|
||||
- Unused using directives (cleanup)
|
||||
- Redundant default initializers (style)
|
||||
|
||||
---
|
||||
|
||||
## Unity Scene Setup
|
||||
|
||||
### For FortFight (Existing Scenes)
|
||||
|
||||
**Current State:**
|
||||
- Has old `TrajectoryPreview` component (from `Minigames.FortFight.Core`)
|
||||
|
||||
**Migration Options:**
|
||||
|
||||
**Option A: Replace Component (Recommended)**
|
||||
1. Select slingshot GameObject
|
||||
2. Remove old `FortFight.Core.TrajectoryPreview` component
|
||||
3. Add new `Common.Visual.TrajectoryPreview` component
|
||||
4. Configure visual settings (color, width, points)
|
||||
5. Base class will auto-find it
|
||||
|
||||
**Option B: Keep Old Component (Compatibility)**
|
||||
- Old `FortFight.Core.TrajectoryPreview` still exists in project
|
||||
- Can keep using it temporarily
|
||||
- But it won't get new improvements
|
||||
- Eventually should migrate to common version
|
||||
|
||||
### For Airplane (New Scenes)
|
||||
|
||||
**Setup:**
|
||||
1. Select launch controller GameObject
|
||||
2. Add `Common.Visual.TrajectoryPreview` component
|
||||
3. Add `LineRenderer` component (auto-required)
|
||||
4. Configure trajectory settings:
|
||||
- Trajectory Points: 20
|
||||
- Time Step: 0.1
|
||||
- Line Color: Yellow
|
||||
- Line Width: 0.1
|
||||
5. Base class will auto-find it
|
||||
|
||||
### Inspector Fields
|
||||
|
||||
**DragLaunchController now has:**
|
||||
- `Launch Anchor` - spawn point (required)
|
||||
- `Trajectory Preview` - optional, auto-finds if not assigned
|
||||
|
||||
**No inspector fields needed in subclasses for trajectory!**
|
||||
|
||||
---
|
||||
|
||||
## API Usage Examples
|
||||
|
||||
### From Game Code (If Needed)
|
||||
|
||||
```csharp
|
||||
// Access trajectory preview from controller
|
||||
trajectoryPreview.SetTrajectoryPoints(30); // Change point count
|
||||
trajectoryPreview.SetTimeStep(0.05f); // Change time step
|
||||
trajectoryPreview.LockTrajectory(2f); // Lock for 2 seconds
|
||||
|
||||
// Manual trajectory update (rare - base class handles this)
|
||||
trajectoryPreview.UpdateTrajectory(
|
||||
startPos,
|
||||
direction,
|
||||
force,
|
||||
projectilePrefab // Reads Rigidbody2D automatically
|
||||
);
|
||||
```
|
||||
|
||||
### For New Minigames
|
||||
|
||||
```csharp
|
||||
public class MyLauncher : DragLaunchController
|
||||
{
|
||||
protected override SlingshotConfig GetSlingshotConfig()
|
||||
{
|
||||
return mySettings.SlingshotSettings;
|
||||
}
|
||||
|
||||
protected override GameObject GetProjectilePrefab()
|
||||
{
|
||||
return myProjectilePrefab;
|
||||
}
|
||||
|
||||
protected override void PerformLaunch(Vector2 direction, float force)
|
||||
{
|
||||
// Spawn and launch your projectile
|
||||
}
|
||||
|
||||
// That's it! Trajectory preview works automatically.
|
||||
// Base class handles: ShowPreview, HidePreview, UpdateVisuals
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Benefits
|
||||
|
||||
✅ **Single Implementation** - One trajectory calculation, one place to fix bugs
|
||||
✅ **Less Code** - ~180 lines removed from game-specific controllers
|
||||
✅ **Easier Maintenance** - Change trajectory logic in one place
|
||||
✅ **Reusable** - Any future slingshot minigame gets it free
|
||||
✅ **Flexible API** - Multiple overloads for different use cases
|
||||
✅ **Automatic** - Base class handles everything, subclasses do nothing
|
||||
✅ **Accurate** - Reads physics directly from prefab's Rigidbody2D
|
||||
✅ **Configurable** - Visual settings in one component
|
||||
|
||||
---
|
||||
|
||||
## Migration Path for FortFight
|
||||
|
||||
### Immediate (Can Do Now)
|
||||
1. Old `FortFight.Core.TrajectoryPreview` still exists and works
|
||||
2. No breaking changes to existing scenes
|
||||
3. SlingshotController is compatible with both old and new component
|
||||
|
||||
### Future (Recommended)
|
||||
1. Replace old component with new `Common.Visual.TrajectoryPreview`
|
||||
2. Delete old `Minigames/FortFight/Core/TrajectoryPreview.cs` file
|
||||
3. Clean up any references
|
||||
|
||||
### Why Migrate?
|
||||
- Future improvements go to common version only
|
||||
- Old version reads gravity from settings (deprecated)
|
||||
- New version reads gravity from prefab's Rigidbody2D (accurate)
|
||||
- Consistency across all minigames
|
||||
|
||||
---
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
### FortFight
|
||||
- [ ] Trajectory preview shows during drag
|
||||
- [ ] Trajectory updates as you pull back
|
||||
- [ ] Trajectory locks after launch (shows for 2 seconds)
|
||||
- [ ] Different ammo types have different trajectories
|
||||
- [ ] Heavy projectiles have steeper arcs
|
||||
- [ ] Trajectory matches actual flight path
|
||||
|
||||
### Airplane
|
||||
- [ ] Add TrajectoryPreview component to scene
|
||||
- [ ] Trajectory preview shows during drag
|
||||
- [ ] Trajectory matches actual airplane flight
|
||||
- [ ] Preview hides when released
|
||||
- [ ] Prefab's Rigidbody2D mass and gravityScale are used
|
||||
|
||||
### General
|
||||
- [ ] No errors in console
|
||||
- [ ] Trajectory calculation is smooth
|
||||
- [ ] Colors and width are configurable
|
||||
- [ ] Line renderer appears/disappears correctly
|
||||
|
||||
---
|
||||
|
||||
## Old vs New Comparison
|
||||
|
||||
| Aspect | Before | After |
|
||||
|--------|--------|-------|
|
||||
| **Trajectory Code Location** | 2 places (FortFight + Airplane) | 1 place (Common) |
|
||||
| **Lines of Code** | ~230 (duplicated) | ~220 (common) + 0 in games |
|
||||
| **FortFight Controller** | ~300 lines | ~250 lines |
|
||||
| **Airplane Controller** | ~220 lines | ~90 lines |
|
||||
| **Maintenance** | Fix bugs in 2 places | Fix bugs in 1 place |
|
||||
| **New Minigames** | Copy/paste trajectory code | Add component, done |
|
||||
| **Gravity Calculation** | From settings (FortFight), inline (Airplane) | From prefab Rigidbody2D |
|
||||
| **API** | Internal, game-specific | Public, reusable overloads |
|
||||
|
||||
---
|
||||
|
||||
## Future Enhancements (Easy to Add Now)
|
||||
|
||||
Since trajectory is centralized, we can easily add:
|
||||
|
||||
- **Different Visualization Styles** (dots, dashed, solid)
|
||||
- **Collision Preview** (show where trajectory hits)
|
||||
- **Wind Effects** (add wind vector to calculation)
|
||||
- **Multiple Trajectories** (show min/max arc range)
|
||||
- **Performance Optimizations** (LOD, caching)
|
||||
- **Custom Materials** (glow, fade, animated)
|
||||
|
||||
All of these would benefit **every minigame** automatically!
|
||||
|
||||
---
|
||||
|
||||
## Conclusion
|
||||
|
||||
**Goal State Achieved:** ✅
|
||||
|
||||
✅ One common trajectory preview component
|
||||
✅ Easy-to-use API with multiple overloads
|
||||
✅ Used by both FortFight and Airplane controllers
|
||||
✅ Base class handles everything automatically
|
||||
✅ Subclasses have minimal code
|
||||
✅ No duplicate trajectory logic
|
||||
✅ Reads physics directly from prefabs
|
||||
✅ Zero compilation errors
|
||||
|
||||
**Status:** Ready for Unity testing!
|
||||
|
||||
**Next Step:** Add `Common.Visual.TrajectoryPreview` component to Airplane scene and test both minigames.
|
||||
|
||||
---
|
||||
|
||||
**Date:** December 4, 2025
|
||||
**Implementation Time:** ~30 minutes
|
||||
**Files Created:** 1
|
||||
**Files Modified:** 3
|
||||
**Code Reduction:** ~180 lines
|
||||
**Compilation Errors:** 0
|
||||
|
||||
Reference in New Issue
Block a user