Add RumbleManager for enhanced player feedback and integrate with existing systems
This commit is contained in:
@@ -16,6 +16,7 @@ namespace Infrastructure.Unity
|
||||
[SerializeField] private PlayerController playerPrefab;
|
||||
[SerializeField] private DeathPlaneAdapter deathPlanePrefab;
|
||||
[SerializeField] private SoundManager soundManager;
|
||||
[SerializeField] private RumbleManager rumbleManager;
|
||||
[SerializeField] private CameraController cameraController;
|
||||
[SerializeField] private NpcController npcPrefab;
|
||||
[SerializeField] private HunterNpcController hunterNpcPrefab;
|
||||
@@ -65,7 +66,7 @@ namespace Infrastructure.Unity
|
||||
// Set Theme based on High Score
|
||||
ThemeManager.CurrentTheme = ThemeManager.GetTheme(_gameSession.HighScore);
|
||||
|
||||
if (levelGenerator) levelGenerator.Generate(soundManager, _allTiles, _tileViews, cameraController);
|
||||
if (levelGenerator) levelGenerator.Generate(soundManager, _allTiles, _tileViews, cameraController, rumbleManager);
|
||||
|
||||
SpawnDeathPlane();
|
||||
SpawnPlayer();
|
||||
@@ -275,6 +276,9 @@ namespace Infrastructure.Unity
|
||||
|
||||
instance.OnCollected += (t) =>
|
||||
{
|
||||
cameraController?.Shake(0.2f, 0.15f);
|
||||
rumbleManager?.PulseMedium();
|
||||
|
||||
if (t == PowerUpType.TimeSlow)
|
||||
{
|
||||
_gameSession.ActivateTimeSlow(10f);
|
||||
|
||||
@@ -27,19 +27,17 @@ namespace Infrastructure.Unity
|
||||
|
||||
private TilePool _tilePool;
|
||||
|
||||
public void Generate(SoundManager soundManager, List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, CameraController camera)
|
||||
public void Generate(SoundManager soundManager, List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, CameraController camera, RumbleManager rumble)
|
||||
{
|
||||
_tilePool = new TilePool(tilePrefab, transform);
|
||||
|
||||
GenerateFloor(0, MapPatterns.GenerateSquare(gridSizeX, gridSizeY), soundManager, allTiles, tileViews, camera);
|
||||
|
||||
GenerateFloor(1, MapPatterns.GenerateDonut(gridSizeX, Mathf.FloorToInt(gridSizeX / 3f)), soundManager, allTiles, tileViews, camera);
|
||||
|
||||
GenerateFloor(2, MapPatterns.GenerateCircle(gridSizeX), soundManager, allTiles, tileViews, camera);
|
||||
GenerateFloor(0, MapPatterns.GenerateSquare(gridSizeX, gridSizeY), soundManager, allTiles, tileViews, camera, rumble);
|
||||
GenerateFloor(1, MapPatterns.GenerateDonut(gridSizeX, Mathf.FloorToInt(gridSizeX / 3f)), soundManager, allTiles, tileViews, camera, rumble);
|
||||
GenerateFloor(2, MapPatterns.GenerateCircle(gridSizeX), soundManager, allTiles, tileViews, camera, rumble);
|
||||
}
|
||||
|
||||
private void GenerateFloor(int floorIndex, List<Vector2Int> coordinates, SoundManager soundManager,
|
||||
List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, CameraController camera)
|
||||
List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, CameraController camera, RumbleManager rumble)
|
||||
{
|
||||
var yOffset = -(floorIndex * floorHeightDistance);
|
||||
var xOffset = gridSizeX / 2f;
|
||||
@@ -48,7 +46,7 @@ namespace Infrastructure.Unity
|
||||
foreach (var coord in coordinates)
|
||||
{
|
||||
var pos = new Vector3(coord.x - xOffset, yOffset, coord.y - zOffset);
|
||||
CreateTile(pos, $"{floorIndex}_{coord.x}_{coord.y}", floorIndex, soundManager, allTiles, tileViews, camera);
|
||||
CreateTile(pos, $"{floorIndex}_{coord.x}_{coord.y}", floorIndex, soundManager, allTiles, tileViews, camera, rumble);
|
||||
}
|
||||
|
||||
if (floorIndex > 0 && jumpPadPrefab)
|
||||
@@ -80,11 +78,20 @@ namespace Infrastructure.Unity
|
||||
|
||||
telA.Initialize(telB.transform);
|
||||
telB.Initialize(telA.transform);
|
||||
|
||||
System.Action onTeleport = () =>
|
||||
{
|
||||
camera?.Shake(0.2f, 0.2f);
|
||||
rumble?.PulseMedium();
|
||||
};
|
||||
|
||||
telA.OnTeleport += onTeleport;
|
||||
telB.OnTeleport += onTeleport;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateTile(Vector3 position, string id, int floorIndex, SoundManager soundManager,
|
||||
List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, CameraController camera)
|
||||
List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, CameraController camera, RumbleManager rumble)
|
||||
{
|
||||
var go = _tilePool.Get();
|
||||
go.transform.position = position;
|
||||
@@ -111,6 +118,7 @@ namespace Infrastructure.Unity
|
||||
if (t.Type == TileType.Fragile)
|
||||
{
|
||||
camera?.Shake(0.1f, 0.05f);
|
||||
rumble?.PulseLight();
|
||||
}
|
||||
|
||||
if (tileBreakVfxPrefab)
|
||||
|
||||
37
Assets/Scripts/Infrastructure/Unity/RumbleManager.cs
Normal file
37
Assets/Scripts/Infrastructure/Unity/RumbleManager.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Infrastructure.Unity
|
||||
{
|
||||
public class RumbleManager : MonoBehaviour
|
||||
{
|
||||
private Coroutine _rumbleCoroutine;
|
||||
|
||||
public void Pulse(float lowFrequency, float highFrequency, float duration)
|
||||
{
|
||||
if (Gamepad.current == null) return;
|
||||
|
||||
if (_rumbleCoroutine != null) StopCoroutine(_rumbleCoroutine);
|
||||
|
||||
_rumbleCoroutine = StartCoroutine(RumbleRoutine(lowFrequency, highFrequency, duration));
|
||||
}
|
||||
|
||||
public void PulseLight() => Pulse(0.1f, 0.2f, 0.1f);
|
||||
public void PulseMedium() => Pulse(0.4f, 0.5f, 0.2f);
|
||||
public void PulseHeavy() => Pulse(0.8f, 1.0f, 0.3f);
|
||||
|
||||
private IEnumerator RumbleRoutine(float low, float high, float duration)
|
||||
{
|
||||
Gamepad.current.SetMotorSpeeds(low, high);
|
||||
yield return new WaitForSeconds(duration);
|
||||
Gamepad.current.SetMotorSpeeds(0f, 0f);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (Gamepad.current != null)
|
||||
Gamepad.current.SetMotorSpeeds(0f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6eb2e3678564ac1b40c68e722a6469f
|
||||
timeCreated: 1765581035
|
||||
@@ -5,6 +5,8 @@ namespace Infrastructure.Unity
|
||||
{
|
||||
public class TeleporterAdapter : MonoBehaviour
|
||||
{
|
||||
public event Action OnTeleport;
|
||||
|
||||
private Transform _targetDestination;
|
||||
private TeleporterAdapter _targetAdapter;
|
||||
private float _cooldownTimer;
|
||||
@@ -45,6 +47,7 @@ namespace Infrastructure.Unity
|
||||
}
|
||||
|
||||
Lock(1.0f);
|
||||
OnTeleport?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user