몬스터 스포너 테스트코드 구현

1. 몬스터 상태 Hit, Death 추가
2. 몬스터 스킬 정리
This commit is contained in:
Mingu Kim
2025-02-20 05:21:58 +09:00
parent 5f7428db4c
commit a27bb7d6d1
14 changed files with 926 additions and 709 deletions

View File

@@ -1,22 +1,13 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using Assets.PixelFantasy.PixelMonsters.Common.Scripts;
using Unity.VisualScripting;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using DamageCalculator = TON.DamageCalculator;
using Vector2 = UnityEngine.Vector2;
using Vector3 = UnityEngine.Vector3;
namespace TON
{
public class MonsterBase : MonoBehaviour, IDamage
public partial class MonsterBase : MonoBehaviour, IDamage
{
[SerializeField]
public int id; // 몬스터의 ID
public float defencePower;
@@ -30,15 +21,16 @@ namespace TON
StateMachine _stateMachine;
private AttackPattern _attackPattern;
private SkillPattern _skillPattern;
// [SerializeField] private TextMeshProUGUI _textState;
private Vector3 _direction; // 몬스터의 이동 방향
public bool IsDetect { get; set; } // 몬스터가 대상을 인식했는지 여부
public bool IsAttacking { get; set; } // 몬스터가 공격했는지 여부
public bool IsFisnishAttack { get; set; } // 몬스터 공격 모션이 끝났는지 여부
public bool IsHit { get; set; } // 몬스터 공격 모션이 끝났는지 여부
public bool IsDead { get; set; } // 몬스터 공격 모션이 끝났는지 여부
public bool IsSkillAttackable => _skillPattern.IsAttackable;
[SerializeField] private GameObject _target; // 몬스터의 타겟
[SerializeField] private Collider2D _collider; // 몬스터의 콜라이더
@@ -47,37 +39,23 @@ namespace TON
private string currentAnimationState; // 현재 애니메이션 상태
// hp바
[SerializeField] private Image _hpBarImage; // HP 바 이미지
public GameObject _hpBarImage; // HP 바 이미지
private float _maxHP;
private float currentHP;
// 몬스터 스킬 프리팹
public GameObject smallFirePrefab;
public GameObject DragonBreathPrefab;
public GameObject IceBlastPrefab;
public GameObject PumpkinCrashPrefab;
public GameObject TrollChargePrefab;
public GameObject TrollCrashPrefab;
public GameObject TrollThundePrefab;
public GameObject WolfEnergyWavePrefab;
public GameObject WolfPunchPrefab;
public GameObject DragonShockWavePrefab;
public GameObject FireImpactPrefab;
private float hpMaxWidth;
// 첫 번째 프레임 전에 호출됩니다.
private void Start()
{ // 전략 패턴
// TODO : 수정중
// _attackPattern = new Monster1AttackPattern();
// _attackPattern = new Monster2AttackPattern();
{
_animator = GetComponent<Animator>(); // 애니메이터 컴포넌트 초기화
// _stateMachine = new StateMachine(new IdleState(), this, _textState);
_stateMachine = new StateMachine(new IdleState(), this);
// 몬스터 데이터 로드 및 적용
InitializeMonsterData();
InitializeMonsterSkillData();
_skillPattern = new Monster1SkillPattern(_monsterData, this);
id = _monsterData.id;
@@ -86,6 +64,8 @@ namespace TON
_spriteRenderer.flipX = !(_direction.x > 0); // 이동 방향에 따라 스프라이트 플립
_collider = GetComponent<Collider2D>(); // 콜라이더 컴포넌트 초기화
// hpMaxWidth = _hpBarImage.GetComponent<RectTransform>().sizeDelta.x;
}
// TODO : 불러온 값 변수에 대응하게 수정
@@ -95,11 +75,9 @@ namespace TON
if (_monsterData != null)
{
_maxHP = _monsterData.hp;
currentHP = _maxHP;
currentHP = _monsterData.hp;
defencePower = _monsterData.defencePower;
Debug.Log($"몬스터 {_monsterData.name} 데이터 로드 완료");
}
else
@@ -108,29 +86,6 @@ namespace TON
}
}
// TODO : 불러온 값 변수에 대응하게 수정
private void InitializeMonsterSkillData()
{
_monsterSkillData = MonsterSkillDataManager.Singleton.GetMonsterSkillData(_monsterData.monsterSkillID);
if (_monsterData.monsterSkillIDTwo > -1)
{
_monsterSkillDataTwo = MonsterSkillDataManager.Singleton.GetMonsterSkillData(_monsterData.monsterSkillIDTwo);
}
if (_monsterSkillData != null && _monsterSkillDataTwo != null)
{
Debug.Log($"몬스터 {_monsterSkillData.skillName} 데이터 로드 완료");
Debug.Log($"몬스터 {_monsterSkillDataTwo.skillName} 데이터 로드 완료");
}
else
{
Debug.LogError($"몬스터 스킬 ID {_monsterSkillData.skillId}에 대한 데이터를 찾을 수 없습니다.");
Debug.LogError($"몬스터 스킬 ID {_monsterSkillDataTwo.skillId}에 대한 데이터를 찾을 수 없습니다.");
}
}
// 애니메이션 상태를 변경하는 메서드
public void ChangeAnimationState(string newState)
{
@@ -143,7 +98,7 @@ namespace TON
private void Update()
{
_stateMachine.Update();
_skillPattern.Update();
}
public void FinishAttack()
@@ -163,13 +118,11 @@ namespace TON
if (prevHP > 0 && currentHP <= 0)
{
// 몬스터가 죽었을 때 처리 (죽는 애니메이션은 주석 처리됨)
// Destroy(gameObject); // 몬스터 파괴
DestroyMonster();
_stateMachine.SetTransition(new DeathState());
}
else if (prevHP > 0 && currentHP > 0)
{
// 피격 애니메이션은 주석 처리됨 (필요시 활성화)
_stateMachine.SetTransition(new HitState());
}
}
@@ -178,9 +131,10 @@ namespace TON
{
if (_hpBarImage != null)
{
// 현재 체력 비율 계산 (0.0 ~ 1.0)
float hpRatio = currentHP / _maxHP;
_hpBarImage.fillAmount = hpRatio; // 이미지 크기를 체력 비율에 맞게 조절
float minHPBarWidth = 5f; // 최소 HP 바 길이 (원하는 값으로 설정)
float hpBarWidth = Mathf.Max(currentHP / _maxHP * hpMaxWidth, minHPBarWidth); // 최소 길이 적용
_hpBarImage.GetComponent<RectTransform>().sizeDelta = new Vector2(hpBarWidth, _hpBarImage.GetComponent<RectTransform>().sizeDelta.y);
}
}
@@ -231,25 +185,12 @@ namespace TON
public void MonsterSkillLaunch()
{
// _spriteRenderer.flipX = target.transform.position.x < transform.position.x;
// newSkill.transform.position = transform.position + new Vector3(0, 1f, 0);
// newSkill.GetComponent<MonsterSkill>().Direction = new Vector2(0, 1);
var target = GameObject.FindGameObjectWithTag("Player");
_spriteRenderer.flipX = target.transform.position.x < transform.position.x;
// TODO : 몬스터가 가지고 있는 스킬에 따라 분기되는 조건 추가
// GameObject newSkill = Instantiate(smallFirePrefab);
// GameObject newSkill = Instantiate(DragonBreathPrefab);
GameObject newSkill = Instantiate(IceBlastPrefab);
// GameObject newSkill = Instantiate(PumpkinCrashPrefab);
// GameObject newSkill = Instantiate(TrollChargePrefab);
// GameObject newSkill = Instantiate(TrollCrashPrefab);
// GameObject newSkill = Instantiate(TrollThundePrefab);
// GameObject newSkill = Instantiate(WolfEnergyWavePrefab);
// GameObject newSkill = Instantiate(WolfPunchPrefab);
// GameObject newSkill = Instantiate(DragonShockWavePrefab);
// GameObject newSkill = Instantiate(FireImpactPrefab);
newSkill.transform.position = transform.position + new Vector3(0, 1f, 0);
newSkill.GetComponent<MonsterSkill>().Direction = new Vector2(0, 1);
_skillPattern.Attack(target);
}
public void DestroyMonster()