Little Trafalgar dust trail fun

This commit is contained in:
Michal Pikulski
2025-09-23 11:05:35 +02:00
parent 2ae2bc3ac5
commit 4b206b9b2e
17 changed files with 5734 additions and 1 deletions

3
Assets/Scripts/FX.meta Normal file
View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f055c7c056594d629fab36165f110dca
timeCreated: 1758616881

View File

@@ -0,0 +1,91 @@
using UnityEngine;
using Input;
namespace FX
{
/// <summary>
/// Controls particle effects based on player movement.
/// Automatically enables/disables particle emission when the player starts/stops moving.
/// Attach this to the same GameObject as the PlayerTouchController.
/// </summary>
public class TrafalgarFXController : MonoBehaviour
{
private PlayerTouchController _playerController;
private ParticleSystem _particleSystem;
private void Awake()
{
// Get the PlayerTouchController on this game object
_playerController = GetComponent<PlayerTouchController>();
if (_playerController == null)
{
Debug.LogError("TrafalgarFXController: No PlayerTouchController found on this GameObject! This component should be attached to the same GameObject as PlayerTouchController.");
enabled = false;
return;
}
// Find the particle system in children
_particleSystem = GetComponentInChildren<ParticleSystem>();
if (_particleSystem == null)
{
Debug.LogError("TrafalgarFXController: No ParticleSystem found in children! This component requires a ParticleSystem in the hierarchy below it.");
enabled = false;
return;
}
// Make sure emission is disabled at start
var emission = _particleSystem.emission;
emission.enabled = false;
}
private void Start()
{
// Subscribe to movement events
_playerController.OnMovementStarted += EnableParticles;
_playerController.OnMovementStopped += DisableParticles;
// Set initial state based on current movement status
SetParticlesState(_playerController.IsMoving);
}
private void OnDestroy()
{
// Unsubscribe from events when this component is destroyed
if (_playerController != null)
{
_playerController.OnMovementStarted -= EnableParticles;
_playerController.OnMovementStopped -= DisableParticles;
}
}
private void EnableParticles()
{
SetParticlesState(true);
}
private void DisableParticles()
{
SetParticlesState(false);
}
private void SetParticlesState(bool enabled)
{
if (_particleSystem != null)
{
var emission = _particleSystem.emission;
emission.enabled = enabled;
if (enabled)
{
// Optionally play the system when enabling (useful if it's not in looping mode)
if (!_particleSystem.isPlaying)
{
_particleSystem.Play();
}
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d5435358d90b4c29982a670998cd9a56
timeCreated: 1758617481

View File

@@ -20,6 +20,12 @@ namespace Input
public LayerMask obstacleMask;
public float colliderRadius = 0.5f;
// --- Movement Events ---
private bool _isMoving = false;
public bool IsMoving => _isMoving;
public event System.Action OnMovementStarted;
public event System.Action OnMovementStopped;
// --- Unity/Component References ---
private AIPath aiPath;
@@ -225,6 +231,8 @@ namespace Input
void Update()
{
UpdateMovementState();
if (animator != null && aiPath != null)
{
float normalizedSpeed = 0f;
@@ -244,6 +252,39 @@ namespace Input
}
}
/// <summary>
/// Checks if the player is currently moving and fires appropriate events when movement state changes.
/// </summary>
private void UpdateMovementState()
{
bool isCurrentlyMoving = false;
// Check direct movement
if (isHolding && GameManager.Instance.DefaultHoldMovementMode == GameSettings.HoldMovementMode.Direct)
{
isCurrentlyMoving = directMoveVelocity.sqrMagnitude > 0.001f;
}
// Check pathfinding movement
else if (aiPath != null && aiPath.enabled)
{
isCurrentlyMoving = aiPath.velocity.sqrMagnitude > 0.001f;
}
// Fire events only when state changes
if (isCurrentlyMoving && !_isMoving)
{
_isMoving = true;
OnMovementStarted?.Invoke();
Debug.Log("[PlayerTouchController] Movement started");
}
else if (!isCurrentlyMoving && _isMoving)
{
_isMoving = false;
OnMovementStopped?.Invoke();
Debug.Log("[PlayerTouchController] Movement stopped");
}
}
private void SetSpriteFlip(Vector3 velocity)
{
if (spriteRenderer != null && velocity.sqrMagnitude > 0.001f)