feat: 解耦音频与触感系统
This commit is contained in:
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OCES.Haptic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
@@ -33,6 +32,7 @@ namespace OCES.Audio
|
||||
AudioContainerSelector m_containerSelector;
|
||||
PitchStepResolver m_pitchStepResolver;
|
||||
VolumeStepResolver m_volumeStepResolver;
|
||||
internal Action<ActiveSound> OnSoundStarted, OnSoundStopped;
|
||||
|
||||
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
void Update()
|
||||
@@ -435,14 +435,7 @@ namespace OCES.Audio
|
||||
IncrementClipCount(activeSound.AudioObject.Id);
|
||||
}
|
||||
|
||||
if (activeSound.AudioObject.ContainerType == ContainerType.Blend && activeSound.AudioObject.Haptic > 0)
|
||||
{
|
||||
Debug.LogWarning($"[Haptic System] Blend container {activeSound.AudioObject.Id} should not have haptic feedback!");
|
||||
}
|
||||
else
|
||||
{
|
||||
TryStartHaptic(activeSound);
|
||||
}
|
||||
this.OnSoundStarted?.Invoke(activeSound);
|
||||
|
||||
activeSound.Coroutine = StartCoroutine(RemoveWhenFinished(activeSound));
|
||||
}
|
||||
@@ -565,6 +558,7 @@ namespace OCES.Audio
|
||||
{
|
||||
StopCoroutine(active.Coroutine);
|
||||
//Debug.Log($"[StopSound] 协程已终止: {active.AudioObject.Name[0]}");
|
||||
this.OnSoundStopped?.Invoke(active);
|
||||
}
|
||||
|
||||
if(active.Source) active.Source.Stop();
|
||||
@@ -572,18 +566,6 @@ namespace OCES.Audio
|
||||
this.m_activeSounds.Remove(active);
|
||||
this.m_pool.ReturnToPool(active.Source.gameObject);
|
||||
}
|
||||
|
||||
static void TryStartHaptic(ActiveSound active)
|
||||
{
|
||||
uint hapticId = active.AudioObject.Haptic;
|
||||
if (hapticId == 0) return;
|
||||
HapticSystem.Instance.Play(hapticId, isDirectCall: false);
|
||||
}
|
||||
|
||||
static void TryStopHaptic(uint hapticId)
|
||||
{
|
||||
HapticSystem.Instance.Stop(hapticId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user