示例#1
0
 public ShelfPosition GetRandomStorageLocation(Product product) // the parameter is used to narrow the possible locations
 {
     try
     {
         List <StoreObjectFunction_DisplayShelf> storageShelves = GetStorageShelves();
         List <ShelfPosition> starterPositions = new List <ShelfPosition>();
         if (storageShelves.Count > 0)
         {
             foreach (StoreObjectFunction_DisplayShelf displayShelf in storageShelves)
             {
                 if (displayShelf.shelves.Count > 0)
                 {
                     foreach (Shelf shelf_ in displayShelf.shelves)
                     {
                         if (shelf_.starterPositions.Count > 0)
                         {
                             foreach (ShelfPosition starterPosition in shelf_.starterPositions)
                             {
                                 starterPosition.shelf = shelf_;
                                 starterPositions.Add(starterPosition);
                             }
                         }
                     }
                 }
             }
             int           randomPosition = UnityEngine.Random.Range(0, starterPositions.Count - 1);
             ShelfPosition shelfPosition  = starterPositions[randomPosition];
             Shelf         shelf          = shelfPosition.shelf;
             ProductGO     productGO      = product.productGO.GetComponent <ProductGO>();
             if (shelf.Fits(productGO, shelfPosition.transform.position))
             {
                 return(shelfPosition);
             }
             else
             {
                 return(GetRandomStorageLocation(product));
             }
         }
         else
         {
             dm.notificationManager.AddToQueue("No storage shelves", NotificationManager.NotificationType.problem);
             return(null);
         }
     }
     catch (NullReferenceException)
     {
         dm.notificationManager.AddToQueue("No storage positions", NotificationManager.NotificationType.problem);
         return(null);
     }
 }
示例#2
0
    public ShelfPosition GetRandomPosition(ProductGO product)
    {
        if (presetPositions.Count > 0)
        {
            int           rand           = UnityEngine.Random.Range(0, presetPositions.Count);
            ShelfPosition randomPosition = presetPositions[rand];
            Shelf         shelf          = GetShelf(randomPosition.shelfLayer);
            if (shelf.Fits(product, randomPosition.transform.position))
            {
                return(randomPosition);
            }
            else
            {
                GetRandomPosition(product);
            }
        }
        return(null);

        /*
         * if (shelf.Fits())*/
    }