Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 70 additions & 70 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
{
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"**/.vs": true,
"**/.gitmodules": true,
"**/.vsconfig": true,
"**/*.booproj": true,
"**/*.pidb": true,
"**/*.suo": true,
"**/*.user": true,
"**/*.userprefs": true,
"**/*.unityproj": true,
"**/*.dll": true,
"**/*.exe": true,
"**/*.pdf": true,
"**/*.mid": true,
"**/*.midi": true,
"**/*.wav": true,
"**/*.gif": true,
"**/*.ico": true,
"**/*.jpg": true,
"**/*.jpeg": true,
"**/*.png": true,
"**/*.psd": true,
"**/*.tga": true,
"**/*.tif": true,
"**/*.tiff": true,
"**/*.3ds": true,
"**/*.3DS": true,
"**/*.fbx": true,
"**/*.FBX": true,
"**/*.lxo": true,
"**/*.LXO": true,
"**/*.ma": true,
"**/*.MA": true,
"**/*.obj": true,
"**/*.OBJ": true,
"**/*.asset": true,
"**/*.cubemap": true,
"**/*.flare": true,
"**/*.mat": true,
"**/*.meta": true,
"**/*.prefab": true,
"**/*.unity": true,
"build/": true,
"Build/": true,
"Library/": true,
"library/": true,
"obj/": true,
"Obj/": true,
"Logs/": true,
"logs/": true,
"ProjectSettings/": true,
"UserSettings/": true,
"temp/": true,
"Temp/": true
},
"files.associations": {
"*.asset": "yaml",
"*.meta": "yaml",
"*.prefab": "yaml",
"*.unity": "yaml"
},
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.sln": "*.csproj"
},
"dotnet.defaultSolution": "Framework.sln",
"git.ignoreLimitWarning": true
}
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"**/.vs": true,
"**/.gitmodules": true,
"**/.vsconfig": true,
"**/*.booproj": true,
"**/*.pidb": true,
"**/*.suo": true,
"**/*.user": true,
"**/*.userprefs": true,
"**/*.unityproj": true,
"**/*.dll": true,
"**/*.exe": true,
"**/*.pdf": true,
"**/*.mid": true,
"**/*.midi": true,
"**/*.wav": true,
"**/*.gif": true,
"**/*.ico": true,
"**/*.jpg": true,
"**/*.jpeg": true,
"**/*.png": true,
"**/*.psd": true,
"**/*.tga": true,
"**/*.tif": true,
"**/*.tiff": true,
"**/*.3ds": true,
"**/*.3DS": true,
"**/*.fbx": true,
"**/*.FBX": true,
"**/*.lxo": true,
"**/*.LXO": true,
"**/*.ma": true,
"**/*.MA": true,
"**/*.obj": true,
"**/*.OBJ": true,
"**/*.asset": true,
"**/*.cubemap": true,
"**/*.flare": true,
"**/*.mat": true,
"**/*.meta": true,
"**/*.prefab": true,
"**/*.unity": true,
"build/": true,
"Build/": true,
"Library/": true,
"library/": true,
"obj/": true,
"Obj/": true,
"Logs/": true,
"logs/": true,
"ProjectSettings/": true,
"UserSettings/": true,
"temp/": true,
"Temp/": true
},
"files.associations": {
"*.asset": "yaml",
"*.meta": "yaml",
"*.prefab": "yaml",
"*.unity": "yaml"
},
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.sln": "*.csproj"
},
"dotnet.defaultSolution": "Unity-Framework.sln",
"git.ignoreLimitWarning": true
}
2 changes: 1 addition & 1 deletion Assets/Framework/Sample/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ GameObject:
- component: {fileID: 365617369}
- component: {fileID: 365617368}
m_Layer: 0
m_Name: GameObject
m_Name: Bootstrap
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down
8 changes: 8 additions & 0 deletions Assets/Framework/Scripts/Utilities/Audio Manager.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions Assets/Framework/Scripts/Utilities/Audio Manager/AudioEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections.Generic;
using UnityEngine;

namespace Framework.Utilities.AudioManager
{
[CreateAssetMenu(fileName = "AudioCatalog", menuName = "Framework/Audio/Audio Catalog")]
public class AudioCatalogSO : ScriptableObject
{
public List<SoundEntry> entries = new();
public Dictionary<string, SoundEntry> entriesDict = new();

// NOTE: 在编辑器中保持同步,以及统计数量一样不代表内容一致
private void EnsureMap()
{
if (entries.Count != entriesDict.Count)
{
entriesDict.Clear();
foreach (var e in entries)
{
if (!entriesDict.ContainsKey(e.id))
{
entriesDict.Add(e.id, e);
}
}
}
}

public SoundEntry GetSoundEntry(string id)
{
EnsureMap();
return entriesDict.TryGetValue(id, out var entry) ? entry : null;
}

public AudioClip GetAudioClip(string id)
{
EnsureMap();
return entriesDict.TryGetValue(id, out var entry) ? entry.clip : null;
}

#if UNITY_EDITOR
public void EditorRebuild()
{
entriesDict.Clear();
EnsureMap();
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}

[System.Serializable]
public class SoundEntry
{
public string id;
public AudioClip clip;
[Range(0f, 1f)] public float defaultVolume = 1f;
[Range(0.5f, 2f)] public float defaultPitch = 1f;
public bool spatial = false;
public bool loop = false;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Assets/Framework/Scripts/Utilities/Audio Manager/AudioHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using UnityEngine;
using System;

namespace Framework.Utilities.AudioManager
{
public class AudioHandle
{
AudioSource _src;
Action<AudioSource> _release;

internal AudioHandle(AudioSource src, Action<AudioSource> release)
{
_src = src;
_release = release;
}

public bool IsPlaying => _src != null && _src.isPlaying;

// 关闭音效,并且调用回调函数
public void Stop()
{
if (_src == null) return;
_src.Stop();
_release?.Invoke(_src);
_src = null;
_release = null;
}

// Internal: used by manager to return when finished
internal void ReturnIfFinished()
{
if (_src == null) return;
if (!_src.isPlaying)
{
_release?.Invoke(_src);
_src = null;
_release = null;
}
}
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading