2026-03-31 물체 상호작용

This commit is contained in:
2026-03-31 18:08:26 +09:00
parent 71dfbf1af2
commit 902b1b76fb
141 changed files with 11063 additions and 343 deletions

View File

@@ -1,6 +1,8 @@
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
using Unity.VisualScripting;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -13,22 +15,40 @@ public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
public void ItemUse(ItemInstance item)
{
Debug.Log("아이템 사용");
switch(item.Data.ItemEffectType)
{
case ItemEffectType.RECOVERY_HP:
{
Debug.Log("HP회복 작동!!");
//RecoveryHPHealthEffect(GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>(), item.Data.IntervalDamage, item.Data.IntervalDamageTime, item.Data.ItemEffectVisual);
Debug.Log($"전 HP : {GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>().CurrentHP}");
RecoveryHPHealthEffect(GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>(), item.Data.RecoveryHP, item.Data.ItemEffectVisual);
Debug.Log($"후 HP : {GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>().CurrentHP}");
}
break;
case ItemEffectType.INTERVAL_DAMAGE:
{
Debug.Log("틱데미지 아이템 타입임");
IntervalDamageHealthEffect(GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>(), item.Data.IntervalDamage, item.Data.IntervalDamageTime, item.Data.ItemEffectVisual);
}
break;
}
}
public void RecoveryHPHealthEffect(Health health,float recoveryHP,GameObject itemEffectVisual)
{
PlayerHealth playerHealth = health as PlayerHealth;
if (playerHealth != null)
{
GameObject fx_Visual = Instantiate(itemEffectVisual, playerHealth.transform); // health의 자식으로 이펙트 생성
fx_Visual.transform.localPosition = new Vector3(0, 1.5f, 0);
playerHealth.ChangeHP(Mathf.Clamp(playerHealth.CurrentHP + Mathf.FloorToInt(recoveryHP), 0, playerHealth.Pstat.MaxHp)); //소수점 전부 버림
}
}
public void IntervalDamageHealthEffect(Health health,float damage,float time,GameObject itemEffectVisual)
{
IntervalDamage(health, damage,time, itemEffectVisual);
@@ -37,17 +57,39 @@ public void IntervalDamageHealthEffect(Health health,float damage,float time,Gam
//일정 시간 동안 틱대미지 일으키는 함수
public async void IntervalDamage(Health health, float damage,float time, GameObject itemEffectVisual)
{
// 유니티 오브젝트 자체의 CancellationToken 가져오기 (오브젝트 파괴 시 자동 취소)
CancellationToken token = health.destroyCancellationToken;
GameObject fx_Visual = Instantiate(itemEffectVisual, health.transform); // health의 자식으로 이펙트 생성
fx_Visual.transform.localPosition = new Vector3(0, 1.5f, 0);
float tickDamage = damage / time;
while(time <=0)
Debug.Log($"damage: {damage}");
Debug.Log($"time: {time}");
Debug.Log($"tickDamage: {tickDamage}");
Debug.Log($"CurrentHP : {health.CurrentHP}");
try
{
health.ChangeHP(Mathf.FloorToInt(tickDamage)); //소수점 전부 버림
if (health.CurrentHP <= 0) break;
time--;
await Task.Yield();
while (time > 0)
{
Debug.Log($"진입");
health.ChangeHP(health.CurrentHP - Mathf.FloorToInt(tickDamage)); //소수점 전부 버림
if (health.CurrentHP <= 0) break;
time--;
Debug.Log($"중독 HP : {GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>().CurrentHP}");
await Task.Delay(1000, token);
}
}
catch (System.OperationCanceledException)
{
Debug.Log("데미지 루프가 취소됨");
}
finally
{
// 정상 종료되든, 취소되든(Exception) 이펙트는 확실히 제거
if (fx_Visual != null) Destroy(fx_Visual);
}
Destroy(fx_Visual);
}
}

View File

@@ -108,9 +108,14 @@ public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
InputManager.Instance.OnAimToggleEvent += CurrentCharacterController.AimToggleInput;
InputManager.Instance.OnLookEvent += CurrentCharacterController.LookInput;
InputManager.Instance.OnDodgeEvent += CurrentCharacterController.DodgeInput;
//공격매핑
//InputManager.Instance.OnNormalAttackEvent;
//InputManager.Instance.OnHeavyAttackEvent;
//기타매핑
InputManager.Instance.OnInteractionEvent += CurrentCharacterController.InteractInput;
//UI매핑
InputManager.Instance.OnKeyDown_IKeyEvent += GameManager.Instance.InGameUI.InventoryToggle;