2024-04-28 14:41:33 -07:00

68 lines
1.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace ScarletMansion {
public class ScarletVent : MonoBehaviour {
public AudioSource shakeAudioSource;
public AudioSource summonAudioSource;
public PlayAudioAnimationEvent audioEvent;
[Header("Shake")]
public ParticleSystem spawningPartciles;
public ParticleSystem lightingParticles;
public ParticleSystem emitParticles;
public float volumeToRate = 1f;
public static bool prewarm;
void Start(){
if (!prewarm){
OpenVentClientRpc();
prewarm = true;
Plugin.logger.LogInfo("Prewarming particles by forcing it emit now lmao");
}
}
private void PlayParticleSystem(ParticleSystem ps){
if (ps.isPlaying) return;
ps.Play();
}
private void StopParticleSystem(ParticleSystem ps){
if (!ps.isPlaying) return;
ps.Stop();
}
public void OpenVentClientRpc(){
emitParticles.Play();
audioEvent.PlayAudio1Oneshot();
}
void Update(){
var isPlaying = shakeAudioSource.isPlaying;
if (isPlaying){
PlayParticleSystem(spawningPartciles);
SetEmissionRate(spawningPartciles, shakeAudioSource.volume * volumeToRate);
if (shakeAudioSource.volume >= 0.8f) PlayParticleSystem(lightingParticles);
else StopParticleSystem(lightingParticles);
} else {
StopParticleSystem(spawningPartciles);
StopParticleSystem(lightingParticles);
}
}
private void SetEmissionRate(ParticleSystem ps, float mult){
var emis = ps.emission;
emis.rateOverTimeMultiplier = mult;
}
}
}