refactor: power-up effects applied centrally in GameBootstrap
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using Core.Domain;
|
using Core.Domain;
|
||||||
|
using Core.Domain.Status.Effects;
|
||||||
using Core.Ports;
|
using Core.Ports;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -370,14 +371,22 @@ namespace Infrastructure.Unity
|
|||||||
|
|
||||||
instance.Configure(type);
|
instance.Configure(type);
|
||||||
|
|
||||||
instance.OnCollected += (t) =>
|
instance.OnCollected += (t, dur) =>
|
||||||
{
|
{
|
||||||
cameraController?.Shake(0.2f, 0.15f);
|
cameraController?.Shake(0.2f, 0.15f);
|
||||||
rumbleManager?.PulseMedium();
|
rumbleManager?.PulseMedium();
|
||||||
|
|
||||||
if (t == PowerUpType.TimeSlow)
|
switch (t)
|
||||||
{
|
{
|
||||||
_gameSession.ActivateTimeSlow(10f);
|
case PowerUpType.TimeSlow:
|
||||||
|
_gameSession.ActivateTimeSlow(dur);
|
||||||
|
break;
|
||||||
|
case PowerUpType.LightFooted:
|
||||||
|
_playerInstance?.Status.AddEffect(new LightFootedEffect(dur));
|
||||||
|
break;
|
||||||
|
case PowerUpType.SpeedBoost:
|
||||||
|
_playerInstance?.Status.AddEffect(new SpeedBoostEffect(dur));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using Core.Domain;
|
using Core.Domain;
|
||||||
using Core.Domain.Status.Effects;
|
|
||||||
using KBCore.Refs;
|
using KBCore.Refs;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ namespace Infrastructure.Unity
|
|||||||
private MaterialPropertyBlock _propBlock;
|
private MaterialPropertyBlock _propBlock;
|
||||||
private static readonly int ColorProperty = Shader.PropertyToID("_BaseColor");
|
private static readonly int ColorProperty = Shader.PropertyToID("_BaseColor");
|
||||||
|
|
||||||
public event Action<PowerUpType> OnCollected;
|
public event Action<PowerUpType, float> OnCollected;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@@ -45,20 +44,16 @@ namespace Infrastructure.Unity
|
|||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
if (other.TryGetComponent<PlayerController>(out var player))
|
if (other.TryGetComponent<PlayerController>(out _))
|
||||||
{
|
{
|
||||||
ApplyEffect(player);
|
OnCollected?.Invoke(type, duration);
|
||||||
OnCollected?.Invoke(type);
|
|
||||||
|
|
||||||
if (pickupVfx)
|
if (pickupVfx)
|
||||||
{
|
{
|
||||||
var vfx = Instantiate(pickupVfx, transform.position, Quaternion.identity);
|
var vfx = Instantiate(pickupVfx, transform.position, Quaternion.identity);
|
||||||
var main = vfx.main;
|
var main = vfx.main;
|
||||||
|
|
||||||
meshRenderer.GetPropertyBlock(_propBlock);
|
meshRenderer.GetPropertyBlock(_propBlock);
|
||||||
var currentColor = _propBlock.GetColor(ColorProperty);
|
main.startColor = _propBlock.GetColor(ColorProperty);
|
||||||
main.startColor = currentColor;
|
|
||||||
|
|
||||||
Destroy(vfx.gameObject, 2f);
|
Destroy(vfx.gameObject, 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,24 +61,6 @@ namespace Infrastructure.Unity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyEffect(PlayerController player)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case PowerUpType.LightFooted:
|
|
||||||
player.Status.AddEffect(new LightFootedEffect(duration));
|
|
||||||
break;
|
|
||||||
case PowerUpType.SpeedBoost:
|
|
||||||
player.Status.AddEffect(new SpeedBoostEffect(duration, 1.5f));
|
|
||||||
break;
|
|
||||||
case PowerUpType.TimeSlow:
|
|
||||||
// Handled globally
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Configure(PowerUpType newType)
|
public void Configure(PowerUpType newType)
|
||||||
{
|
{
|
||||||
type = newType;
|
type = newType;
|
||||||
|
|||||||
Reference in New Issue
Block a user