示例#1
0
    public void EquipItem()
    {
        if (!(item is Equipment))
        {
            return;
        }

        equipmentManager.EquipItem(item as Equipment);
    }
    void MovingInventoryItem()
    {
        if (moveInventoryItem)
        {
            if (Input.GetMouseButton(0))
            {
                Vector3 screenSpace   = MainCamera.WorldToScreenPoint(moveInventoryItemObj.transform.position);
                Vector3 mousePosition = MainCamera.ScreenToWorldPoint(
                    new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
                moveInventoryItemObj.transform.position = mousePosition;

                if (!CheckMousePos())
                {
                    slot = null;
                }
            }

            else if (Input.GetMouseButtonUp(0))
            {
                if (slot != null)
                {
                    // 아이템이 원래 인벤토리에 있었다면...
                    if (moveInventoryItemObj.GetComponent <Item>().onInventory == PlayerInventory.transform)
                    {
                        // 슬롯이 플레이어 인벤토리의 슬롯이면..
                        if (PlayerInventory.CheckSlotParent(slot))
                        {
                            Debug.Log("인벤 -> 인벤");
                            PlayerInventory.InventoyItemMove(moveInventoryItemObj, slot);
                        }

                        else if (PlayerEquipment.CheckSlotParent(slot))
                        {
                            Debug.Log("인벤 -> 장비");
                            // 실패 시
                            if (!PlayerEquipment.EquipItem(moveInventoryItemObj, slot))
                            {
                                // 다시 인벤토리로 돌아가기
                                PlayerInventory.ReturnInvenItem(moveInventoryItemObj);
                            }
                            // 성공 시 인벤토리 슬롯 비우기
                            else
                            {
                                PlayerInventory.SetInventoryEmpty(moveInventoryItemObj);
                            }
                        }

                        // 박스의 슬롯이면..
                        else if (GameManager.Instance.BoxComponent.CheckSlotParent(slot))
                        {
                            Debug.Log("인벤 => 박스");
                            if (GameManager.Instance.BoxComponent.CheckEmptySlot(slot))
                            {
                                PlayerInventory.InvenToInven(GameManager.Instance.BoxComponent, moveInventoryItemObj, slot);
                            }
                            else
                            {
                                PlayerInventory.ReturnInvenItem(moveInventoryItemObj);
                            }
                        }
                    }

                    // 아이템이 원래 박스에 있었다면..
                    else if (moveInventoryItemObj.GetComponent <Item>().onInventory == GameManager.Instance.BoxInventory.transform)
                    {
                        // 슬롯이 플레이어 인벤토리의 슬롯이면..
                        if (PlayerInventory.CheckSlotParent(slot))
                        {
                            Debug.Log("박스 => 인벤");
                            if (PlayerInventory.CheckEmptySlot(slot))
                            {
                                GameManager.Instance.BoxComponent.InvenToInven(PlayerInventory, moveInventoryItemObj, slot);
                            }
                            else
                            {
                                GameManager.Instance.BoxComponent.ReturnInvenItem(moveInventoryItemObj);
                            }
                        }

                        else if (PlayerEquipment.CheckSlotParent(slot))
                        {
                            Debug.Log("박스 => 장비창");
                            // ...
                            if (!PlayerEquipment.EquipItem(moveInventoryItemObj, slot))
                            {
                                // 다시 인벤토리로 돌아가기
                                GameManager.Instance.BoxComponent.ReturnInvenItem(moveInventoryItemObj);
                            }
                            // 성공 시 인벤토리 슬롯 비우기
                            else
                            {
                                GameManager.Instance.BoxComponent.SetInventoryEmpty(moveInventoryItemObj);
                            }
                        }

                        // 박스의 슬롯이면..
                        else if (GameManager.Instance.BoxComponent.CheckSlotParent(slot))
                        {
                            Debug.Log("박스 -> 박스");
                            GameManager.Instance.BoxComponent.InventoyItemMove(moveInventoryItemObj, slot);
                        }
                    }

                    else if (moveInventoryItemObj.GetComponent <Item>().onInventory == PlayerEquipment.transform)
                    {
                        // 슬롯이 플레이어 인벤토리의 슬롯이면..
                        if (PlayerInventory.CheckSlotParent(slot))
                        {
                            Debug.Log("장비 => 인벤");
                            PlayerEquipment.TakeOffEquip(PlayerInventory, moveInventoryItemObj, slot);
                        }

                        else if (PlayerEquipment.CheckSlotParent(slot))
                        {
                            Debug.Log("장비 => 장비창");
                            // ...
                            PlayerEquipment.EquipToEquip(moveInventoryItemObj, slot);
                        }
                        // 박스의 슬롯이면..
                        else if (GameManager.Instance.BoxComponent.CheckSlotParent(slot))
                        {
                            Debug.Log("장비 -> 박스");
                            PlayerEquipment.TakeOffEquip(GameManager.Instance.BoxComponent, moveInventoryItemObj, slot);
                        }
                    }
                }

                else
                {
                    // 인벤에서 버릴때
                    if (moveInventoryItemObj.GetComponent <Item>().onInventory == PlayerInventory.transform)
                    {
                        PlayerInventory.PullItem(moveInventoryItemObj);
                    }

                    // 박스에서 버릴때
                    else if (moveInventoryItemObj.GetComponent <Item>().onInventory == GameManager.Instance.BoxInventory.transform)
                    {
                        GameManager.Instance.BoxComponent.PullItem(moveInventoryItemObj);
                    }

                    else if (moveInventoryItemObj.GetComponent <Item>().onInventory == PlayerEquipment.transform)
                    {
                        PlayerEquipment.PullItem(moveInventoryItemObj);
                    }
                }

                moveInventoryItem    = false;
                moveInventoryItemObj = null;
            }
        }
    }
    public void ParsingData(InventoryManager inventory, EquipmentManager equip)
    {
        if (SaveInvenstr == "" || SaveEquipstr == "")
        {
            return;
        }

        inventory.ClearInventory();
        equip.ClearEquipment();


        // 인벤토리 로드...
        string[] valarr = SaveInvenstr.Split('|');


        foreach (var item in valarr)
        {
            // parsingArr[0] = name [1] = y [2] = x
            string[] parsingArr = item.Split(',');
            if (parsingArr[0] != "null")
            {
                GameObject gameObject = null;
                for (int i = 0; i < itemoffsetList.Count; ++i)
                {
                    if (parsingArr[0] == itemoffsetList[i].ItemName)
                    {
                        gameObject = CreateItemObject(itemoffsetList[i]);
                    }
                }
                if (gameObject != null)
                {
                    inventory.SettingInventoryItemSize(gameObject, int.Parse(parsingArr[1]), int.Parse(parsingArr[2]));
                }
            }
        }

        // 장비창 로드...

        string[] valarr2 = SaveEquipstr.Split('|');
        foreach (var item in valarr2)
        {
            string[] parsingArr = item.Split(',');
            if (parsingArr[0] != "null")
            {
                GameObject gameObject = null;
                for (int i = 0; i < itemoffsetList.Count; ++i)
                {
                    if (parsingArr[0] == itemoffsetList[i].ItemName)
                    {
                        gameObject = CreateItemObject(itemoffsetList[i]);
                    }
                }
                GameObject slot = equip.GetEquipSlot(parsingArr[1]);

                if (gameObject && slot)
                {
                    equip.EquipItem(gameObject, slot);
                }
            }
        }
    }