|
@ -4,6 +4,9 @@ using UnityEngine; |
|
|
|
|
|
|
|
|
public class AudioController : MonoBehaviour |
|
|
public class AudioController : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
|
|
|
public Transform objectA; |
|
|
|
|
|
public Transform objectB; |
|
|
|
|
|
|
|
|
public AudioSource[] bgmSources; |
|
|
public AudioSource[] bgmSources; |
|
|
public AudioSource[] ambSources; |
|
|
public AudioSource[] ambSources; |
|
|
public AudioSource[] sfxSources; |
|
|
public AudioSource[] sfxSources; |
|
@ -20,6 +23,8 @@ public class AudioController : MonoBehaviour |
|
|
|
|
|
|
|
|
NotificationServer.register("fade bgm", fadeBgm); |
|
|
NotificationServer.register("fade bgm", fadeBgm); |
|
|
NotificationServer.register("fade amb", fadeAmb); |
|
|
NotificationServer.register("fade amb", fadeAmb); |
|
|
|
|
|
|
|
|
|
|
|
NotificationServer.register("statechange Searchlight", searchlightStateChanged); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Start() |
|
|
void Start() |
|
@ -31,9 +36,40 @@ public class AudioController : MonoBehaviour |
|
|
foreach (AudioSource s in sfxSources) |
|
|
foreach (AudioSource s in sfxSources) |
|
|
s.volume = 0f; |
|
|
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) |
|
|
public void playAmb(object audioNameObj) |
|
|
{ |
|
|
{ |
|
|
string audioName = audioNameObj as string; |
|
|
string audioName = audioNameObj as string; |
|
@ -65,7 +101,7 @@ public class AudioController : MonoBehaviour |
|
|
if (s.isPlaying) |
|
|
if (s.isPlaying) |
|
|
{ |
|
|
{ |
|
|
LeanTween.cancel(s.gameObject); |
|
|
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; |
|
|
s.volume = val; |
|
|
}).setOnComplete(()=>{ |
|
|
}).setOnComplete(()=>{ |
|
|
s.Stop(); |
|
|
s.Stop(); |
|
@ -78,7 +114,7 @@ public class AudioController : MonoBehaviour |
|
|
foundEmpty = true; |
|
|
foundEmpty = true; |
|
|
s.clip = clip; |
|
|
s.clip = clip; |
|
|
s.Play(); |
|
|
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; |
|
|
s.volume = val; |
|
|
}).setIgnoreTimeScale(true); |
|
|
}).setIgnoreTimeScale(true); |
|
|
} |
|
|
} |
|
@ -156,6 +192,7 @@ public class AudioController : MonoBehaviour |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
AudioSource foundEmpty = null; |
|
|
AudioSource foundEmpty = null; |
|
|
|
|
|
int timeSamples = 0; |
|
|
foreach (AudioSource s in bgmSources) |
|
|
foreach (AudioSource s in bgmSources) |
|
|
{ |
|
|
{ |
|
|
if (s.clip != null && s.clip == clip) |
|
|
if (s.clip != null && s.clip == clip) |
|
@ -165,8 +202,9 @@ public class AudioController : MonoBehaviour |
|
|
} |
|
|
} |
|
|
else if (s.isPlaying) |
|
|
else if (s.isPlaying) |
|
|
{ |
|
|
{ |
|
|
|
|
|
timeSamples = s.timeSamples; |
|
|
LeanTween.cancel(s.gameObject); |
|
|
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; |
|
|
s.volume = val; |
|
|
}).setOnComplete(()=>{ |
|
|
}).setOnComplete(()=>{ |
|
|
s.Stop(); |
|
|
s.Stop(); |
|
@ -183,15 +221,16 @@ public class AudioController : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
LeanTween.cancel(foundEmpty.gameObject); |
|
|
LeanTween.cancel(foundEmpty.gameObject); |
|
|
foundEmpty.clip = clip; |
|
|
foundEmpty.clip = clip; |
|
|
|
|
|
foundEmpty.timeSamples = timeSamples; |
|
|
foundEmpty.Play(); |
|
|
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; |
|
|
foundEmpty.volume = val; |
|
|
}).setIgnoreTimeScale(true); |
|
|
}).setIgnoreTimeScale(true); |
|
|
} |
|
|
} |
|
|
else if (foundEmpty != null && foundEmpty.isPlaying) |
|
|
else if (foundEmpty != null && foundEmpty.isPlaying) |
|
|
{ |
|
|
{ |
|
|
LeanTween.cancel(foundEmpty.gameObject); |
|
|
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; |
|
|
foundEmpty.volume = val; |
|
|
}).setIgnoreTimeScale(true); |
|
|
}).setIgnoreTimeScale(true); |
|
|
} |
|
|
} |
|
@ -204,7 +243,7 @@ public class AudioController : MonoBehaviour |
|
|
if (s.isPlaying) |
|
|
if (s.isPlaying) |
|
|
{ |
|
|
{ |
|
|
LeanTween.cancel(s.gameObject); |
|
|
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; |
|
|
s.volume = val; |
|
|
}).setOnComplete(()=>{ |
|
|
}).setOnComplete(()=>{ |
|
|
s.Stop(); |
|
|
s.Stop(); |
|
@ -221,7 +260,7 @@ public class AudioController : MonoBehaviour |
|
|
if (s.isPlaying) |
|
|
if (s.isPlaying) |
|
|
{ |
|
|
{ |
|
|
LeanTween.cancel(s.gameObject); |
|
|
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; |
|
|
s.volume = val; |
|
|
}).setOnComplete(()=>{ |
|
|
}).setOnComplete(()=>{ |
|
|
s.Stop(); |
|
|
s.Stop(); |
|
|