2026-03-30 아이템 사용 진행중

This commit is contained in:
2026-03-30 18:01:09 +09:00
parent d833da5bfa
commit f8773fa168
33 changed files with 613 additions and 8 deletions

View File

@@ -6,11 +6,19 @@ public enum ItemType
CONSUMABLE = 1
}
public enum ItemEffectType
{
NONE = 0,
INTERVAL_DAMAGE = 1
}
[CreateAssetMenu(fileName = "New Item", menuName = "Item")]
public class Item : ScriptableObject
{
public string ItemId;
public ItemType ItemType;
public ItemEffectType ItemEffectType;
public GameObject ItemEffectVisual;
public int SortId;
public string ItemName;
public Sprite Icon; //인벤토리용 2D 아이콘
@@ -30,4 +38,9 @@ public class Item : ScriptableObject
[Header("Collider Settings")]
public Vector3 ColliderCenter = Vector3.zero;
public Vector3 ColliderSize = Vector3.one;
//ItemEffectType.INTERVAL_DAMAGE 일 경우
public float IntervalDamage;
public float IntervalDamageTime;
}

View File

@@ -16,6 +16,9 @@ public class GameManager : MonoBehaviour
public InGameUIManager InGameUI { get; private set; }
public InventoryManager Inventory { get; private set; }
//기타
public ItemEffectManager ItemEffect { get; private set; }
[Header("Item Dynamic Settings")]
public float ItemRotationSpeed = 50f; // 회전 속도
public float ItemBounceAmplitude = 0.1f; // 오르내리는 높이
@@ -44,9 +47,11 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
this.IntroUI = FindFirstObjectByType<IntroUIManager>();
this.InGameUI = FindFirstObjectByType<InGameUIManager>();
this.Inventory = FindFirstObjectByType<InventoryManager>();
this.ItemEffect = FindFirstObjectByType<ItemEffectManager>();
if (this.Level != null) this.Level.OnSceneLoaded(scene, mode);
if (this.Camera != null) this.Camera.OnSceneLoaded(scene, mode);
if (this.ItemEffect != null) this.ItemEffect.OnSceneLoaded(scene, mode);
InputManager.Instance.PlayerInputEnable(true);
GlobalUIManager.Instance.SetSceneLoadingActive(false);

View File

@@ -0,0 +1,43 @@
using System.Collections;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ItemEffectManager : MonoBehaviour
{
public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
}
public void ItemUse(ItemInstance item)
{
if(item.Data.ItemEffectType == ItemEffectType.INTERVAL_DAMAGE)
{
IntervalDamageHealthEffect(GameManager.Instance.Level.CurrentCharacter.GetComponent<Health>(), item.Data.IntervalDamage, item.Data.IntervalDamageTime, item.Data.ItemEffectVisual);
}
}
public void IntervalDamageHealthEffect(Health health,float damage,float time,GameObject itemEffectVisual)
{
IntervalDamage(health, damage,time, itemEffectVisual);
}
//일정 시간 동안 틱대미지 일으키는 함수
public async void IntervalDamage(Health health, float damage,float time, GameObject itemEffectVisual)
{
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)
{
health.ChangeHP(Mathf.FloorToInt(tickDamage)); //소수점 전부 버림
if (health.CurrentHP <= 0) break;
time--;
await Task.Yield();
}
Destroy(fx_Visual);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 784f293946888364996d3928fe23ffd4

View File

@@ -2,17 +2,16 @@
public class PlayerHealth : Health
{
private PlayerStat _pstat;
public int currentHp;
[SerializeField] private PlayerStat _pstat;
void Start()
{
_pstat = GetComponent<PlayerStat>();
//currentHp = _pstat.MaxHp; // 스태틱 데이터를 가져와 초기화
currentHp = _pstat.MaxHp; // 스태틱 데이터를 가져와 초기화
}
public void TakeDamage(int damage)
{
ChangeHP(currentHp - Mathf.Clamp(damage,0,currentHp));
}
}

View File

@@ -183,4 +183,10 @@ public void UpdateSlotUI()
}
//SlotBg.sprite = _rarityImage.sprite;
}
public void ItemUse()
{
GameManager.Instance.ItemEffect.ItemUse(currentItem);
currentItem.CurrentStack -= 1;
}
}

View File

@@ -2,5 +2,11 @@
public class Health : MonoBehaviour
{
protected int currentHp;
public int CurrentHP { get { return currentHp; } }
public void ChangeHP(int newHp)
{
currentHp = newHp;
}
}