102 lines
2.2 KiB
C#
102 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class LevelSoundManager : MonoBehaviour
|
|
{
|
|
public List<string> ambientsDay = new List<string>();
|
|
|
|
public List<string> ambientsNight = new List<string>();
|
|
|
|
public float ambientFadeTime = 30f;
|
|
|
|
public List<AudioObject> ambientsDayAudioObject = new List<AudioObject>();
|
|
|
|
public List<AudioObject> ambientsNightAudioObject = new List<AudioObject>();
|
|
|
|
public bool sameNightEffects;
|
|
|
|
public string effectsDay = string.Empty;
|
|
|
|
public string effectsNight = string.Empty;
|
|
|
|
[ReadOnly]
|
|
public float effectTimer = -1f;
|
|
|
|
public Vector2 effectFrequency = new Vector2(10f, 30f);
|
|
|
|
[ReadOnly]
|
|
public bool isDay = true;
|
|
|
|
public void Initialize()
|
|
{
|
|
effectTimer = Random.Range(effectFrequency.x, effectFrequency.y);
|
|
AudioObject audioObject = null;
|
|
for (int i = 0; i < ambientsNight.Count; i++)
|
|
{
|
|
audioObject = AudioController.Play(ambientsNight[i]);
|
|
if ((bool)audioObject)
|
|
{
|
|
audioObject.Pause();
|
|
ambientsNightAudioObject.Add(audioObject);
|
|
}
|
|
}
|
|
for (int j = 0; j < ambientsDay.Count; j++)
|
|
{
|
|
audioObject = AudioController.Play(ambientsDay[j]);
|
|
if ((bool)audioObject)
|
|
{
|
|
if (ambientsNightAudioObject.Count > 0)
|
|
{
|
|
audioObject.Pause();
|
|
}
|
|
ambientsDayAudioObject.Add(audioObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (effectTimer > 0f)
|
|
{
|
|
effectTimer -= Time.deltaTime;
|
|
if (effectTimer <= 0f)
|
|
{
|
|
effectTimer = Random.Range(effectFrequency.x, effectFrequency.y);
|
|
AudioController.Play((!isDay && !sameNightEffects) ? effectsNight : effectsDay, Random.Range(0.2f, 1f));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StartDay(bool startDay, bool instant)
|
|
{
|
|
isDay = startDay;
|
|
if (ambientsNightAudioObject.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < ambientsDayAudioObject.Count; i++)
|
|
{
|
|
if (isDay)
|
|
{
|
|
ambientsDayAudioObject[i].Unpause((!instant) ? ambientFadeTime : 0f);
|
|
}
|
|
else
|
|
{
|
|
ambientsDayAudioObject[i].Pause((!instant) ? ambientFadeTime : 0f);
|
|
}
|
|
}
|
|
for (int j = 0; j < ambientsNightAudioObject.Count; j++)
|
|
{
|
|
if (!isDay)
|
|
{
|
|
ambientsNightAudioObject[j].Unpause((!instant) ? ambientFadeTime : 0f);
|
|
}
|
|
else
|
|
{
|
|
ambientsNightAudioObject[j].Pause((!instant) ? ambientFadeTime : 0f);
|
|
}
|
|
}
|
|
}
|
|
}
|