diff --git a/Assets/Plugins/iOS/LofeltHaptics.framework.meta b/Assets/Plugins/iOS/LofeltHaptics.framework.meta
index 47312cc..91e3981 100644
--- a/Assets/Plugins/iOS/LofeltHaptics.framework.meta
+++ b/Assets/Plugins/iOS/LofeltHaptics.framework.meta
@@ -1,6 +1,5 @@
fileFormatVersion: 2
guid: 3f3b3e40c5ec34183af765f15c1ce362
-folderAsset: yes
PluginImporter:
externalObjects: {}
serializedVersion: 2
@@ -12,24 +11,6 @@ PluginImporter:
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- - first:
- : Any
- second:
- enabled: 0
- settings:
- Exclude Android: 1
- Exclude Editor: 1
- Exclude Linux64: 1
- Exclude OSXUniversal: 1
- Exclude Win: 1
- Exclude Win64: 1
- Exclude iOS: 0
- - first:
- Android: Android
- second:
- enabled: 0
- settings:
- CPU: ARMv7
- first:
Any:
second:
@@ -40,42 +21,13 @@ PluginImporter:
second:
enabled: 0
settings:
- CPU: AnyCPU
DefaultValueInitialized: true
- OS: AnyOS
- - first:
- Standalone: Linux64
- second:
- enabled: 0
- settings:
- CPU: None
- - first:
- Standalone: OSXUniversal
- second:
- enabled: 0
- settings:
- CPU: None
- - first:
- Standalone: Win
- second:
- enabled: 0
- settings:
- CPU: None
- - first:
- Standalone: Win64
- second:
- enabled: 0
- settings:
- CPU: None
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: true
- CPU: AnyCPU
- CompileFlags:
- FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
diff --git a/Assets/Resources/Audios/au_sfx_notice_level_countDown_edge.wav b/Assets/Resources/Audios/au_sfx_notice_level_countDown_edge.wav
new file mode 100644
index 0000000..d5ba137
--- /dev/null
+++ b/Assets/Resources/Audios/au_sfx_notice_level_countDown_edge.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1e832d9b133d74f1d9723c8605881ba305c37d2e0ed3767efa8014949bfadf22
+size 251992
diff --git a/Assets/Resources/Audios/au_sfx_notice_level_countDown_edge.wav.meta b/Assets/Resources/Audios/au_sfx_notice_level_countDown_edge.wav.meta
new file mode 100644
index 0000000..c43db99
--- /dev/null
+++ b/Assets/Resources/Audios/au_sfx_notice_level_countDown_edge.wav.meta
@@ -0,0 +1,23 @@
+fileFormatVersion: 2
+guid: e640dc3c900064126804112a521170ea
+AudioImporter:
+ externalObjects: {}
+ serializedVersion: 7
+ defaultSettings:
+ serializedVersion: 2
+ loadType: 0
+ sampleRateSetting: 0
+ sampleRateOverride: 44100
+ compressionFormat: 1
+ quality: 1
+ conversionMode: 0
+ preloadAudioData: 0
+ platformSettingOverrides: {}
+ forceToMono: 0
+ normalize: 1
+ loadInBackground: 0
+ ambisonic: 0
+ 3D: 1
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Resources/Audios/au_sfx_notice_level_countDown_time.wav b/Assets/Resources/Audios/au_sfx_notice_level_countDown_time.wav
new file mode 100644
index 0000000..6c2fc02
--- /dev/null
+++ b/Assets/Resources/Audios/au_sfx_notice_level_countDown_time.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:277376c43a54a39ff777d5843c5aff20a2457fdc579668e8cb83a050699d8166
+size 109256
diff --git a/Assets/Resources/Audios/au_sfx_notice_level_countDown_time.wav.meta b/Assets/Resources/Audios/au_sfx_notice_level_countDown_time.wav.meta
new file mode 100644
index 0000000..575ddb8
--- /dev/null
+++ b/Assets/Resources/Audios/au_sfx_notice_level_countDown_time.wav.meta
@@ -0,0 +1,23 @@
+fileFormatVersion: 2
+guid: be8f215dba3904ddf9f72fc064c97e71
+AudioImporter:
+ externalObjects: {}
+ serializedVersion: 7
+ defaultSettings:
+ serializedVersion: 2
+ loadType: 0
+ sampleRateSetting: 0
+ sampleRateOverride: 44100
+ compressionFormat: 1
+ quality: 1
+ conversionMode: 0
+ preloadAudioData: 0
+ platformSettingOverrides: {}
+ forceToMono: 0
+ normalize: 1
+ loadInBackground: 0
+ ambisonic: 0
+ 3D: 1
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity
index e3f8118..eb910d9 100644
--- a/Assets/Scenes/SampleScene.unity
+++ b/Assets/Scenes/SampleScene.unity
@@ -1012,7 +1012,7 @@ GameObject:
- component: {fileID: 1394234350}
- component: {fileID: 1394234349}
m_Layer: 5
- m_Name: Button (Legacy)
+ m_Name: PlaySound
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -1085,15 +1085,27 @@ MonoBehaviour:
- m_Target: {fileID: 2093584670}
m_TargetAssemblyTypeName: OCES.Audio.AudioSystem, Assembly-CSharp
m_MethodName: Play
- m_Mode: 5
+ m_Mode: 3
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
- m_IntArgument: 11
+ m_IntArgument: 57
m_FloatArgument: 0
m_StringArgument: rain
m_BoolArgument: 0
m_CallState: 2
+ - m_Target: {fileID: 2093584670}
+ m_TargetAssemblyTypeName: OCES.Audio.AudioSystem, Assembly-CSharp
+ m_MethodName: Play
+ m_Mode: 3
+ m_Arguments:
+ m_ObjectArgument: {fileID: 0}
+ m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
+ m_IntArgument: 58
+ m_FloatArgument: 0
+ m_StringArgument:
+ m_BoolArgument: 0
+ m_CallState: 2
--- !u!114 &1394234350
MonoBehaviour:
m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/OCES/Audio/Generated/AudioObject.cs b/Assets/Scripts/OCES/Audio/Generated/AudioObject.cs
index ad2dd9a..50683c3 100644
--- a/Assets/Scripts/OCES/Audio/Generated/AudioObject.cs
+++ b/Assets/Scripts/OCES/Audio/Generated/AudioObject.cs
@@ -130,6 +130,11 @@ public partial class AudioObject : IBinarySerializable
///
public bool RandomType { get; set; }
+ ///
+ /// Volume Step阈值 ms
+ ///
+ public uint VolumeStepThreshold { get; set; }
+
///
/// 起始音量
/// dB
@@ -178,6 +183,7 @@ public partial class AudioObject : IBinarySerializable
BlendCrossFadeType = (BlendCrossFadeType)reader.ReadByte();
LimitRepetition = reader.ReadByte();
RandomType = reader.ReadBoolean();
+ VolumeStepThreshold = reader.ReadUInt32();
Volume = reader.ReadInt32();
VolumeStep = reader.ReadInt32();
}
@@ -216,6 +222,7 @@ public partial class AudioObject : IBinarySerializable
writer.Write((byte)BlendCrossFadeType);
writer.Write(LimitRepetition);
writer.Write(RandomType);
+ writer.Write(VolumeStepThreshold);
writer.Write(Volume);
writer.Write(VolumeStep);
}
diff --git a/Assets/Scripts/OCES/Audio/Generated/AudioObjectDefinitions.cs b/Assets/Scripts/OCES/Audio/Generated/AudioObjectDefinitions.cs
index 262cf9c..e54a9e6 100644
--- a/Assets/Scripts/OCES/Audio/Generated/AudioObjectDefinitions.cs
+++ b/Assets/Scripts/OCES/Audio/Generated/AudioObjectDefinitions.cs
@@ -71,6 +71,8 @@ public static class AudioObjectDefinitions
{ "Grid", 54 },
{ "NVDice", 55 },
{ "NVHeartbeats", 56 },
+ { "au_sfx_notice_level_countDown_edge", 57 },
+ { "au_sfx_notice_level_countDown_time", 58 },
{ "sfx_amb_desert", 2000 },
{ "sfx_amb_forest", 2001 },
{ "sfx_anim_common_item_fly", 3000 },
diff --git a/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs b/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs
index d307afd..da454af 100644
--- a/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs
+++ b/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
+using OCES.Audio.HandWritten;
using UnityEngine;
using UnityEngine.Audio;
@@ -33,6 +34,7 @@ namespace OCES.Audio
AudioSourcePool m_pool;
AudioContainerSelector m_containerSelector;
PitchStepResolver m_pitchStepResolver;
+ VolumeStepResolver m_volumeStepResolver;
#if UNITY_EDITOR
void Update()
@@ -74,6 +76,7 @@ namespace OCES.Audio
this.m_pool = pool;
this.m_containerSelector = new AudioContainerSelector();
this.m_pitchStepResolver = new PitchStepResolver();
+ this.m_volumeStepResolver = new VolumeStepResolver();
AudioMixerGroup[] sfx = Find("Master/Regular/SFX");
if (sfx.Length > 0) this.m_sfxGroup = sfx[0];
@@ -173,7 +176,8 @@ namespace OCES.Audio
// 执行播放
float pitch = this.m_pitchStepResolver.ResolvePitch(audioObject, now); //算一下用不用变调
- PlayNewSound(audioObject, pitch);
+ float volume = this.m_volumeStepResolver.ResolveVolume(audioObject, now);
+ PlayNewSound(audioObject, pitch, volume);
this.m_lastPlayTime[audioObject.Id] = now;
onPlay?.Invoke();
}
@@ -182,12 +186,13 @@ namespace OCES.Audio
// 播放逻辑
// ─────────────────────────────────────────────
- void PlayNewSound(AudioObject audioObject, float pitch)
+ void PlayNewSound(AudioObject audioObject, float pitch, float volume)
{
ActiveSound active = new()
{
AudioObject = audioObject,
Pitch = pitch,
+ Volume = volume,
State = ActiveSoundState.Pending,
StartTime = Time.realtimeSinceStartupAsDouble,
};
@@ -207,7 +212,7 @@ namespace OCES.Audio
///
/// 连续容器播放协程(Random / Sequence 持续模式)
///
- IEnumerator PlayContainerContinuous(AudioSource source, AudioObject audioObject, ActiveSound chainActive, int startIndex, float pitch)
+ IEnumerator PlayContainerContinuous(AudioSource source, AudioObject audioObject, ActiveSound chainActive, int startIndex)
{
bool isRandom = audioObject.ContainerType == ContainerType.Random;
@@ -229,7 +234,7 @@ namespace OCES.Audio
limitRepetition);
// 配置并播放
- if (!SetupSource(source, audioObject, pitch, index))
+ if (!SetupSource(source, chainActive, index))
{
Debug.LogError($"音频文件未找到:{audioObject.Name[index]}");
yield break;
@@ -334,8 +339,9 @@ namespace OCES.Audio
return this.m_sfxGroup;
}
- bool SetupSource(AudioSource source, AudioObject audioObject, float pitch, int clipIndex = 0)
+ bool SetupSource(AudioSource source, ActiveSound activeSound, int clipIndex = 0)
{
+ AudioObject audioObject = activeSound.AudioObject;
AudioClip clip = Resources.Load($"Audios/{audioObject.Name[clipIndex]}"); // TODO 抽象同一资源加载接口
if (!clip)
{
@@ -347,7 +353,8 @@ namespace OCES.Audio
source.loop = audioObject.LoopCount < 0;
source.priority = audioObject.Priority;
source.outputAudioMixerGroup = GetMixerGroup(audioObject.MixingType);
- source.pitch = pitch;
+ source.pitch = activeSound.Pitch;
+ source.volume = activeSound.Volume;
return true;
}
@@ -371,6 +378,7 @@ namespace OCES.Audio
{
AudioObject audioObject = active.AudioObject;
float pitch = active.Pitch;
+ float volume = active.Volume;
// =======================
// Blend(每个clip一个ActiveSound)
@@ -385,10 +393,11 @@ namespace OCES.Audio
{
AudioObject = audioObject,
Pitch = pitch,
- State = ActiveSoundState.Playing
+ Volume = volume,
+ State = ActiveSoundState.Playing,
};
- if (!SetupSource(source, audioObject, pitch, i))
+ if (!SetupSource(source, child, i))
{
this.m_pool.ReturnToPool(source.gameObject);
continue;
@@ -424,7 +433,7 @@ namespace OCES.Audio
int start = audioObject.ContainerType == ContainerType.Random ? -1 : 0;
active.Coroutine = StartCoroutine(
- PlayContainerContinuous(sourceSingle, audioObject, active, start, pitch)
+ PlayContainerContinuous(sourceSingle, audioObject, active, start)
);
return;
@@ -440,9 +449,9 @@ namespace OCES.Audio
_ => 0
};
- if (!SetupSource(sourceSingle, audioObject, pitch, index))
+ if (!SetupSource(sourceSingle, active, index))
{
- m_pool.ReturnToPool(sourceSingle.gameObject);
+ this.m_pool.ReturnToPool(sourceSingle.gameObject);
return;
}
@@ -506,6 +515,7 @@ namespace OCES.Audio
public int CurrentLoopCount;
public Coroutine Coroutine;
public float Pitch;
+ public float Volume;
public ActiveSoundState State;
}
}
\ No newline at end of file
diff --git a/Assets/Scripts/OCES/Audio/HandWritten/VolumeStepResolver.cs b/Assets/Scripts/OCES/Audio/HandWritten/VolumeStepResolver.cs
new file mode 100644
index 0000000..ae5e8ad
--- /dev/null
+++ b/Assets/Scripts/OCES/Audio/HandWritten/VolumeStepResolver.cs
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace OCES.Audio.HandWritten
+{
+ public class VolumeStepResolver
+ {
+ readonly Dictionary m_volumeStepCounts = new();
+ readonly Dictionary m_volumeStepLastTime = new();
+
+ internal float ResolveVolume(AudioObject audioObject, double time)
+ {
+ // 计算一下配置的音量是多少
+ float baseVolume = Mathf.Pow(10,audioObject.Volume / 20f);
+
+ // 优化版。看看表现,要是确实Mathf.Pow造成性能卡点了就用这个。
+ //float baseVolume = audioObject.Volume == 0 ? 1f : Mathf.Pow(10,audioObject.Volume / 20f);
+
+ if (audioObject.VolumeStepThreshold == 0) //没配置VolumeStep
+ {
+ return baseVolume;
+ }
+
+ // 超时了,或者没播过
+ if (!this.m_volumeStepLastTime.TryGetValue(audioObject.Id, out double lastVolumeStepTime)
+ || time - lastVolumeStepTime > audioObject.VolumeStepThreshold)
+ {
+ this.m_volumeStepCounts[audioObject.Id] = 0;
+ this.m_volumeStepLastTime[audioObject.Id] = time;
+ return baseVolume;
+ }
+
+ //命中了
+ int volumeStepCount = this.m_volumeStepCounts[audioObject.Id];
+ volumeStepCount = this.m_volumeStepCounts[audioObject.Id] = volumeStepCount + 1;
+ this.m_volumeStepLastTime[audioObject.Id] = time;
+ return Mathf.Clamp(Mathf.Pow(10, (audioObject.Volume + audioObject.VolumeStep * volumeStepCount) / 20f), 0f, 1f);
+ }
+ }
+}
diff --git a/Assets/Scripts/OCES/Audio/HandWritten/VolumeStepResolver.cs.meta b/Assets/Scripts/OCES/Audio/HandWritten/VolumeStepResolver.cs.meta
new file mode 100644
index 0000000..008cac7
--- /dev/null
+++ b/Assets/Scripts/OCES/Audio/HandWritten/VolumeStepResolver.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0059d6fc851c474a97bc05f6385f9a48
+timeCreated: 1776067889
\ No newline at end of file