IEnumerator MoveProduct()
    {
        while (true)
        {
            currentDisplayShelf = null;
            currentShelf        = null;
            bool movementConflict = false;
            if (currentProduct != null)
            {
                // Raise or lower shelf layer
                if (Input.GetKeyUp(dm.database.settings.GetRaiseShelfLayer()))
                {
                    SetCurrentShelfLayer(currentShelfLayer + 1);
                }
                if (Input.GetKeyUp(dm.database.settings.GetLowerShelfLayer()))
                {
                    SetCurrentShelfLayer(currentShelfLayer - 1);
                }

                // If moving a box
                bool productIsBox = currentProduct.currentProduct.IsBox();
                if (productIsBox)
                { // Moving box
                    print("Moving box");
                }
                if (currentProduct.newStack != null)
                {
                    currentProduct.newStack.CancelAddingBox();
                    currentProduct.newStack = null;
                    if (currentProduct.currentPlaceholder != null)
                    {
                        currentProduct.currentPlaceholder.gameObject.SetActive(true);
                    }
                }

                bool chooseContainerPanelOpen = uiM_v5.chooseContainerPanel.panelOpen;
                bool placingBudPanelOpen      = uiM_v5.packagedBudPlacementPanel.panelOpen;
                // Raycasting
                Ray          ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits = Physics.RaycastAll(ray.origin, ray.direction);

                if (currentProduct.currentProduct.NeedsContainer())
                {
                    if (Input.GetKeyUp(dm.database.settings.GetOpenChooseContainerPanel().ToLower()))
                    {
                        if (chooseContainerPanelOpen)
                        {
                            uiM_v5.CloseChooseContainerPanel();
                        }
                        else
                        {
                            currentProduct.currentPlaceholder.indicator.OpenChooseContainerPanel(currentProduct);
                        }
                    }
                }
                if (chooseContainerPanelOpen || placingBudPanelOpen)
                {
                    // Dont carry on if either of these windows are open
                    yield return(null);
                }
                else if (currentProduct.currentPlaceholder != null)
                {
                    currentProduct.currentPlaceholder.GetComponent <BoxCollider>().enabled = false;
                    currentProduct.currentPlaceholder.HighlightOff();
                    bool hitShelf = false;
                    foreach (RaycastHit hit in hits)
                    {
                        if (hit.transform.tag == "DisplayShelf" || hit.transform.tag == "CheckoutCounter")
                        {
                            if (hit.transform.tag == "DisplayShelf")
                            {
                                SetCurrentDisplayShelf(hit.transform.gameObject.GetComponent <StoreObjectFunction_DisplayShelf>());
                            }
                            else if (hit.transform.tag == "CheckoutCounter")
                            {
                                StoreObjectFunction_DisplayShelf shelf = hit.transform.gameObject.GetComponent <StoreObjectFunction_DisplayShelf>();
                                if (shelf != null)
                                {
                                    SetCurrentDisplayShelf(shelf);
                                }
                                else
                                {
                                    hitShelf = false;
                                    break;
                                }
                            }
                        }
                        if (hit.transform.gameObject.layer == 21)
                        {
                            currentShelf = hit.transform.gameObject.GetComponent <Shelf>();
                            if (currentShelf.shelfLayer == GetCurrentShelfLayer())
                            {
                                hitShelf = true;
                                currentProduct.currentPlaceholder.transform.position = hit.point;
                            }
                            SetCurrentDisplayShelf(currentShelf.parentShelf);
                        }
                        if (hit.transform.gameObject.layer == 17)
                        {
                            //print("Hitting product");
                        }
                        if (hit.transform.tag == "StorageBox" && productIsBox)
                        {
                            Box        beingMoved           = currentProduct.currentPlaceholder.GetComponent <Box>();
                            StorageBox storageBoxBeingMoved = (StorageBox)beingMoved.product;
                            Box        hitBox = hit.transform.GetComponent <Box>();
                            if (hitBox != null)
                            {
                                BoxStack stack = hitBox.parentBoxStack;
                                if (stack != null)
                                {
                                    if (stack.boxList.Count <= 2)
                                    {
                                        currentProduct.newStack = stack;
                                        Box        toSend        = Instantiate(beingMoved);
                                        StorageBox newStorageBox = new StorageBox(storageBoxBeingMoved.productReference, toSend.gameObject);
                                        newStorageBox.uniqueID = storageBoxBeingMoved.uniqueID;
                                        toSend.product         = newStorageBox;
                                        currentProduct.newStack.StartAddingBox(toSend);
                                        beingMoved.gameObject.SetActive(false);
                                        // need to handle carrying across contents as well
                                    }
                                    else
                                    {
                                        // Stack is full
                                        stack.gameObject.GetComponent <Highlighter>().ConstantOnImmediate(Color.red);
                                    }
                                }
                                else
                                {
                                    print("Need to create a new stack");
                                }
                            }
                        }
                    }
                    if (!hitShelf && hits.Length > 0 && !productIsBox)
                    { // Find the nearest display shelf
                        try
                        {
                            currentDisplayShelf = GetClosestDisplayShelf(hits[0].point);
                            currentShelf        = currentDisplayShelf.GetShelf(GetCurrentShelfLayer(), hits[0].point);
                            Vector3 closestPoint = currentShelf.GetCollider().ClosestPoint(hits[0].point);
                            currentProduct.currentPlaceholder.transform.position = closestPoint;
                        }
                        catch (System.NullReferenceException)
                        {
                            // Failed to find a nearby shelf
                        }
                    }
                    else if (!hitShelf && hits.Length > 0 && productIsBox)
                    {
                        try
                        {
                            RaycastHit       toUse          = hits[0];
                            bool             outdoorHit     = false;
                            ComponentSubGrid closestSubGrid = dm.dispensary.GetClosestSubGrid(toUse.point);
                            ComponentGrid    grid           = closestSubGrid.parentGrid;
                            FloorTile        hitTile        = null;
                            foreach (RaycastHit hit in hits)
                            {
                                if (hit.transform.tag == "Floor")
                                {
                                    hitTile = hit.transform.GetComponent <FloorTile>();
                                }
                            }
                            if (hitTile != null)
                            {
                                outdoorHit = false;
                            }
                            else
                            {
                                outdoorHit = true;
                            }
                            ComponentNode nodeToSnapTo    = null;
                            GameObject    tempTileGO      = Instantiate(dm.database.GetFloorTile(10000).gameObject_);
                            BoxCollider   placeholderTile = tempTileGO.GetComponent <BoxCollider>();
                            if (hitTile != null)
                            {
                                outdoorHit   = false;
                                nodeToSnapTo = hitTile.node;
                            }
                            if (nodeToSnapTo == null)
                            {
                                nodeToSnapTo = GetClosestEdgeNode(grid, toUse, outdoorHit);
                            }
                            Vector3 snapPos = nodeToSnapTo.worldPosition;
                            Vector3 newPos  = new Vector3(snapPos.x, snapPos.y + placeholderTile.bounds.extents.y, snapPos.z);
                            if (!dm.actionManager.snapToGrid)
                            { // If not snapping to grid and didnt hit something outside
                                if (!outdoorHit)
                                {
                                    foreach (RaycastHit hit in hits)
                                    {
                                        if (hit.transform.tag == "Floor")
                                        {
                                            newPos = hit.point;
                                        }
                                    }
                                }
                            }
                            currentProduct.currentPlaceholder.transform.position = newPos;
                            Destroy(tempTileGO.gameObject);
                        }
                        catch (System.NullReferenceException)
                        {
                        }
                    }
                    if (currentDisplayShelf != null && currentShelf != null)
                    {
                        // Disable Colliders
                        currentDisplayShelf.GetComponent <BoxCollider>().enabled = false;
                        currentShelf.GetCollider().enabled = false;

                        // Perform collision check
                        BoxCollider productCollider = currentProduct.currentPlaceholder.GetComponent <BoxCollider>();
                        productCollider.enabled = true;
                        Vector3 size = productCollider.bounds.size; // /14
                        //Vector3 center = productCollider.bounds.center;
                        productCollider.enabled = false;
                        //size.x = Mathf.Abs(size.x);
                        //size.y = Mathf.Abs(size.y);
                        //size.z = Mathf.Abs(size.z);
                        //float oldY = size.y;
                        //size.y = size.z;
                        //size.z = oldY;
                        Vector3    center  = new Vector3(productCollider.transform.position.x, productCollider.transform.position.y + size.y / 2, productCollider.transform.position.z);
                        Collider[] results = Physics.OverlapBox(center, size / 2);

                        if (results.Length > 0)
                        {
                            //print(results.Length);
                            bool conflict = true;

                            /*foreach (Collider col in results)
                             * {
                             *  if (col.tag == "Shelf")
                             *  {
                             *      print("COnflict with shelf 1");
                             *      conflict = true;
                             *      break;
                             *  }
                             *  else if (col.gameObject.layer == 21)
                             *  { // Shelf layer
                             *      print("COnflict with shelf 2");
                             *      conflict = true;
                             *      break;
                             *  }
                             *  else if (col.gameObject.layer == 17)
                             *  { // Product layer
                             *      print("COnflict with product");
                             *      conflict = true;
                             *      break;
                             *  }
                             * }*/
                            if (conflict)
                            {
                                movementConflict = true;
                                currentProduct.currentPlaceholder.HighlightOn(Color.red);
                            }
                            results = null;
                        }

                        // Re-enable colliders
                        currentDisplayShelf.GetComponent <BoxCollider>().enabled = true;
                        currentShelf.GetCollider().enabled = true;
                    }
                    else
                    {
                        //print("Didnt check");
                    }
                    currentProduct.currentPlaceholder.GetComponent <BoxCollider>().enabled = true;
                }
                else
                {
                    print("Placeholder doesnt exist");
                }
                if (Input.GetMouseButtonUp(0) && !dm.PointerOverUI)
                { // Left Click
                    if (!movementConflict)
                    {
                        if (currentProduct.currentProduct.NeedsContainer())
                        {
                            if (currentProduct.currentContainer != null)
                            {
                                Box.PackagedBud packagedBud = currentProduct.GetPackagedBud();
                                if (packagedBud != null)
                                {
                                    currentProduct.currentPlaceholder.indicator.OpenPackagedBudPlacementPanel(currentProduct.currentContainer, packagedBud);
                                }
                            }
                            else
                            {
                                currentProduct.currentPlaceholder.indicator.OpenChooseContainerPanel(currentProduct);
                            }
                        }
                        else if (!productIsBox)
                        {
                            Box.PackagedProduct packagedProduct = null;
                            bool isPackagedProduct = false;
                            try
                            {
                                packagedProduct   = (Box.PackagedProduct)currentProduct.currentProduct;
                                isPackagedProduct = true;
                            }
                            catch (System.InvalidCastException)
                            { // Wasnt a packaged product
                                // Do nothing, allow to carry on
                                isPackagedProduct = false;
                            }
                            if (isPackagedProduct)
                            {
                                if (packagedProduct != null)
                                {
                                    packagedProduct.MoveProduct(Dispensary.JobType.StoreBudtender, currentProduct.currentPlaceholder.transform.position, currentDisplayShelf);
                                    currentProduct.FinishMovement();

                                    // Try moving next packaged product
                                    StartCoroutine(StartMovingNextPackagedProduct());
                                    yield return(new WaitForSeconds(.0125f)); // Needs to last longer than the waitforseconds(.01f)

                                    packagedProduct.parentBox.RemoveProduct(packagedProduct);
                                    uiM_v5.leftBarMainSelectionsPanel.UpdateBoxScrollable();
                                    yield break;

                                    /*Product newProduct = null;
                                     * CurrentProduct oldProduct = currentProduct;
                                     * try
                                     * { // Use packaged product reference
                                     *  newProduct = CreateProduct(packagedProduct.packagedProductReference, packagedProduct.parentBox.transform.position);
                                     * }
                                     * catch (System.NullReferenceException)
                                     * { // Use product reference
                                     *  newProduct = CreateProduct(packagedProduct.productReference, packagedProduct.parentBox.transform.position);
                                     * }
                                     * if (newProduct != null)
                                     * {
                                     *  newProduct.productGO.gameObject.SetActive(false);
                                     *  newProduct.MoveProduct(Dispensary.JobType.StoreBudtender, currentProduct.currentPlaceholder.transform.position, currentDisplayShelf);
                                     *  currentProduct.currentProduct.uniqueID = newProduct.uniqueID;
                                     *  currentProduct.FinishMovement();
                                     *
                                     *  // Try moving next packaged product
                                     *  StartCoroutine(StartMovingNextPackagedProduct());
                                     *  yield return new WaitForSeconds(.0125f); // Needs to last longer than the waitforseconds(.01f)
                                     *  packagedProduct.parentBox.RemoveProduct(packagedProduct);
                                     *  uiM_v5.leftBarMainSelectionsPanel.UpdateBoxScrollable();
                                     *  yield break;
                                     * }*/
                                }
                            }
                            else
                            { // Is not a packaged product0
                                currentProduct.currentProduct.MoveProduct(Dispensary.JobType.StoreBudtender, currentProduct.currentPlaceholder.transform.position, currentDisplayShelf);

                                uiM_v5.leftBarMainSelectionsPanel.RemoveProduct(currentProduct.currentProduct, false);
                                if (moveMode == MoveMode.single)
                                {
                                    FinishedMovingSingleProduct();
                                }
                                else if (moveMode == MoveMode.multiple)
                                {
                                    FinishedMovingMultipleProducts();
                                }
                                yield break;
                            }
                        }
                        else if (productIsBox)
                        {
                            bool       newStackExists = false;
                            StorageBox beingMoved     = (StorageBox)currentProduct.currentProduct;
                            if (currentProduct.newStack != null)
                            {
                                newStackExists = true;
                            }
                            if (newStackExists)
                            {
                                beingMoved.MoveProduct(Dispensary.JobType.StoreBudtender, currentProduct.currentPlaceholder.transform.position, currentProduct.newStack);
                            }
                            else if (currentDisplayShelf != null)
                            {
                                beingMoved.MoveProduct(Dispensary.JobType.StoreBudtender, currentProduct.currentPlaceholder.transform.position, currentDisplayShelf);
                            }
                        }
                    }
                    else
                    {
                        print("Cant move here: wont fit");
                    }
                }
            }
            yield return(null);
        }
    }