- RPG Project - 27 [ Equipment System - Equip On ]2024년 11월 09일
- SiJun-Park
- 작성자
- 2024.11.09.:23
이번의 목표는 아이템 착용입니다.
Google SpreadSheets 가장 먼저 DB를 업데이트 해주어야 하니깐, Google SpreadSheets에 들어가 추가를 할 물품들을 추가 해줍니다.
상태창 이번 구현에는 투구, 갑옷, 무기, 방패, 신발만 구현을 할 예정이라 위와 같이 슬롯을 만들어 주었습니다.
public void UseItem() { if (!_isUsing) return; // 비어있는 거면 그냥 return if (Input.GetMouseButtonDown(1)) { Using(); return; } _DragImage.gameObject.SetActive(true); // 드래그 이미지를 활성화 시켜준다. 이때 해당 아이템의 transform을 가져오기 때문에 아이템 자체가 이동이 된다. _DragImage.transform.position = Input.mousePosition; _BackGround.sprite = _Icon.sprite; UpdateSlot(true, _Icon.sprite); _text.text = ""; } public void Using() { if (!_isUsing) return; if (_items.Count == 1) { //한개일 경우 사용 후 삭제! _items.Peek().Using(); _items.Clear(); // 전부 삭제 _isStackable = false; UpdateSlot(false, _default); return; } ItemControl currentitem = _items.Pop(); currentitem.Using(); UpdateSlot(_isUsing, _Icon.sprite); }
이제 인벤토리 Slot에서 마우스 우측을 클릭하면 사용이 되게 합니다.
public void Using() { switch (_item_type) { case item_type.HP: break; case item_type.MP: break; case item_type.SP: break; case item_type.Gold: break; case item_type.ETC: break; default: // 나머지는 전부 다 장착 아이템 EquipControl._instance.Equip_on(this); break; } }
Using함수를 보면 이제 위와 같이 case로 조건을 달아준 것 이외는 전부 다 장착 아이템으로 만들었기 때문에
default에 다 넣어줍니다.
public enum _slot_type { Helmet, Shoes, Armer, Weapon, Shield } public void UpdatgeInformation(_slot_type type, ItemControl item) { _damage = UserControl._instance._damage; _damage_text.text = "Damage : " + _damage; _level = UserControl._instance._level; _level_text.text = "Level : " + _level; _ac = UserControl._instance._def; _ac_text.text = "AC : " + _ac; _sp = UserControl._instance._SP; _sp_text.text = "SP : " + _sp; switch (type) { case _slot_type.Helmet: if (_helemt_using) return; _helemt_using = true; Helmet.sprite = item._Icon; break; case _slot_type.Shoes: if (_shoes_using) return; _shoes_using = true; Shoes.sprite = item._Icon; break; case _slot_type.Armer: if (_armer_using) return; _armer_using = true; Armer.sprite = item._Icon; break; case _slot_type.Weapon : if (_weapon_using) return; _weapon_using = true; Weapon.sprite = item._Icon; break; case _slot_type.Shield: if (_shield_using) return; _shield_using = true; Shield.sprite = item._Icon; break; } UpdateEquipSlot(type, item._item_type, item._name, item._isStackable, item._Icon, item._WearImage, item._value, item._prefebnum, item._UseSound, item.damage, item.def, item.hp, item.mp, item._EquipSound, item._BundleData, item._EquipData); }
위는 이제 슬롯의 타입과 아이템을 불러와 아이콘과 사용 중이라는 표시를 해줍니다
이는 나중에 교체 시스템 또는 아이템을 벗는 행위를 할 때 사용을 할 예정입니다.
void Update_UserStat(ItemControl item) { if (item._isStackable) return; Player._damage += item.damage; Player._HP += item.hp; Player._MP += item.mp; Player._def += item.def; } public void Equip_on(ItemControl item) { if (item._isStackable) return; Player = UserControl._instance; Update_UserStat(item); switch (item._item_type) { case item_type.Helmet: UpdatgeInformation(_slot_type.Helmet, item); break; case item_type.Shoes: UpdatgeInformation(_slot_type.Shoes, item); break; case item_type.Armer: UpdatgeInformation(_slot_type.Armer, item); break; case item_type.Shield: Instantiate(item._WearImage, Player._LeftHand); UpdatgeInformation(_slot_type.Shield, item); Player._isShield_Using = true; break; case item_type.One_Hand_Axe: Instantiate(item._WearImage, Player._RightHand); Player._CurrentWeapon = UserControl.Weapon.One_Hand_Axe; UpdatgeInformation(_slot_type.Weapon, item); Player.AttackSound = item._UseSound; break; } SoundManager._instance.PrivatePlaySound(item._EquipSound, Player.transform); }
그러면 아까 EquipOn으로 this를 보내었습니다. 그것을 받아와서 가장 먼저 스테이터스를 업데이트 해주고
그 아이템의 타입에 맞도록 업데이트를 해줍니다
이때 방패와 무기는 오브젝트를 생성을 원하는 위치에 해줍니다.
마지막으로 입는 사운드 까지 출력을 하여 주었습니다.
public struct EquipSlot { public _slot_type Type; public item_type _item_type; public string _name; public bool _isStackable; public Sprite _Icon; public GameObject _WearImage; public int _value; public int _prefebnum; public AudioClip _UseSound; public int _damage; public int _def; public int _hp; public int _mp; public AudioClip _EquipSound; public Bundle_item_data_Class _BundleData; public Equip_item_data_Class _EquipData; public EquipSlot(_slot_type type, item_type item_type, string name, bool Stack, Sprite Icon, GameObject WearImage, int value, int prefeb, AudioClip Use, int damage, int def, int hp, int mp, AudioClip Equip, Bundle_item_data_Class bundledb, Equip_item_data_Class equipdb) { Type = type; _item_type = item_type; _name = name; _isStackable = Stack; _Icon = Icon; _WearImage = WearImage; _value = value; _prefebnum = prefeb; _UseSound = Use; _damage = damage; _def = def; _hp = hp; _mp = mp; _EquipSound = Equip; _BundleData = bundledb; _EquipData = equipdb; } }
이제 해당 슬롯마다 아이템 정보를 저장 하여야하니 struct 구조체로 Equipslot을 선언 해주었습니다.
private List<EquipSlot> equipSlots = new List<EquipSlot> { new EquipSlot(_slot_type.Helmet, item_type.Helmet, null, false, null, null, 0, 0, null, 0, 0, 0, 0, null, null, null), new EquipSlot(_slot_type.Weapon, item_type.Sword, null, false, null, null, 0, 0, null, 0, 0, 0, 0, null, null, null), new EquipSlot(_slot_type.Shoes, item_type.Shoes, null, false, null, null, 0, 0, null, 0, 0, 0, 0, null, null, null), new EquipSlot(_slot_type.Shield, item_type.Shield, null, false, null, null, 0, 0, null, 0, 0, 0, 0, null, null, null), new EquipSlot(_slot_type.Armer, item_type.Armer, null, false, null, null, 0, 0, null, 0, 0, 0, 0, null, null, null) };
리스트 형식으로 관리를 하며 슬롯마다 초기화를 해주었습니다.
private void UpdateEquipSlot(_slot_type type, item_type item_type, string name, bool Stack, Sprite Icon, GameObject WearImage, int value, int prefeb, AudioClip Use, int damage, int def, int hp, int mp, AudioClip Equip, Bundle_item_data_Class bundledb, Equip_item_data_Class equipdb) { int index = equipSlots.FindIndex(slot => slot.Type == type); if(index >= 0) { equipSlots[index] = new EquipSlot(type, item_type, name, Stack, Icon, WearImage, value, prefeb, Use, damage, def, hp, mp, Equip, bundledb, equipdb); } }
UpdatgeInformation 함수의 맨 밑부분에서 이제 해당 슬롯을 업데이트 해주는 형식으로 구현을 하여
EquipSlot마다 값을 저장 해주었습니다.
이 값은 이후에 바꾸거나, 빼거나 할 시 효율적으로 작업하기 위해서 구현을 하였습니다.
결과 'Unity > RPG Project' 카테고리의 다른 글
RPG Project - 29 [ Description System ] (0) 2024.11.13 RPG Project - 28 [ Equipment System - Equip OFF ] (0) 2024.11.09 RPG Project - 26 [ Skill System - Buff System ] (0) 2024.11.06 RPG Project - 25 [ Skill System - Area Skill System ] (0) 2024.11.04 RPG Project - 24 [ Skill System - Close Target System ] (0) 2024.11.04 다음글이전글이전 글이 없습니다.댓글