WinterJamSnowman/Assets/Scripts/EntityScripts/TileVisuals.cs

85 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Lemon.GenericLib.VFX;
public class TileVisuals : MonoBehaviour
{
[Header("Runtime")]
[Space]
[Header("Refereces")]
private TileDrawer tileDrawer;
[SerializeField] private HitFlash frontFlash;
[SerializeField] private HitFlash backFlash;
[SerializeField] private float flashDuration;
[SerializeField] private float shakeDuration = 0.2f;
private float entireDuration = 1.5f;
private VFX_Manager vfxManager;
private CameraController cameraController;
private bool isPlayer;
private bool initialized = false;
private void CheckInit()
{
if (!initialized)
{
//initialization code here
tileDrawer = GetComponent<TileDrawer>();
entireDuration = tileDrawer.board.CollapseCycleTime;
isPlayer = tileDrawer.board.controlledByPlayer;
tileDrawer.onStateChange += updateVisuals;
vfxManager = VFX_Manager.insatnceVFXM;
cameraController = CameraController.instanceCC;
initialized = true;
}
}
private void Start()
{
CheckInit();
}
private void updateVisuals(TileDrawer.TileState tileState){
CheckInit();
switch (tileState)
{
case TileDrawer.TileState.idle:
break;
case TileDrawer.TileState.pending:
StopCoroutine(FlashingCoroutine());
StartCoroutine(FlashingCoroutine());
break;
case TileDrawer.TileState.poof:
vfxManager?.spawnVFX("Explosion", transform.position);
vfxManager?.spawnVFX("ParticlePuff", transform.position);
if (isPlayer) {
Debug.Log("bro!!!'");
cameraController?.ApplyScreenShake(shakeDuration,10, true); //why does this not work!!!
}
break;
case TileDrawer.TileState.dropped:
vfxManager?.spawnVFX("ParticlePound", transform.position + (Vector3.down * 0.5f));
break;
case TileDrawer.TileState.none:
break;
default:
break;
}
}
IEnumerator FlashingCoroutine() {
frontFlash.Flash(flashDuration);
//backFlash.Flash(flashDuration);
yield return new WaitForSeconds(entireDuration - (flashDuration * 3));
frontFlash.Flash(flashDuration);
// backFlash.Flash(flashDuration);
yield return new WaitForSeconds(flashDuration * 2);
frontFlash.Flash(flashDuration);
//backFlash.Flash(flashDuration);
}
}