public bool Fits(ProductGO product, Vector3 pos) { Collider productGOCollider = product.GetComponent <Collider>(); float raycastDistance = productGOCollider.bounds.extents.y * 2; float radius = productGOCollider.bounds.extents.x; RaycastHit[] hits = Physics.SphereCastAll(pos - new Vector3(0, .05f, 0), radius, Vector3.up, raycastDistance); foreach (RaycastHit hit in hits) { if (hit.transform.tag == "StoreObject") { continue; } else if (hit.transform.tag == "Shelf") { Shelf shelf = hit.transform.GetComponent <Shelf>(); if (shelf.shelfLayer != shelfLayer) { return(false); } else { continue; } } else if (hit.transform.gameObject.layer == 17) { return(false); } } return(true); }
public Product CreateProduct(StoreObjectReference container, Box.PackagedBud bud) { // Create a container and put packaged bud into it GameObject newContainer = Instantiate(container.gameObject_); newContainer.transform.position = bud.parentBox.transform.position; ProductGO productGO = newContainer.GetComponent <ProductGO>(); if (container.proType == StoreObjectReference.productType.jar) { StorageJar storageJar = new StorageJar(container, newContainer); storageJar.uniqueID = Dispensary.GetUniqueProductID(); productGO.product = storageJar; float incrementValue = 1; List <Bud> newBuds = new List <Bud>(); while (bud.weight > 0) { if (bud.weight - 1 < 0) { incrementValue = bud.weight; } GameObject budGO = new GameObject(bud.strain.name + " Nug"); budGO.transform.SetParent(newContainer.transform); budGO.transform.localPosition = Vector3.zero; Bud newBud = budGO.AddComponent <Bud>(); newBud.strain = bud.strain; newBud.weight = incrementValue; newBuds.Add(newBud); bud.weight -= incrementValue; } print("Adding buds"); storageJar.AddBud(newBuds); return(storageJar); } return(null); }
public void AddStartJar() { List <StoreObjectReference> containerObjects = db.GetProducts(StoreObjectReference.productType.container); GameObject jar = Instantiate(containerObjects[1].gameObject_); ProductGO productGO = jar.GetComponent <ProductGO>(); productGO.objectID = containerObjects[1].objectID; StorageJar storageJar = new StorageJar(containerObjects[1], jar); storageJar.uniqueID = Dispensary.GetUniqueProductID(); storageJar.objectID = containerObjects[1].objectID; productGO.product = storageJar; productGO.canHighlight = true; jar.GetComponent <Jar>().product = storageJar; List <Bud> toAdd = new List <Bud>(); Strain toUse = db.GetRandomStrain(); for (int i = 0; i < 28; i++) { GameObject bud = new GameObject("Bud"); Bud newBud = bud.AddComponent <Bud>(); newBud.strain = toUse; newBud.weight = UnityEngine.Random.Range(.65f, 1.35f); newBud.weight = Mathf.Round(newBud.weight * 100f) / 100f; // Round to 2 decimal places jar.GetComponent <Jar>().AddBud(bud); bud.transform.position = Vector3.zero; toAdd.Add(newBud); } storageJar.AddBud(toAdd); ShelfPosition jarPosition = dm.dispensary.Storage_cs[0].GetRandomStorageLocation(storageJar); jar.transform.position = jarPosition.transform.position; jar.transform.parent = jarPosition.transform; jarPosition.shelf.parentShelf.AddProduct(storageJar); }
public void FocusCallback() { try { ProductGO product = GetCurrentProduct().productGO.GetComponent <ProductGO>(); camManager.FocusCameraOnObject(product.cameraPosition, product.gameObject); } catch (NullReferenceException) { // no camera position } }
public void Place(StoreObjectFunction_DisplayShelf newParentShelf, Vector3 pos) { ProductGO pGO = productGO.GetComponent <ProductGO>(); // The ProductGO component attached to the productGO pGO.transform.position = pos; productGO.SetActive(true); // the product gameobject set to true ProductManager productManager = GameObject.Find("DispensaryManager").GetComponent <ProductManager>(); productManager.ProductPlaced(this); newParentShelf.AddProduct(this); parentShelf = newParentShelf; }
public void AddStartBox() { List <StoreObjectReference> boxModels = db.GetProducts(StoreObjectReference.productType.box); GameObject box = Instantiate(boxModels[1].gameObject_); ProductGO productGO = box.GetComponent <ProductGO>(); productGO.objectID = boxModels[1].objectID; StorageBox storageBox = new StorageBox(boxModels[1], box); storageBox.uniqueID = Dispensary.GetUniqueProductID(); storageBox.objectID = boxModels[1].objectID; productGO.product = storageBox; productGO.canHighlight = true; box.GetComponent <Box>().product = storageBox; List <Product> toAdd = new List <Product>(); List <StoreObjectReference> bongs = db.GetProducts(StoreObjectReference.productType.glassBong); // Add bongs to box /*for (int i = 0; i < 4; i++) * { * GameObject bongGO = Instantiate(bongs[0].gameObject_); * bongGO.GetComponent<Glass>().height = 16f; * ProductGO productGO_ = bongGO.GetComponent<ProductGO>(); * productGO_.objectID = bongs[0].objectID; * Bong newBong = new Bong(bongGO); * newBong.parentProduct = storageBox; * newBong.objectID = bongs[0].objectID; * productGO_.product = newBong; * productGO_.canHighlight = false; * bongGO.gameObject.SetActive(false); * toAdd.Add(newBong); * box.GetComponent<Box>().AddProduct(newBong); * } * storageBox.AddProducts(toAdd);*/ Box parentBox = box.GetComponent <Box>(); Box.PackagedProduct newPackagedProduct = new Box.PackagedProduct(parentBox, bongs[4], 8); parentBox.AddProduct(newPackagedProduct); Strain toUse = db.GetStrain("Trainwreck"); // Temp add bud to starting box. eventually will contain pipes, bowls, and rolling papers to start Box.PackagedBud newBud = new Box.PackagedBud(parentBox, toUse, 88); parentBox.AddBud(newBud); ShelfPosition boxPosition = dm.dispensary.Storage_cs[0].GetRandomStorageLocation(storageBox); box.transform.position = boxPosition.transform.position; box.transform.parent = boxPosition.transform; boxPosition.shelf.parentShelf.AddProduct(storageBox); }
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); } }
public Box CreateBox(int orderWeight) { StoreObjectReference currentBoxReference = GetBox(orderWeight); GameObject newProductBox = Instantiate(currentBoxReference.gameObject_); ProductGO productGO = newProductBox.GetComponent <ProductGO>(); productGO.objectID = currentBoxReference.objectID; StorageBox storageBox = new StorageBox(currentBoxReference, newProductBox); storageBox.objectID = currentBoxReference.objectID; storageBox.uniqueID = Dispensary.GetUniqueProductID(); productGO.product = storageBox; productGO.canHighlight = true; newProductBox.GetComponent <Box>().product = storageBox; newProductBox.GetComponent <Box>().currentWeight = 0; newProductBox.GetComponent <Box>().maxWeight = currentBoxReference.boxWeight; return(newProductBox.GetComponent <Box>()); }
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())*/ }
public void FinishAddingBox(Box boxToMove) { // Sets the temp stack to be the main one if (tempIncreasedStack != null) { Destroy(tempIncreasedStack.gameObject); } displayingTempIncreasedStack = false; if (newBox != null) { StorageBox product = (StorageBox)boxToMove.product; Box reallyNewBox = Instantiate(newBox); product.box = reallyNewBox.gameObject; reallyNewBox.product = product; ProductGO newProductGO = reallyNewBox.GetComponent <ProductGO>(); ProductGO toMoveProductGO = boxToMove.GetComponent <ProductGO>(); newProductGO.objectID = toMoveProductGO.objectID; reallyNewBox.parentBoxStack = this; AddBox(reallyNewBox); } Destroy(boxToMove.gameObject); SortStack(transform.position, true, false); }
public void PlaceProduct(ProductGO product) { parentShelf.AddProduct(product.product); product.transform.SetParent(transform, false); }
public void FocusCallback() { ProductGO product = GetCurrentProduct().productGO.GetComponent <ProductGO>(); camManager.FocusCameraOnObject(product.cameraPosition, product.gameObject); }
public Product CreateProduct(StoreObjectReference toCreate, Vector3 pos) { GameObject newProductGameObject = Instantiate(toCreate.gameObject_); ProductGO newProductGO = newProductGameObject.GetComponent <ProductGO>(); newProductGO.transform.position = pos; newProductGO.gameObject.SetActive(false); if (toCreate.color.colorIsAssigned) { newProductGameObject = ApplyColor(newProductGameObject, toCreate.color.color); } /*if (newProductGO.colorable) * { * if (toCreate.randomColor != null) * { * newProductGameObject = ApplyColor(newProductGameObject, toCreate.randomColor); * } * else * { * newProductGameObject = ApplyRandomColor(newProductGameObject); * } * }*/ Product.type_ productType; switch (toCreate.proType) { case StoreObjectReference.productType.jar: productType = Product.type_.storageJar; break; case StoreObjectReference.productType.glassBong: productType = Product.type_.glassBong; break; case StoreObjectReference.productType.acrylicBong: productType = Product.type_.acrylicBong; break; case StoreObjectReference.productType.glassPipe: productType = Product.type_.glassPipe; break; case StoreObjectReference.productType.acrylicPipe: productType = Product.type_.acrylicPipe; break; case StoreObjectReference.productType.rollingPaper: productType = Product.type_.rollingPaper; break; case StoreObjectReference.productType.edible: productType = Product.type_.edible; break; case StoreObjectReference.productType.bowl: productType = Product.type_.bowl; break; case StoreObjectReference.productType.grinder: productType = Product.type_.grinder; break; default: productType = Product.type_.reference; break; } newProductGO.objectID = toCreate.objectID; switch (productType) { case Product.type_.glassBong: case Product.type_.acrylicBong: Bong newBong = new Bong(toCreate, newProductGameObject); newBong.uniqueID = Dispensary.GetUniqueProductID(); newBong.objectID = toCreate.objectID; newBong.boxWeight = toCreate.boxWeight; newProductGO.product = newBong; return(newBong); case Product.type_.glassPipe: case Product.type_.acrylicPipe: Pipe newPipe = new Pipe(toCreate, newProductGameObject); newPipe.uniqueID = Dispensary.GetUniqueProductID(); newPipe.objectID = toCreate.objectID; newPipe.boxWeight = toCreate.boxWeight; newProductGO.product = newPipe; return(newPipe); case Product.type_.storageJar: StorageJar newJar = new StorageJar(toCreate, newProductGameObject); newJar.uniqueID = Dispensary.GetUniqueProductID(); newJar.objectID = toCreate.objectID; newJar.boxWeight = toCreate.boxWeight; newProductGO.product = newJar; return(newJar); case Product.type_.bowl: Bowl newBowl = new Bowl(toCreate, newProductGameObject); newBowl.uniqueID = Dispensary.GetUniqueProductID(); newBowl.objectID = toCreate.objectID; newBowl.boxWeight = toCreate.boxWeight; newProductGO.product = newBowl; //newBowl = (Bowl)ApplyRandomColor(newBowl); return(newBowl); case Product.type_.grinder: Grinder newGrinder = new Grinder(toCreate, newProductGameObject); newGrinder.uniqueID = Dispensary.GetUniqueProductID(); newGrinder.objectID = toCreate.objectID; newGrinder.boxWeight = toCreate.boxWeight; newProductGO.product = newGrinder; //newGrinder = (Grinder)ApplyRandomColor(newGrinder); return(newGrinder); } return(null); }
public void Setup(ProductManager.CurrentProduct currentProduct) { parentProduct = currentProduct; if (db == null) { Start(); } GameSettings settings = db.settings; if (indicator == null) { indicator = Instantiate(db.GetStoreObject("Placeholder Indicator").gameObject_).GetComponent <PlaceholderDisplayIndicator>(); indicator.transform.SetParent(transform); ProductGO productGO = gameObject.GetComponent <ProductGO>(); if (productGO != null) { indicator.transform.localPosition = productGO.indicatorPos; indicator.transform.localEulerAngles = productGO.indicatorEulers; indicator.transform.localScale = productGO.indicatorScale; } else { indicator.transform.localPosition = Vector3.zero; indicator.transform.localEulerAngles = Vector3.zero; indicator.transform.localScale = Vector3.one; } if (currentProduct.currentProduct.NeedsContainer()) { if (currentProduct.currentContainer == null) { indicator.BeingMoved(true, "No Container Selected", "Press '" + settings.GetOpenChooseContainerPanel().ToLower() + "' to choose a container"); } else { Box.PackagedBud packagedBud = parentProduct.GetPackagedBud(); if (packagedBud != null) { string topString = "Moving " + packagedBud.weight + "g of " + packagedBud.strain.name; StoreObjectReference container = parentProduct.currentContainer; string bottomString = "Container - " + container.boxWeight + "g Capacity"; indicator.BeingMoved(false, topString, bottomString); } else { indicator.BeingMoved(false, parentProduct.currentContainer.productName, parentProduct.currentContainer.boxWeight + "g Capacity"); } } } else { Box.PackagedBud potentialBud = parentProduct.GetPackagedBud(); if (potentialBud != null) { indicator.BeingMoved(false, potentialBud.strain.name, potentialBud.weight + "g"); } else { try { indicator.BeingMoved(); //indicator.BeingMoved(false, currentProduct.currentProduct.GetName(), ""); } catch (System.NullReferenceException) { indicator.BeingMoved(false, "NullReferenceException", "F**k"); } } } } }