Add BeatPulseController for music synchronization and event handling
This commit is contained in:
@@ -28,6 +28,7 @@ namespace Infrastructure.Unity
|
||||
|
||||
private MaterialPropertyBlock _propBlock;
|
||||
private static readonly int ColorProperty = Shader.PropertyToID("_BaseColor");
|
||||
private static readonly int EmissionIntensity = Shader.PropertyToID("_EmissionIntensity");
|
||||
|
||||
private Action<TileViewAdapter> _onReturnToPool;
|
||||
|
||||
@@ -108,6 +109,12 @@ namespace Infrastructure.Unity
|
||||
_linkedTile?.StepOn();
|
||||
}
|
||||
|
||||
public void PulseEmission(float intensity)
|
||||
{
|
||||
StartCoroutine(PulseEmissionRoutine(intensity, 0.2f));
|
||||
StartCoroutine(PulseScaleRoutine());
|
||||
}
|
||||
|
||||
private void SetColor(Color color)
|
||||
{
|
||||
meshRenderer.GetPropertyBlock(_propBlock);
|
||||
@@ -157,5 +164,26 @@ namespace Infrastructure.Unity
|
||||
_linkedTile.OnStateChanged -= OnTileStateChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator PulseScaleRoutine()
|
||||
{
|
||||
var original = transform.localScale;
|
||||
transform.localScale = original * 1.05f;
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
transform.localScale = original;
|
||||
}
|
||||
|
||||
private IEnumerator PulseEmissionRoutine(float intensity, float duration)
|
||||
{
|
||||
meshRenderer.GetPropertyBlock(_propBlock);
|
||||
var originalIntensity = _propBlock.GetFloat(EmissionIntensity);
|
||||
_propBlock.SetFloat(EmissionIntensity, intensity);
|
||||
meshRenderer.SetPropertyBlock(_propBlock);
|
||||
|
||||
yield return new WaitForSeconds(duration);
|
||||
|
||||
_propBlock.SetFloat(EmissionIntensity, originalIntensity);
|
||||
meshRenderer.SetPropertyBlock(_propBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user