Beispiel #1
0
        public GameObject GetSlotMapping(InventorySlot inventorySlot, out bool makeDisabled, bool alreadyAdded = false)
        {
            makeDisabled = false;
            InventorySlotMapping inventorySlotMapping = inventorySlotMappings.Find(x => x.inventorySlot == inventorySlot);

            if (inventorySlotMapping == null)
            {
                Debug.LogError(name + ": Trying to put an Entity in an InventorySlot (" + inventorySlot + ") Location that does " +
                               "not have an InventorySlotMapping. (On the Entity Component - please set the InventorySlotMapping variable)");
                return(null);
            }

            int numInSlot = inventoryType.GetInventorySlotAmount(this, inventorySlot);

            if (alreadyAdded)
            {
                --numInSlot;
            }

            int locationIndex = -1;

            switch (inventorySlot.slotType)
            {
            case InventorySlot.SlotType.Invisible:
            case InventorySlot.SlotType.OwnerInvisible:
                locationIndex = 0;
                break;

            case InventorySlot.SlotType.Location:
                if (numInSlot > 1)
                {
                    Debug.LogError(name + ": Entity.GetSlotMapping failed to find slot location in InventorySlot = " + inventorySlot.name);
                    return(null);
                }
                locationIndex = 0;
                break;

            case InventorySlot.SlotType.MultiLocation:
                locationIndex = numInSlot;
                if (numInSlot >= inventorySlotMapping.locations.Count)
                {
                    if (inventorySlot.extraBecomesInvisible)
                    {
                        // Place item in the last slot and tell caller it should be disabled
                        makeDisabled  = true;
                        locationIndex = inventorySlotMapping.locations.Count - 1;
                    }
                    else
                    {
                        Debug.LogError(name + ": Entity.GetSlotMapping failed to find slot location in InventorySlot = " + inventorySlot.name);
                        return(null);
                    }
                }
                break;

            case InventorySlot.SlotType.Skinned:
                Debug.LogError("InventorySlot (" + inventorySlot.name + ") - Skinned Slot type is currently not supported.");
                return(null);
            }

            if (locationIndex >= inventorySlotMapping.locations.Count)
            {
                Debug.LogError(name + ": GetSlotMapping (" + inventorySlot.name + ") tried to use a inventorySlotMapping.locations " +
                               "that doesn't exist: " + locationIndex + " >= " + inventorySlotMapping.locations.Count);
                return(null);
            }

            return(inventorySlotMapping.locations[locationIndex]);
        }