Merge pull request #62 from Degulleo/DO-59-사운드-제어
Do-59 [Fix] 오디오파일을 리소스 폴더에서 코드로 로드, 코인 구입 시 한번에 증가
This commit is contained in:
commit
3a1a5ed77f
8
Assets/Resources/Sounds.meta
Normal file
8
Assets/Resources/Sounds.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fc9c29bf8c5aa040aaeace773096d1b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,21 +1,12 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
[Header("BGM")]
|
||||
[SerializeField] private AudioClip mainBgm;
|
||||
[SerializeField] private AudioClip gameBgm;
|
||||
[Header("SFX")]
|
||||
[SerializeField] private AudioClip clickSound;
|
||||
[SerializeField] private AudioClip closeSound;
|
||||
[SerializeField] private AudioClip coinsAddSound;
|
||||
[SerializeField] private AudioClip coinsEmptySound;
|
||||
[SerializeField] private AudioClip coinsRemoveSound;
|
||||
[SerializeField] private AudioClip winSound;
|
||||
[SerializeField] private AudioClip loseSound;
|
||||
[SerializeField] private AudioClip stoneSound;
|
||||
private AudioClip mainBgm;
|
||||
private AudioClip gameBgm;
|
||||
|
||||
[HideInInspector] public AudioSource bgmAudioSource; // BGM을 위한 AudioSource
|
||||
private AudioSource sfxAudioSource; // SFX를 위한 AudioSource
|
||||
@ -25,6 +16,9 @@ public class AudioManager : Singleton<AudioManager>
|
||||
[HideInInspector]public bool isPlayBGM;
|
||||
[HideInInspector]public bool isPlaySFX;
|
||||
|
||||
private Dictionary<string, AudioClip> audioClips = new Dictionary<string, AudioClip>();
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
base.Awake(); // 부모 클래스의 Awake 호출
|
||||
@ -32,6 +26,30 @@ public class AudioManager : Singleton<AudioManager>
|
||||
// BGM과 SFX를 위한 별도의 AudioSource 생성
|
||||
bgmAudioSource = gameObject.AddComponent<AudioSource>();
|
||||
sfxAudioSource = gameObject.AddComponent<AudioSource>();
|
||||
|
||||
//Sounds폴더 내의 모든 오디오클립 로드
|
||||
AudioClip[] clips = Resources.LoadAll<AudioClip>("Sounds");
|
||||
|
||||
foreach (AudioClip clip in clips)
|
||||
{
|
||||
audioClips[clip.name] = clip;
|
||||
}
|
||||
|
||||
Debug.Log($"총 {audioClips.Count}개의 오디오클립이 로드됨.");
|
||||
|
||||
}
|
||||
|
||||
public AudioClip GetAudioClip(string clipName)
|
||||
{
|
||||
if (audioClips.TryGetValue(clipName, out AudioClip clip))
|
||||
{
|
||||
return clip;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"패널 '{clipName}'을 찾을 수 없습니다.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 시작 시 BGM을 자동으로 재생
|
||||
@ -39,12 +57,15 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
isPlayBGM = UserManager.IsPlayBGM;
|
||||
isPlaySFX = UserManager.IsPlaySFX;
|
||||
|
||||
PlayBGM();
|
||||
}
|
||||
|
||||
// 메인 BGM을 재생하는 함수
|
||||
public void PlayMainBGM()
|
||||
{
|
||||
mainBgm = GetAudioClip("main bgm");
|
||||
|
||||
if (bgmAudioSource != null && mainBgm != null && !bgmAudioSource.isPlaying)
|
||||
{
|
||||
bgmAudioSource.clip = mainBgm;
|
||||
@ -56,6 +77,8 @@ public class AudioManager : Singleton<AudioManager>
|
||||
|
||||
public void PlayGameBGM()
|
||||
{
|
||||
gameBgm = GetAudioClip("Game bgm2");
|
||||
|
||||
if (bgmAudioSource != null && gameBgm != null && !bgmAudioSource.isPlaying)
|
||||
{
|
||||
bgmAudioSource.clip = gameBgm;
|
||||
@ -101,10 +124,9 @@ public class AudioManager : Singleton<AudioManager>
|
||||
// 클릭 사운드(SFX) 재생
|
||||
public void PlayClickSound()
|
||||
{
|
||||
|
||||
if (isPlaySFX && sfxAudioSource != null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(clickSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("Click Sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +135,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource != null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(closeSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("Close Sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +143,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource!=null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(coinsAddSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("Coins ADD Sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +151,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource!=null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(coinsEmptySound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("Coins Empty Sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +159,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource!=null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(coinsRemoveSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("Coins Remove Sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +167,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource!=null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(loseSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("lose sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,7 +175,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource!=null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(winSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("win sound"), sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +183,7 @@ public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
if (isPlaySFX && sfxAudioSource!=null)
|
||||
{
|
||||
sfxAudioSource.PlayOneShot(stoneSound, sfxVolume);
|
||||
sfxAudioSource.PlayOneShot(GetAudioClip("stone sound3"), sfxVolume);
|
||||
}
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ public class CoinsPanelController : MonoBehaviour
|
||||
_coinsRect.sizeDelta = new Vector2(100 + textLength * 30f, 100f);
|
||||
}
|
||||
|
||||
private void ChangeTextAnimation(bool isAdd, Action action)
|
||||
private void ChangeTextAnimation(int coinAdd, bool isAdd, Action action)
|
||||
{
|
||||
float duration = 0.2f;
|
||||
float yPos = 40f;
|
||||
@ -64,8 +64,8 @@ public class CoinsPanelController : MonoBehaviour
|
||||
if (isAdd)
|
||||
{
|
||||
var currentHeartCount = coinsCountText.text;
|
||||
coinsCountText.text = (int.Parse(currentHeartCount) + 500).ToString();
|
||||
// 코인 텍스트 100씩 증가
|
||||
coinsCountText.text = (int.Parse(currentHeartCount) + coinAdd).ToString();
|
||||
// 코인 텍스트 증가
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -98,22 +98,19 @@ public class CoinsPanelController : MonoBehaviour
|
||||
_canvasGroup.blocksRaycasts = false; //코인 중복 추가 방지 코드
|
||||
|
||||
Sequence sequence = DOTween.Sequence();
|
||||
// i += a 반복 횟수 조절, 100개 단위로 상승 차감 시 100으로 설정
|
||||
for (int i = 0; i < coinsCount; i+=500)
|
||||
sequence.AppendCallback(() =>
|
||||
{
|
||||
sequence.AppendCallback(() =>
|
||||
ChangeTextAnimation(coinsCount,true, ()=>
|
||||
{
|
||||
ChangeTextAnimation(true, ()=>
|
||||
{
|
||||
_coinsCount += 500;
|
||||
action?.Invoke();
|
||||
});
|
||||
|
||||
// 효과음 재생
|
||||
AudioManager.Instance.PlayCoinsAddSound();
|
||||
_coinsCount += coinsCount;
|
||||
action?.Invoke();
|
||||
});
|
||||
sequence.AppendInterval(0.5f);
|
||||
}
|
||||
|
||||
// 효과음 재생
|
||||
AudioManager.Instance.PlayCoinsAddSound();
|
||||
});
|
||||
sequence.AppendInterval(0.5f);
|
||||
|
||||
sequence.OnComplete(() =>
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = true; //구매 후 클릭 활성화
|
||||
@ -152,7 +149,7 @@ public class CoinsPanelController : MonoBehaviour
|
||||
|
||||
coinsRemoveImageObject.transform.DOScale(3f, 1f);
|
||||
coinsRemoveImageObject.GetComponent<Image>().DOFade(0f, 1f)
|
||||
.OnComplete( ()=>ChangeTextAnimation(false, ()=>
|
||||
.OnComplete( ()=>ChangeTextAnimation(0,false, ()=>
|
||||
{
|
||||
//감소된 코인 적용
|
||||
_coinsCount -= 100;
|
||||
|
@ -262,7 +262,7 @@ public class PanelManager : MonoBehaviour
|
||||
shopItems.Add(shopItem);
|
||||
}
|
||||
}
|
||||
GameManager.Instance.panelManager.OpenShopPanel(shopItems);
|
||||
OpenShopPanel(shopItems);
|
||||
}
|
||||
|
||||
//승급 패널 생성
|
||||
|
Loading…
x
Reference in New Issue
Block a user