42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class ShelfSpaceController : MonoBehaviour
|
||
|
|
{
|
||
|
|
public StockInfo info;
|
||
|
|
public int amountOnShelf;
|
||
|
|
public List<StockObject> objectsOnShelf;
|
||
|
|
public void PlaceStock(StockObject objectToPlace)
|
||
|
|
{
|
||
|
|
if (objectToPlace == null) return;
|
||
|
|
|
||
|
|
// If the shelf is empty, initialize it with the item's info
|
||
|
|
//if (amountOnShelf == 0)
|
||
|
|
if(objectsOnShelf.Count == 0)
|
||
|
|
{
|
||
|
|
info = objectToPlace.info;
|
||
|
|
}
|
||
|
|
// Otherwise, verify that the item matches the shelf's assigned stock type
|
||
|
|
else if (info == null || info.name != objectToPlace.info.name)
|
||
|
|
{
|
||
|
|
return; // Name mismatch or info missing, exit early
|
||
|
|
}
|
||
|
|
|
||
|
|
// Parent the object to the shelf and trigger the placement logic
|
||
|
|
objectToPlace.transform.SetParent(transform);
|
||
|
|
objectToPlace.MakePlaced();
|
||
|
|
//amountOnShelf++;
|
||
|
|
objectsOnShelf.Add(objectToPlace);
|
||
|
|
}
|
||
|
|
public StockObject Getstock()
|
||
|
|
{
|
||
|
|
StockObject stockToReturn = null;
|
||
|
|
if(objectsOnShelf.Count > 0)
|
||
|
|
{
|
||
|
|
stockToReturn = objectsOnShelf[objectsOnShelf.Count - 1];
|
||
|
|
objectsOnShelf.RemoveAt(objectsOnShelf.Count - 1);
|
||
|
|
}
|
||
|
|
return stockToReturn;
|
||
|
|
}
|
||
|
|
}
|