Initial commit

This commit is contained in:
Ardella Malinda Sarastri
2025-07-10 17:06:42 +07:00
commit 72b8b42a0b
8149 changed files with 4223394 additions and 0 deletions

View File

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public static AudioManager Instance;
public Sound[] musicSounds, sfxSounds;
public AudioSource musicSource, sfxSource;
private Dictionary<string, Sound> musicDictionary = new Dictionary<string, Sound>();
private Dictionary<string, Sound> sfxDictionary = new Dictionary<string, Sound>();
void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
Setup();
}
else
{
if (Instance != this)
{
Destroy(gameObject);
}
}
}
private void Setup()
{
for (int i = 0; i < musicSounds.Length; i++)
{
musicDictionary[musicSounds[i].name] = musicSounds[i];
}
for (int i = 0; i < sfxSounds.Length; i++)
{
sfxDictionary[sfxSounds[i].name] = sfxSounds[i];
}
}
public void StopMusic()
{
musicSource.Stop();
}
public void PlayMusic(SoundName name)
{
Sound s = Array.Find(musicSounds, sound => sound.soundName == name);
if (s != null)
{
musicSource.clip = s.clip;
musicSource.Play();
}
}
public void PlayMusic(string name)
{
Sound s = musicDictionary[name];
if (s != null)
{
musicSource.clip = s.clip;
musicSource.Play();
}
}
public void PlaySfx(string name)
{
Sound s = sfxDictionary[name];
if (s != null)
{
sfxSource.PlayOneShot(s.clip);
}
}
public void PlaySfx(AudioClip clip)
{
sfxSource.PlayOneShot(clip);
}
public void PlaySfx(SoundName name)
{
Sound s = Array.Find(sfxSounds, sound => sound.soundName == name);
if (s != null)
{
sfxSource.PlayOneShot(s.clip);
}
}
public void PlaySfx(Sound sound)
{
if (sound != null)
{
sfxSource.PlayOneShot(sound.clip);
}
}
public void PlaySfx(Sound[] randomSound)
{
if (randomSound != null)
{
sfxSource.PlayOneShot(randomSound[UnityEngine.Random.Range(0, randomSound.Length)].clip);
}
}
public void PlaySfx(SoundName[] randomName)
{
SoundName name = randomName[UnityEngine.Random.Range(0, randomName.Length)];
Sound s = Array.Find(sfxSounds, sound => sound.soundName == name);
if (s != null)
{
sfxSource.PlayOneShot(s.clip);
}
}
public void SetSfxVolume(float volume)
{
sfxSource.volume = volume;
}
public void SetMusicVolume(float volume)
{
musicSource.volume = volume;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f5ac05904ff5ab4882b8026e7f21813
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using UnityEngine;
[System.Serializable]
public class Sound
{
public string name;
public SoundName soundName;
public AudioClip clip;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 273e91268ea03254f9cde0aa8362ab44
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
using UnityEngine;
[System.Serializable]
public class SoundList
{
[SerializeField] private Sound[] soundList;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0ad2eabaf4aefc409fddc2622504ce3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,6 @@
public enum SoundName
{
GameMusic, MainMenuMusic
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 687137de75e342b4792ac6fdb52a4321
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: