Esempio n. 1
0
    public void Equip(RavenNest.Models.Item item)
    {
        if (!baseItemPrefab)
        {
            Debug.LogError("BaseItemPrefab not set on player!! Unable to create item");
            return;
        }

        var existingItemController = equippedObjects.FirstOrDefault(x => x.Id == item.Id);

        if (existingItemController != null && existingItemController)
        {
            Destroy(existingItemController.gameObject);
            equippedObjects.Remove(existingItemController);
        }

        var itemController = Instantiate(baseItemPrefab, this.transform).GetComponent <ItemController>();

        itemController.Create(item, player.Appearance.Gender == Gender.Male);
        equippedObjects.Add(itemController);

        itemController.gameObject.layer = player.gameObject.layer;

        if (item.Category == ItemCategory.Weapon)
        {
            SetWeapon(itemController);
        }
        else
        {
            if (IsAppearanceItem(item.Type))
            {
                EquipAppearanceItem(item);
                return;
            }

            switch (item.Type)
            {
            case ItemType.Helm:
            {
                appearance.HideHair();
                appearance.SetItem(itemController, appearance.EquipHead);
            }
            break;

            case ItemType.Amulet:
                appearance.SetItem(itemController, appearance.EquipNeck);
                break;

            case ItemType.Shield:
                appearance.SetItem(itemController, appearance.EquipLHand);
                break;

            case ItemType.LeftShoulder:
                appearance.SetItem(itemController, appearance.EquipLShoulder);
                break;

            case ItemType.RightShoulder:
                appearance.SetItem(itemController, appearance.EquipRShoulder);
                break;
            }
        }
    }