引入 BGM 切换+文档初版草稿
This commit is contained in:
@@ -3,6 +3,7 @@ using DataTable;
|
||||
using Definition;
|
||||
using GameFramework.DataTable;
|
||||
using GameFramework.Sound;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace Sound
|
||||
@@ -11,8 +12,17 @@ namespace Sound
|
||||
{
|
||||
private const float FadeVolumeDuration = 1f;
|
||||
private static int? s_MusicSerialId = null;
|
||||
private static int? s_CurrentBgmId = null;
|
||||
private static float s_CurrentBgmStartOffsetSeconds = 0f;
|
||||
private static float s_CurrentBgmStartRealtime = 0f;
|
||||
|
||||
public static int? PlayBGM(this SoundComponent soundComponent, int musicId, object userData = null)
|
||||
{
|
||||
return PlayBGM(soundComponent, musicId, 0f, userData);
|
||||
}
|
||||
|
||||
public static int? PlayBGM(this SoundComponent soundComponent, int musicId, float startTimeSeconds,
|
||||
object userData = null)
|
||||
{
|
||||
soundComponent.StopMusic();
|
||||
|
||||
@@ -30,8 +40,12 @@ namespace Sound
|
||||
playSoundParams.VolumeInSoundGroup = 1f;
|
||||
playSoundParams.FadeInSeconds = FadeVolumeDuration;
|
||||
playSoundParams.SpatialBlend = 0f;
|
||||
playSoundParams.Time = Mathf.Max(0f, startTimeSeconds);
|
||||
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drBgm.AssetName), "BGM",
|
||||
Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
|
||||
s_CurrentBgmId = musicId;
|
||||
s_CurrentBgmStartOffsetSeconds = playSoundParams.Time;
|
||||
s_CurrentBgmStartRealtime = Time.realtimeSinceStartup;
|
||||
return s_MusicSerialId;
|
||||
}
|
||||
|
||||
@@ -44,6 +58,26 @@ namespace Sound
|
||||
|
||||
soundComponent.StopSound(s_MusicSerialId.Value, FadeVolumeDuration);
|
||||
s_MusicSerialId = null;
|
||||
s_CurrentBgmId = null;
|
||||
s_CurrentBgmStartOffsetSeconds = 0f;
|
||||
s_CurrentBgmStartRealtime = 0f;
|
||||
}
|
||||
|
||||
public static bool TryGetCurrentBgmSnapshot(this SoundComponent soundComponent, out int bgmId,
|
||||
out float timeSeconds)
|
||||
{
|
||||
bgmId = 0;
|
||||
timeSeconds = 0f;
|
||||
|
||||
if (!s_MusicSerialId.HasValue || !s_CurrentBgmId.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bgmId = s_CurrentBgmId.Value;
|
||||
timeSeconds = s_CurrentBgmStartOffsetSeconds +
|
||||
Mathf.Max(0f, Time.realtimeSinceStartup - s_CurrentBgmStartRealtime);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int? PlaySE(this SoundComponent soundComponent, int uiSoundId, object userData = null)
|
||||
@@ -104,4 +138,4 @@ namespace Sound
|
||||
GameEntry.Setting.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user