diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity
index 6cd4bf6..7577141 100644
--- a/Assets/Scenes/SampleScene.unity
+++ b/Assets/Scenes/SampleScene.unity
@@ -271,7 +271,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
- m_Text: Disable Lowpass
+ m_Text: Reset Pitch
--- !u!222 &351150078
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -967,9 +967,9 @@ GameObject:
- component: {fileID: 876276286}
- component: {fileID: 876276285}
- component: {fileID: 876276284}
- - component: {fileID: 876276283}
+ - component: {fileID: 876276287}
m_Layer: 5
- m_Name: LowpassEnable
+ m_Name: TestButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -995,21 +995,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
---- !u!114 &876276283
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 876276281}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: 2ce47fe7df364a8fa37501256e5b5155, type: 3}
- m_Name:
- m_EditorClassIdentifier:
- targetGameState: 0
- enableLowpass: 1
- buttonText: {fileID: 1985546676}
--- !u!114 &876276284
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1054,14 +1039,14 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- - m_Target: {fileID: 2093584670}
- m_TargetAssemblyTypeName: OCES.Audio.AudioSystem, Assembly-CSharp
- m_MethodName: Play
- m_Mode: 3
+ - m_Target: {fileID: 876276287}
+ m_TargetAssemblyTypeName: SetPropertyBind, Assembly-CSharp
+ m_MethodName: SetPitch
+ m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
- m_IntArgument: 11
+ m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
@@ -1104,6 +1089,20 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 876276281}
m_CullTransparentMesh: 1
+--- !u!114 &876276287
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 876276281}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 5820ebe13451f4706bb41024f117f10b, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ inputField: {fileID: 1490886059}
+ targetValue: 0
--- !u!1 &1013617498
GameObject:
m_ObjectHideFlags: 0
@@ -2559,7 +2558,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
- m_Text: Enable Lowpass
+ m_Text: Set Pitch
--- !u!222 &1985546677
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -2672,9 +2671,9 @@ GameObject:
- component: {fileID: 1989157237}
- component: {fileID: 1989157236}
- component: {fileID: 1989157235}
- - component: {fileID: 1989157234}
+ - component: {fileID: 1989157238}
m_Layer: 5
- m_Name: LowpassDisable
+ m_Name: TestButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -2700,21 +2699,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
---- !u!114 &1989157234
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1989157232}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: 2ce47fe7df364a8fa37501256e5b5155, type: 3}
- m_Name:
- m_EditorClassIdentifier:
- targetGameState: 0
- enableLowpass: 0
- buttonText: {fileID: 351150077}
--- !u!114 &1989157235
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -2758,7 +2742,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1989157236}
m_OnClick:
m_PersistentCalls:
- m_Calls: []
+ m_Calls:
+ - m_Target: {fileID: 1989157238}
+ m_TargetAssemblyTypeName: SetPropertyBind, Assembly-CSharp
+ m_MethodName: ResetPitch
+ m_Mode: 1
+ m_Arguments:
+ m_ObjectArgument: {fileID: 0}
+ m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
+ m_IntArgument: 0
+ m_FloatArgument: 0
+ m_StringArgument:
+ m_BoolArgument: 0
+ m_CallState: 2
--- !u!114 &1989157236
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -2797,6 +2793,20 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1989157232}
m_CullTransparentMesh: 1
+--- !u!114 &1989157238
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1989157232}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 5820ebe13451f4706bb41024f117f10b, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ inputField: {fileID: 1490886059}
+ targetValue: 0
--- !u!1 &2093584669
GameObject:
m_ObjectHideFlags: 0
@@ -2827,7 +2837,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5ce1f814dd5d46d48bc33c18ba11c44c, type: 3}
m_Name:
m_EditorClassIdentifier:
- startWithMusic: 1
+ startWithMusic: 0
logLevel: 0
--- !u!4 &2093584671
Transform:
diff --git a/Assets/Scripts/OCES/Audio/HandWritten/AudioSystem.cs b/Assets/Scripts/OCES/Audio/HandWritten/AudioSystem.cs
index 0439268..6981d33 100644
--- a/Assets/Scripts/OCES/Audio/HandWritten/AudioSystem.cs
+++ b/Assets/Scripts/OCES/Audio/HandWritten/AudioSystem.cs
@@ -179,6 +179,92 @@ namespace OCES.Audio
this.m_sfxSystem.Stop(audioId);
}
+ ///
+ /// 设置指定音频ID的音量
+ ///
+ /// 音频ID
+ /// 目标音量 (0.0 - 1.0)
+ public void SetVolume(uint audioId, float targetVolume)
+ {
+ if (targetVolume is < 0 or > 1)
+ {
+ Debug.LogWarning($"[AudioSystem] Volume '{targetVolume}' is out of range [0, 1].");
+ return;
+ }
+ this.m_sfxSystem.SetVolume(audioId, targetVolume);
+ }
+
+ ///
+ /// 设置指定音频ID的音量
+ ///
+ /// 音频ID
+ /// 目标音量 (0.0 - 1.0)
+ public void SetVolume(int audioId, float targetVolume)
+ {
+ SetVolume((uint)audioId, targetVolume);
+ }
+
+ ///
+ /// 设置指定音频ID的音高
+ ///
+ /// 音频ID
+ /// 目标音高 (通常 1.0 为正常音高, -3 ~ 3)
+ public void SetPitch(uint audioId, float targetPitch)
+ {
+ if (targetPitch is < -3 or > 3)
+ {
+ Debug.LogWarning($"[AudioSystem] Pitch '{targetPitch}' is out of range [-3, 3].");
+ return;
+ }
+ this.m_sfxSystem.SetPitch(audioId, targetPitch);
+ }
+
+ ///
+ /// 设置指定音频ID的音高
+ ///
+ /// 音频ID
+ /// 目标音高 (通常 1.0 为正常音高)
+ public void SetPitch(int audioId, float targetPitch)
+ {
+ SetPitch((uint)audioId, targetPitch);
+ }
+
+ ///
+ /// 重置指定音频ID的音量为默认值
+ ///
+ /// 音频ID
+ public void ResetVolume(uint audioId)
+ {
+ this.m_sfxSystem.ResetVolume(audioId);
+ }
+
+ ///
+ /// 重置指定音频ID的音量为默认值
+ ///
+ /// 音频ID
+ public void ResetVolume(int audioId)
+ {
+ ResetVolume((uint)audioId);
+ }
+
+ ///
+ /// 重置指定音频ID的音高为默认值
+ ///
+ /// 音频ID
+ public void ResetPitch(uint audioId)
+ {
+ this.m_sfxSystem.ResetPitch(audioId);
+ }
+
+ ///
+ /// 重置指定音频ID的音高为默认值
+ ///
+ /// 音频ID
+ public void ResetPitch(int audioId)
+ {
+ ResetPitch((uint)audioId);
+ }
+
// ─────────────────────────────────────────────
// 初始化
// ─────────────────────────────────────────────
diff --git a/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs b/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs
index f5da89a..11c73bf 100644
--- a/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs
+++ b/Assets/Scripts/OCES/Audio/HandWritten/SfxSystem.cs
@@ -99,6 +99,62 @@ namespace OCES.Audio
}
}
+ internal void SetVolume(uint audioId, float targetVolume)
+ {
+ List targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
+ foreach (ActiveSound target in targets)
+ {
+ target.Volume = targetVolume;
+ if (target.Source)
+ {
+ target.Source.volume = targetVolume;
+ }
+ }
+ }
+
+ internal void SetPitch(uint audioId, float targetPitch)
+ {
+ List targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
+ foreach (ActiveSound target in targets)
+ {
+ target.Pitch = targetPitch;
+ if (target.Source)
+ {
+ target.Source.pitch = targetPitch;
+ }
+ }
+ }
+
+ internal void ResetVolume(uint audioId)
+ {
+ double now = Time.realtimeSinceStartupAsDouble * 1000.0;
+ List targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
+ foreach (ActiveSound target in targets)
+ {
+ float defaultVolume = this.m_volumeStepResolver.ResolveVolume(target.AudioObject, now);
+ target.Volume = defaultVolume;
+ if (target.Source)
+ {
+ target.Source.volume = defaultVolume;
+ }
+ }
+ }
+
+ internal void ResetPitch(uint audioId)
+ {
+ double now = Time.realtimeSinceStartupAsDouble * 1000.0;
+ List targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
+ foreach (ActiveSound target in targets)
+ {
+ float defaultPitch = this.m_pitchStepResolver.ResolvePitch(target.AudioObject, now);
+ target.Pitch = defaultPitch;
+ if (target.Source != null)
+ {
+ target.Source.pitch = defaultPitch;
+ }
+ }
+ }
+
// ─────────────────────────────────────────────
// 节流 & 调度入口
// ─────────────────────────────────────────────
diff --git a/Assets/Scripts/OCES/SetPropertyBind.cs b/Assets/Scripts/OCES/SetPropertyBind.cs
new file mode 100644
index 0000000..53a3c14
--- /dev/null
+++ b/Assets/Scripts/OCES/SetPropertyBind.cs
@@ -0,0 +1,36 @@
+using System.Collections;
+using System.Collections.Generic;
+using OCES.Audio;
+using UnityEngine;
+using UnityEngine.Serialization;
+using UnityEngine.UI;
+
+public class SetPropertyBind : MonoBehaviour
+{
+ public InputField inputField;
+ public float targetValue;
+
+ public void SetVolume()
+ {
+ uint.TryParse(this.inputField.text, out uint audioId);
+ AudioSystem.Instance.SetVolume(audioId, this.targetValue);
+ }
+
+ public void SetPitch()
+ {
+ uint.TryParse(this.inputField.text, out uint audioId);
+ AudioSystem.Instance.SetPitch(audioId, this.targetValue);
+ }
+
+ public void ResetVolume()
+ {
+ uint.TryParse(this.inputField.text, out uint audioId);
+ AudioSystem.Instance.ResetVolume(audioId);
+ }
+
+ public void ResetPitch()
+ {
+ uint.TryParse(this.inputField.text, out uint audioId);
+ AudioSystem.Instance.ResetPitch(audioId);
+ }
+}
diff --git a/Assets/Scripts/OCES/SetPropertyBind.cs.meta b/Assets/Scripts/OCES/SetPropertyBind.cs.meta
new file mode 100644
index 0000000..b43ffd8
--- /dev/null
+++ b/Assets/Scripts/OCES/SetPropertyBind.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5820ebe13451f4706bb41024f117f10b
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: