コード例 #1
0
    public ShelfContainer GetRandomShelvingUnit(StockTypes selectedType = StockTypes.None)
    {
        // Check if there are shelves in the map
        if (shelvingUnits.Count == 0)
        {
            Debug.LogWarning(!isDoneLoading ? "MapManager is not done loading!" : "There are no shelves in the map!");

            return(null);
        }

        // Filter out shelves that are needed
        List <ShelfContainer> sortedShelfList = new List <ShelfContainer>();

        if (selectedType != StockTypes.None)
        {
            for (int i = 0; i < shelvingUnits.Count; i++)
            {
                ShelfContainer currentShelf = shelvingUnits[i];

                if (currentShelf.ShelfStockType == selectedType)
                {
                    sortedShelfList.Add(shelvingUnits[i]);
                }
            }
        }
        else
        {
            CopyData.CopyObjectData(shelvingUnits, sortedShelfList);
        }

        if (sortedShelfList.Count == 0)
        {
            Debug.LogWarning("There are no shelves that have this type of stock: " + selectedType.ToString());
            return(null);
        }

        // Filter out empty shelves
        List <ShelfContainer> stockedShelves = new List <ShelfContainer>();

        for (int s = 0; s < sortedShelfList.Count; s++)
        {
            ShelfContainer shelf = sortedShelfList[s];
            if (!shelf.IsEmpty())
            {
                stockedShelves.Add(shelf);
            }
        }

        if (stockedShelves.Count == 0)
        {
            Debug.Log("All shelves of " + selectedType.ToString() + " is empty!");
            return(EssentialFunctions.GetRandomFromArray(sortedShelfList));;
        }
        else
        {
            return(EssentialFunctions.GetRandomFromArray(stockedShelves));
        }
    }