/// <summary>
    /// Equip an item from the ground.
    /// </summary>
    public void Equip(_Item item)
    {
        if (item == null)
        {
            return;
        }

        // If theres already an item equipped
        Unequip();

        if (item is _CoreItem)
        {
            var core = item as _CoreItem;
            coreItems[core.targetSlot] = core;
            hud.UnlockItem(GetItemSlot(core));
            MoveToInventory(item);
        }
        else
        {
            // Move it
            MoveToEquipped(item);
        }

        item.OnPickup();
    }
    /// <summary>
    /// Equip an item from the ground.
    /// </summary>
    public void Equip(_Item item)
    {
        if (item == null) return;

        // If theres already an item equipped
        Unequip();

        if (item is _CoreItem) {
            var core = item as _CoreItem;
            coreItems[core.targetSlot] = core;
            hud.UnlockItem(GetItemSlot(core));
            MoveToInventory(item);
        } else {
            // Move it
            MoveToEquipped(item);
        }

        item.OnPickup();
    }
Пример #3
0
    public void OnLoad(Dictionary <string, object> data)
    {
        // Goto position
        exitID = (int)data["player@exitID"];

        SpawnPoint exit = SpawnPoint.GetFromID(exitID);

        if (exit)
        {
            transform.position = exit.transform.position;
            transform.rotation = exit.transform.rotation;
        }

        // Load coreitems
        PlayerInventory inventory    = FindObjectOfType <PlayerInventory>();
        ItemData        equippedData = (ItemData)data["player@equipped"];

        for (int i = 0; i < inventory.coreItems.Length; i++)
        {
            ItemData itemData = (ItemData)data["player@coreItem#" + i];
            if (itemData.prefab == null)
            {
                continue;
            }

            GameObject clone = Instantiate(ItemDataBase.GetPrefab(itemData.prefab)) as GameObject;

            UniqueId uuid = clone.GetComponent <UniqueId>();
            uuid.uniqueId = itemData.uuid;

            _CoreItem item = clone.GetComponent <_CoreItem>();

            if (equippedData.uuid == itemData.uuid)
            {
                // Send to equipped
                inventory.coreItems[item.targetSlot] = item;
                inventory.MoveToEquipped(item);
                item.OnPickup();
                equippedData.prefab = null;
            }
            else
            {
                // Send to inventory
                inventory.coreItems[item.targetSlot] = item;
                inventory.MoveToInventory(item);
                item.OnPickup();
            }
        }

        if (equippedData.prefab != null)
        {
            // Spawn as equipped
            GameObject clone = Instantiate(ItemDataBase.GetPrefab(equippedData.prefab)) as GameObject;

            UniqueId uuid = clone.GetComponent <UniqueId>();
            uuid.uniqueId = equippedData.uuid;

            _Item item = clone.GetComponent <_Item>();

            inventory.MoveToEquipped(item);
            item.OnPickup();
        }
    }