Android build 최적화
Ios 빌드 알아보기
방어구 시스템 4트
밭에 씨앗을 심을 시 인벤토리에 씨앗이 있어야 인터렉트가 되고, 씨앗이 소모되게 하기
public class UIArmorSlot : UIItemSlot
{
enum Images
{
Icon,
}
public ItemParts part;
public override void Initialize()
{
Bind<Image>(typeof(Images));
Get<Image>((int)Images.Icon).gameObject.SetActive(false);
Get<Image>((int)Images.Icon).raycastTarget = false;
}
private void Awake()
{
Initialize();
Managers.Game.Player.ToolSystem.OnEquip += EquipArmor;
Managers.Game.Player.ToolSystem.OnUnEquip += UnEquipArmor;
Managers.Game.Player.ArmorSystem.UnEquipArmor += UnEquipArmor;
}
public void EquipArmor(QuickSlot quickSlot)
{
int parts = GetPart(quickSlot);
if (parts == 0)
{
switch (part)
{
case ItemParts.Head:
Set(quickSlot.itemSlot);
break;
}
}
else if (parts == 1)
{
switch (part)
{
case ItemParts.Body:
Set(quickSlot.itemSlot);
break;
}
}
}
public void UnEquipArmor(QuickSlot quickSlot)
{
int parts = GetPart(quickSlot);
if (parts == 0)
{
switch (part)
{
case ItemParts.Head:
Clear();
break;
}
}
else if (parts == 1)
{
switch (part)
{
case ItemParts.Body:
Clear();
break;
}
}
}
public override void Set(ItemSlot itemSlot)
{
Get<Image>((int)Images.Icon).sprite = itemSlot.itemData.iconSprite;
Get<Image>((int)Images.Icon).gameObject.SetActive(true);
}
public override void Clear()
{
Get<Image>((int)Images.Icon).gameObject.SetActive(false);
}
private int GetPart(QuickSlot slot)
{
var itemData = slot.itemSlot.itemData as EquipItemData;
if (itemData == null) return -1;
return (int)itemData.part;
}
}
public class ArmorSystem : MonoBehaviour
{
public int _defense;
public QuickSlot[] _linkedSlots;
public event Action<QuickSlot> UnEquipArmor;
private void Awake()
{
_linkedSlots = new QuickSlot[2];
Managers.Game.Player.ToolSystem.OnEquip += DefenseOfTheEquippedArmor;
Managers.Game.Player.ToolSystem.OnUnEquip += DefenseOfTheUnEquippedArmor;
Managers.Game.Player.OnHit += Duration;
}
private void Start()
{
Managers.Game.Player.Inventory.OnUpdated += OnInventoryUpdated;
}
public void DefenseOfTheEquippedArmor(QuickSlot quickSlot)
{
EquipItemData toolItemData = ArmorDefense(quickSlot);
_defense += toolItemData.defense;
Managers.Game.Player.playerDefense = _defense;
if ((int)toolItemData.part == 0 || (int)toolItemData.part == 1)
{
_linkedSlots[(int)toolItemData.part] = quickSlot;
}
}
public void DefenseOfTheUnEquippedArmor(QuickSlot quickSlot)
{
EquipItemData toolItemData = ArmorDefense(quickSlot);
_defense -= toolItemData.defense;
Managers.Game.Player.playerDefense = _defense;
if ((int)toolItemData.part == 0 || (int)toolItemData.part == 1)
{
_linkedSlots[(int)toolItemData.part] = null;
}
}
public void Duration() // Player Hit에서 호출
{
for (int i = 0; i < _linkedSlots.Length; i++)
{
if (_linkedSlots[i] != null && _linkedSlots[i].targetIndex != -1) // null로 한 번 걸렀는데 targetIndex를 또 걸러줘야 동작한다. 대체 왜??
{
Managers.Game.Player.Inventory.UseToolItemByIndex(_linkedSlots[i].targetIndex, 1);
}
}
}
public void OnInventoryUpdated(int inventoryIndex, ItemSlot itemSlot)
{
for (int i = 0; i < 2; i++)
{
if (_linkedSlots[i] != null)
{
if (_linkedSlots[i].targetIndex == inventoryIndex)
{
if (itemSlot.itemData == null)
{
EquipItemData toolItemData = ArmorDefense(_linkedSlots[i]);
_defense -= toolItemData.defense;
Managers.Game.Player.playerDefense = _defense;
UnEquipArmor?.Invoke(_linkedSlots[i]);
_linkedSlots[i].Clear();
Managers.Game.Player.ToolSystem.UnEquipArmor(_linkedSlots[i]);
}
}
}
}
}
private EquipItemData ArmorDefense(QuickSlot quickSlot)
{
ItemData armor = quickSlot.itemSlot.itemData;
EquipItemData toolItemDate = (EquipItemData)armor;
return toolItemDate;
}
}
public class ToolSystem : MonoBehaviour
{
public void UnEquipArmor(QuickSlot slot)
{
UnEquip(slot);
}
}
public class Farm : MonoBehaviour, IInteractable
{
public void Interact(Player player) // 인벤토리에 씨앗 확인
{
if (stateObject[0].activeSelf == true)
{
if (SeedsInInventory())
{
_stateMachine.Interact(player);
}
}
else if (stateObject[2].activeSelf == true)
{
_stateMachine.Interact(player);
}
}
private bool SeedsInInventory()
{
for (int i = 0; i < Managers.Game.Player.Inventory.slots.Length; i++)
{
if (Managers.Game.Player.Inventory.slots[i].itemData != null && Managers.Game.Player.Inventory.slots[i].itemData.name == "SeedItemData")
{
Managers.Game.Player.Inventory.RemoveItem(Managers.Game.Player.Inventory.slots[i].itemData, 1);
return true;
}
}
return false;
}
}
Armor system update
인벤토리에 씨앗이 있어야 밭에 작물을 심을 수 있게 변경하였습니다.
프로토 타입을 위해 구석기 시대 코딩을 했다는 합리화를 해본다 . . . 난 노력했다 . . . 리팩토링 반드시 할게요 봐주세요 ㅜ 🥕🥕🥕