효과음 겹치는 문제 수정을 위해 효과음 재생중일때 효과음이 재생되지 않도록 수정

This commit is contained in:
Mingu Kim
2025-06-28 01:09:22 +09:00
parent 02dbaae8d1
commit 8d0e2ee53e
5 changed files with 89 additions and 85 deletions

View File

@@ -19,8 +19,8 @@ namespace TON
static void PerformAndroidBuild()
{
string target_dir = APP_NAME + ".apk";
PlayerSettings.keystorePass = "dlrhahdla"; //키스토어 비번 입력
PlayerSettings.keyaliasPass = "dlrhahdla"; //키스토어 비번 입력
PlayerSettings.keystorePass = string.Empty; //키스토어 비번 입력
PlayerSettings.keyaliasPass = string.Empty; //키스토어 비번 입력
GenericBuild(SCENES, TARGET_DIR + "/" + target_dir, BuildTargetGroup.Android, BuildTarget.Android, BuildOptions.None);
}

View File

@@ -20047,6 +20047,7 @@ MonoBehaviour:
- {fileID: 1877559506}
- {fileID: 897622737}
currentWave: 0
isTimerRunning: 0
waveDataArray:
- monsterPrefabA: {fileID: 9096056522544909490, guid: 53f5c583c440aa546bde473536a2ead1, type: 3}
monsterPrefabB: {fileID: 5532926939721588456, guid: b4cf92d97c6e476458cfc19779d644d0, type: 3}
@@ -20162,7 +20163,7 @@ Transform:
m_GameObject: {fileID: 1185367601}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.72366333, y: -1.5159607, z: -10.076585}
m_LocalPosition: {x: -0.7237015, y: -1.5072632, z: -10.076585}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
@@ -34317,7 +34318,20 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 023ac119be3a3d24c816494653c341dc, type: 3}
m_Name:
m_EditorClassIdentifier:
bgmClip: {fileID: 0}
bgmVolume: 0.2
bgSound: {fileID: 2068238030}
sfxClips:
- {fileID: 8300000, guid: d9b6b98705872654fbd8cd2eb50566c4, type: 3}
- {fileID: 8300000, guid: 7b924592d5ae5b841b180929d40732b7, type: 3}
- {fileID: 8300000, guid: f48df33f7dda4a94aae097863d2e875d, type: 3}
- {fileID: 8300000, guid: d24e772b39f07ea42b380d53d542438f, type: 3}
- {fileID: 8300000, guid: 365990a793283564aa391eddb2dc2c76, type: 3}
- {fileID: 8300000, guid: 3aa1c6aa8a0b2c24487dde9a48e1d6da, type: 3}
- {fileID: 8300000, guid: d5e7610e90cfd054b9c1fc1fef110d91, type: 3}
- {fileID: 8300000, guid: daada6b5d9cf66744a5587c6ed246371, type: 3}
sfxVolume: 0.5
channels: 16
--- !u!4 &2068238029
Transform:
m_ObjectHideFlags: 0

View File

@@ -24,77 +24,4 @@ namespace TON
{
}
}
public class Monster1AttackPattern : AttackPattern
{
public Monster1AttackPattern(MonsterBase monsterBase) : base(monsterBase)
{
}
public override void Attack()
{
if (Time.time >= _lastSkillTime + _skill1Cooldown)
{
Skill1();
_lastSkillTime = Time.time;
}
else
{
MeleeAttack();
}
}
private void Skill1()
{
_monsterBase.MonsterSkillLaunch();
}
private void MeleeAttack()
{
_monsterBase.PlayerAttack();
}
}
public class Monster2AttackPattern : AttackPattern
{
private float _lastSkill2Time;
public Monster2AttackPattern(MonsterBase monsterBase) : base(monsterBase)
{
_lastSkill2Time = -_skill2Cooldown;
}
public override void Attack()
{
if (Time.time >= _lastSkillTime + _skill1Cooldown)
{
Skill1();
_lastSkillTime = Time.time;
}
else if (Time.time >= _lastSkill2Time + _skill2Cooldown)
{
Skill2();
_lastSkill2Time = Time.time;
}
else
{
MeleeAttack();
}
}
private void Skill1()
{
_monsterBase.MonsterSkillLaunch(1); // 스킬 1 발사
}
private void Skill2()
{
_monsterBase.MonsterSkillLaunch(2); // 스킬 2 발사
}
private void MeleeAttack()
{
_monsterBase.PlayerAttack();
}
}
}

