示例#1
0
    public Storable Withdraw(Storable storable)
    {
        for (int i = 0; i < storables.Length; i++)
        {
            if (storables[i] != null && storables[i] == storable)
            {
                storables[i] = null;
                storable.gameObject.SetActive(true);
                storable.gameObject.transform.SetParent(null);
                storable.state            = Storable.State.InWorld;
                storable.currentInventory = null;

                if (globalInventory)
                {
                    Item item = storable.GetComponent <Item>();
                    if (GameManager.Instance.items.ContainsKey(item.data))
                    {
                        GameManager.Instance.items[item.data].Remove(item);
                    }
                }

                return(storable);
            }
        }
        return(null);
    }
示例#2
0
    public bool Deposit(Storable storable)
    {
        for (int i = 0; i < storables.Length; i++)
        {
            if (storables[i] == null)
            {
                storables[i] = storable;
                if (storableSlots.Length > i)
                {
                    storable.transform.SetParent(storableSlots[i]);
                    storable.transform.localPosition = Vector3.zero;
                    storable.transform.localRotation = Quaternion.identity;
                }
                else
                {
                    storable.gameObject.SetActive(false);
                }
                storable.state            = Storable.State.InInventory;
                storable.currentInventory = this;

                if (globalInventory)
                {
                    Item item = storable.GetComponent <Item>();
                    if (GameManager.Instance.items.ContainsKey(item.data) == false)
                    {
                        GameManager.Instance.items.Add(item.data, new List <Item>()
                        {
                            item
                        });
                    }
                    else
                    {
                        GameManager.Instance.items[item.data].Add(item);
                    }
                }

                return(true);
            }
        }
        return(false);
    }