- RPG Project - 28 [ Equipment System - Equip OFF ]2024년 11월 09일
- SiJun-Park
- 작성자
- 2024.11.09.:39
아이템을 착용해제하는 것이 이번 28의 주제입니다.
void Onslot(_slot_type type, BaseEventData eventData, bool b) { if (!b || (eventData as PointerEventData).button != PointerEventData.InputButton.Right) return; CheckInit(type); } public void OnHelmet(BaseEventData eventData) => Onslot(_slot_type.Helmet, eventData, _helemt_using); public void OnArmer(BaseEventData eventData) => Onslot(_slot_type.Armer, eventData, _armer_using); public void OnShield(BaseEventData eventData) => Onslot(_slot_type.Shield, eventData, _shield_using); public void OnShoes(BaseEventData eventData) => Onslot(_slot_type.Shoes, eventData, _shoes_using); public void OnWeapon(BaseEventData eventData) => Onslot(_slot_type.Weapon, eventData, _weapon_using);
먼저 EventTrigger를 이용해서 버튼을 연결 해줍니다.
여기서 해당 슬롯을 사용을 하는지 체크를 해주고 사용을 안한다면 비어있다는 것이니 return을 해줍니다.
또한 우측 마우스 클릭이 아니면 return을 해줍니다.
void UNUpdate_UserStat(EquipSlot equip) { Player._damage -= equip._damage; Player._HP -= equip._hp; Player._MP -= equip._mp; Player._def -= equip._def; updatetext(); } void CheckInit(_slot_type type) { if(InventorySystem.instance._MaxSlots <= 0) { Debug.Log("인벤토리가 부족합니다."); return; } int index = equipSlots.FindIndex(slot => slot.Type == type); if(index >= 0) { UNUpdate_UserStat(equipSlots[index]); ItemControl deleteItem = new GameObject().AddComponent<ItemControl>(); deleteItem._item_type = equipSlots[index]._item_type; deleteItem._name = equipSlots[index]._name; deleteItem._isStackable = equipSlots[index]._isStackable; deleteItem._Icon = equipSlots[index]._Icon; deleteItem._WearImage = equipSlots[index]._WearImage; deleteItem._value = equipSlots[index]._value; deleteItem._prefebnum = equipSlots[index]._prefebnum; deleteItem._UseSound = equipSlots[index]._UseSound; deleteItem.damage = equipSlots[index]._damage; deleteItem.def = equipSlots[index]._def; deleteItem.hp = equipSlots[index]._hp; deleteItem.mp = equipSlots[index]._mp; deleteItem._EquipSound = equipSlots[index]._EquipSound; deleteItem._BundleData = equipSlots[index]._BundleData; deleteItem._EquipData = equipSlots[index]._EquipData; InventorySystem.instance.Item_add(deleteItem); } switch (type) { case _slot_type.Weapon: _weapon_using = false; Weapon.sprite = _default; Player._CurrentWeapon = UserControl.Weapon.Hands; Destroy(Player._RightHand.transform.GetChild(0).gameObject); break; case _slot_type.Helmet: _helemt_using = false; Helmet.sprite = _default; break; case _slot_type.Armer: _armer_using = false; Armer.sprite = _default; break; case _slot_type.Shield: _shield_using = false; Shield.sprite = _default; Destroy(Player._LeftHand.transform.GetChild(0).gameObject); Player._isShield_Using = false; break; case _slot_type.Shoes: _shoes_using = false; Shoes.sprite = _default; break; } }
Init에 들어오게 되면 가장 먼저 내 인벤토리가 꽉차있는지 체크를 하고 꽉차있다면 return을 시켜줍니다.
그게 아니라면 type에 해당하는 슬롯 인덱스를 가져오고
착용을 해제 해줄꺼니 저장하였던 수치만큼 빼주고 텍스트를 업데이트 해줍니다.
그 다음엔 ItemControl을 생성을 해주어 equip 슬롯에 저장된 속성들을 할당을 해주고
아이템을 추가 해줍니다.
마무리로 사용하였던 부위의 사용 여부를 false로 바꾸어주고 지정한 default 아이콘으로 다 바꾸어 줍니다.
결과 'Unity > RPG Project' 카테고리의 다른 글
RPG Project - 30 [ Description System - Auto Position] (1) 2024.11.14 RPG Project - 29 [ Description System ] (0) 2024.11.13 RPG Project - 27 [ Equipment System - Equip On ] (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 다음글이전글이전 글이 없습니다.댓글
스킨 업데이트 안내
현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)