View File

@@ -38,7 +38,7 @@ namespace TON
private CharacterBase _characterBase;
// public AudioClip _attackSound;
public AudioClip _attackSound;
public AudioClip _deathSound;
public AudioClip _hitSound;
@@ -135,7 +135,6 @@ namespace TON
if (prevHP > 0 && currentHP <= 0)
{
_stateMachine.SetTransition(new DeathState());
//TODO : 현재 웨이브 값, 경험치, 골드 MonsterSpawner.WaveData;
}
else if (prevHP > 0 && currentHP > 0)
{
@@ -167,7 +166,7 @@ namespace TON
}
}
public void Attack(GameObject player)
public void Attack(CharacterBase player)
{
// 데미지 계산 (현재 임시 값)
DamageCalculator damageCalculator = new DamageCalculator();
@@ -181,13 +180,17 @@ namespace TON
_characterBase.ApplyDamage(damage);
// SoundManager.instance.SFXPlay("Attack", _attackSound);
if (player != null)
{
SoundManager.instance.SFXPlay("Attack", _attackSound);
}
// Debug.Log($" 몬스터 공격! 최종 데미지: {damage}"); // 데미지 출력
}
public void PlayerAttack()
{
var target = GameObject.FindGameObjectWithTag("Player");
var target = GameObject.Find("TON.Player").GetComponentInChildren<CharacterBase>();
Attack(target);
}

View File

@@ -7,15 +7,26 @@ namespace TON
{
public class SoundManager : MonoBehaviour
{
public AudioSource bgSound;
[Header("#BGM")]
public AudioClip bgmClip;
public float bgmVolume;
AudioSource bgSound;
[Header("#SFX")]
public float sfxVolume;
AudioSource sfxSound;
public static SoundManager instance;
// 현재 재생 중인 SFX 클립과 해당 AudioSource를 저장할 Dictionary
private Dictionary<AudioClip, AudioSource> playingSfxMap = new Dictionary<AudioClip, AudioSource>();
private void Awake()
{
if (instance == null)
{
instance = this;
Init();
DontDestroyOnLoad(instance);
// 씬 로드 이벤트에 리스너 등록
SceneManager.sceneLoaded += OnSceneLoaded;
@@ -26,21 +37,70 @@ namespace TON
}
}
void Init()
{
// 배경음 플레이어 초기화
GameObject bgmObject = new GameObject("BGM");
bgmObject.transform.parent = transform;
bgSound = bgmObject.AddComponent<AudioSource>();
bgSound.playOnAwake = false;
bgSound.loop = true;
bgSound.volume = bgmVolume;
bgSound.clip = bgmClip;
// 호과음 플레이어 초기화
GameObject sfxObject = new GameObject("SFX");
sfxObject.transform.parent = transform;
sfxSound = sfxObject.AddComponent<AudioSource>();
sfxSound.playOnAwake = false;
sfxSound.volume = sfxVolume;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
// 씬이 바뀔 때마다 배경 음악 종료
BgSoundPlay(null);
foreach (var entry in playingSfxMap)
{
if (entry.Value != null && entry.Value.gameObject != null)
{
Destroy(entry.Value.gameObject);
}
}
playingSfxMap.Clear();
}
public void SFXPlay(string sfxName, AudioClip clip)
{
// 재생 중인지 확인
if (playingSfxMap.ContainsKey(clip) && playingSfxMap[clip].isPlaying)
{
Debug.Log($"SFX '{sfxName}' 재생중이므로 재생하지 않고 넘김.");
return; // 이미 재생 중이면 재생하지 않고 종료
}
GameObject go = new GameObject(sfxName + "Sound");
AudioSource audiosource = go.AddComponent<AudioSource>();
audiosource.clip = clip;
audiosource.volume = sfxVolume; // SFX 볼륨 적용
audiosource.Play();
Destroy(go, clip.length);
playingSfxMap[clip] = audiosource;
StartCoroutine(DestroyAndRemoveSFX(go, clip, clip.length));
}
private IEnumerator DestroyAndRemoveSFX(GameObject go, AudioClip clip, float delay)
{
yield return new WaitForSeconds(delay);
if (playingSfxMap.ContainsKey(clip) && playingSfxMap[clip] == go.GetComponent<AudioSource>())
{
playingSfxMap.Remove(clip);
}
Destroy(go);
}
public void BgSoundPlay(AudioClip clip)