|
|
@ -4,6 +4,9 @@ using UnityEngine; |
|
|
|
|
|
|
|
public class AudioController : MonoBehaviour |
|
|
|
{ |
|
|
|
public Transform objectA; |
|
|
|
public Transform objectB; |
|
|
|
|
|
|
|
public AudioSource[] bgmSources; |
|
|
|
public AudioSource[] ambSources; |
|
|
|
public AudioSource[] sfxSources; |
|
|
@ -20,6 +23,8 @@ public class AudioController : MonoBehaviour |
|
|
|
|
|
|
|
NotificationServer.register("fade bgm", fadeBgm); |
|
|
|
NotificationServer.register("fade amb", fadeAmb); |
|
|
|
|
|
|
|
NotificationServer.register("statechange Searchlight", searchlightStateChanged); |
|
|
|
} |
|
|
|
|
|
|
|
void Start() |
|
|
@ -31,9 +36,40 @@ public class AudioController : MonoBehaviour |
|
|
|
foreach (AudioSource s in sfxSources) |
|
|
|
s.volume = 0f; |
|
|
|
|
|
|
|
NotificationServer.notify("play amb", "oceanAmbience:0.5"); |
|
|
|
NotificationServer.notify("play amb", "oceanAmbience:0.4"); |
|
|
|
} |
|
|
|
|
|
|
|
// void Update()
|
|
|
|
// {
|
|
|
|
// doMusicMix();
|
|
|
|
// }
|
|
|
|
|
|
|
|
public void doMusicMix() |
|
|
|
{ |
|
|
|
NotificationServer.notify("play bgm", "tense:0.75"); |
|
|
|
// float distance = Vector3.Distance(objectA.position, objectB.position);
|
|
|
|
// Debug.LogWarning(distance);
|
|
|
|
// distance = Mathf.Clamp(1000f / distance, 0f, 1f);
|
|
|
|
// float tenseVol = 0.75f * distance;
|
|
|
|
// float spottedVol = 0.5f * (1f-distance);
|
|
|
|
// NotificationServer.notify("play bgm", "tense:"+tenseVol+"/spotted"+spottedVol);
|
|
|
|
} |
|
|
|
|
|
|
|
public void searchlightStateChanged() |
|
|
|
{ |
|
|
|
if (Searchlight.state == Searchlight.SearchState.Chasing) |
|
|
|
{ |
|
|
|
NotificationServer.notify("play sfx", "shipSpotted:0.5"); |
|
|
|
// NotificationServer.notify("play sfx", "spottedDialogue");
|
|
|
|
NotificationServer.notify("play bgm", "attack:9"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
doMusicMix(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void playAmb(object audioNameObj) |
|
|
|
{ |
|
|
|
string audioName = audioNameObj as string; |
|
|
@ -65,7 +101,7 @@ public class AudioController : MonoBehaviour |
|
|
|
if (s.isPlaying) |
|
|
|
{ |
|
|
|
LeanTween.cancel(s.gameObject); |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 1f).setOnUpdate((float val)=>{ |
|
|
|
s.volume = val; |
|
|
|
}).setOnComplete(()=>{ |
|
|
|
s.Stop(); |
|
|
@ -78,7 +114,7 @@ public class AudioController : MonoBehaviour |
|
|
|
foundEmpty = true; |
|
|
|
s.clip = clip; |
|
|
|
s.Play(); |
|
|
|
LeanTween.value(s.gameObject, s.volume, volume, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(s.gameObject, s.volume, volume, 1f).setOnUpdate((float val)=>{ |
|
|
|
s.volume = val; |
|
|
|
}).setIgnoreTimeScale(true); |
|
|
|
} |
|
|
@ -156,6 +192,7 @@ public class AudioController : MonoBehaviour |
|
|
|
return; |
|
|
|
|
|
|
|
AudioSource foundEmpty = null; |
|
|
|
int timeSamples = 0; |
|
|
|
foreach (AudioSource s in bgmSources) |
|
|
|
{ |
|
|
|
if (s.clip != null && s.clip == clip) |
|
|
@ -165,8 +202,9 @@ public class AudioController : MonoBehaviour |
|
|
|
} |
|
|
|
else if (s.isPlaying) |
|
|
|
{ |
|
|
|
timeSamples = s.timeSamples; |
|
|
|
LeanTween.cancel(s.gameObject); |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 1f).setOnUpdate((float val)=>{ |
|
|
|
s.volume = val; |
|
|
|
}).setOnComplete(()=>{ |
|
|
|
s.Stop(); |
|
|
@ -183,15 +221,16 @@ public class AudioController : MonoBehaviour |
|
|
|
{ |
|
|
|
LeanTween.cancel(foundEmpty.gameObject); |
|
|
|
foundEmpty.clip = clip; |
|
|
|
foundEmpty.timeSamples = timeSamples; |
|
|
|
foundEmpty.Play(); |
|
|
|
LeanTween.value(foundEmpty.gameObject, foundEmpty.volume, volume, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(foundEmpty.gameObject, foundEmpty.volume, volume, 1f).setOnUpdate((float val)=>{ |
|
|
|
foundEmpty.volume = val; |
|
|
|
}).setIgnoreTimeScale(true); |
|
|
|
} |
|
|
|
else if (foundEmpty != null && foundEmpty.isPlaying) |
|
|
|
{ |
|
|
|
LeanTween.cancel(foundEmpty.gameObject); |
|
|
|
LeanTween.value(foundEmpty.gameObject, foundEmpty.volume, volume, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(foundEmpty.gameObject, foundEmpty.volume, volume, 1f).setOnUpdate((float val)=>{ |
|
|
|
foundEmpty.volume = val; |
|
|
|
}).setIgnoreTimeScale(true); |
|
|
|
} |
|
|
@ -204,7 +243,7 @@ public class AudioController : MonoBehaviour |
|
|
|
if (s.isPlaying) |
|
|
|
{ |
|
|
|
LeanTween.cancel(s.gameObject); |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 1f).setOnUpdate((float val)=>{ |
|
|
|
s.volume = val; |
|
|
|
}).setOnComplete(()=>{ |
|
|
|
s.Stop(); |
|
|
@ -221,7 +260,7 @@ public class AudioController : MonoBehaviour |
|
|
|
if (s.isPlaying) |
|
|
|
{ |
|
|
|
LeanTween.cancel(s.gameObject); |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 0.5f).setOnUpdate((float val)=>{ |
|
|
|
LeanTween.value(s.gameObject, s.volume, 0f, 1f).setOnUpdate((float val)=>{ |
|
|
|
s.volume = val; |
|
|
|
}).setOnComplete(()=>{ |
|
|
|
s.Stop(); |
|
|
|