35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
[CreateAssetMenu(fileName = "NoteAudioCollection", menuName = "Ichni/Note/NoteAudioCollection")]
|
|
public class NoteAudioCollection : SerializedScriptableObject
|
|
{
|
|
public Dictionary<string, AudioClip> audioClips = new Dictionary<string, AudioClip>();
|
|
}
|
|
|
|
public static class AudioExtension
|
|
{
|
|
/// <summary>
|
|
/// 在全局(不受位置影响)播放一段 AudioClip。
|
|
/// </summary>
|
|
public static void PlayClipAtPoint2D(AudioClip clip, float volume = 1f)
|
|
{
|
|
// 新建一个临时的 GameObject
|
|
GameObject go = new GameObject("TempAudio2D");
|
|
var src = go.AddComponent<AudioSource>();
|
|
src.outputAudioMixerGroup = null; //EditorManager.instance.audioManager.noteSoundFXGroup;
|
|
src.clip = clip;
|
|
src.volume = volume;
|
|
src.spatialBlend = 0f; // 0 = 完全 2D
|
|
src.playOnAwake = false;
|
|
src.Play();
|
|
// 自动销毁,避免内存泄漏
|
|
Object.Destroy(go, clip.length + 0.1f);
|
|
}
|
|
}
|
|
}
|