Beispiel #1
0
 public void OnPlace()
 {
     if (HasDisplayShelfFunction())
     {
         StoreObjectFunction_DisplayShelf displayShelf = GetDisplayShelfFunction();
         displayShelf.OnPlace();
     }
     if (HasCheckoutCounterFunction())
     {
         StoreObjectFunction_CheckoutCounter checkoutCounter = GetCheckoutCounterFunction();
         checkoutCounter.OnPlace();
     }
     if (HasBudtenderCounterFunction())
     {
         StoreObjectFunction_BudtenderCounter budtenderCounter = GetBudtenderCounterFunction();
         budtenderCounter.OnPlace();
     }
     if (HasDecorationFunction())
     {
         StoreObjectFunction_Decoration decoration = GetDecorationFunction();
         decoration.OnPlace();
     }
     if (HasDoorwayFunction())
     {
         StoreObjectFunction_Doorway doorway = GetDoorwayFunction();
         doorway.OnPlace();
     }
 }
Beispiel #2
0
    public override void MoveProduct(Dispensary.JobType preferredJob, Vector3 pos, StoreObjectFunction_DisplayShelf displayShelf)
    {
        GameObject  dm        = GameObject.Find("DispensaryManager");
        Inventory   inventory = dm.GetComponent <DispensaryManager>().dispensary.inventory;
        MoveProduct newAction = new MoveProduct(inventory, this, pos, true, preferredJob);

        newAction.SetupShelfProduct(parentShelf, displayShelf);
        dm.GetComponent <StaffManager>().AddActionToQueue(newAction);
    }
Beispiel #3
0
    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 MoveProduct(Inventory inventory_, Product toMove_, Vector3 toMoveTo, bool goBackToJobPos, Dispensary.JobType preferredJob) : base(preferredJob, StaffAIAction.ActionType.sequence)
 {
     inventory    = inventory_;
     toMove       = toMove_;
     newPosition  = toMoveTo;
     backToJobPos = goBackToJobPos;
     SetupDictionary();
     oldShelf = null;
     newShelf = null;
     oldStack = null;
     newStack = null;
 }
Beispiel #5
0
    // Getters and setters
    public bool HasDisplayShelfFunction()
    {
        StoreObjectFunction_DisplayShelf potentialDisplayShelfFunction = gameObject.GetComponent <StoreObjectFunction_DisplayShelf>();

        if (potentialDisplayShelfFunction != null)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
    public StoreObjectFunction_DisplayShelf GetClosestDisplayShelf(Vector3 point)
    {
        StoreObjectFunction_DisplayShelf closest = null;
        float closestVal = 100000.0f;

        foreach (StoreObjectFunction_DisplayShelf displayShelf in dm.dispensary.GetAllDisplayShelves())
        {
            float distance = Vector3.Distance(point, displayShelf.transform.position);
            if (distance < closestVal)
            {
                closestVal = distance;
                closest    = displayShelf;
            }
        }
        return(closest);
    }
 public override void MoveProduct(Dispensary.JobType preferredJob, Vector3 pos, StoreObjectFunction_DisplayShelf displayShelf)
 {
     // Wont be used here
 }
 public void SetupShelfProduct(StoreObjectFunction_DisplayShelf oldShelf_, StoreObjectFunction_DisplayShelf newShelf_)
 {
     oldShelf = oldShelf_;
     newShelf = newShelf_;
 }
 public void SetCurrentDisplayShelf(StoreObjectFunction_DisplayShelf newShelf)
 {
     currentDisplayShelf  = newShelf;
     currentShelf         = currentDisplayShelf.GetShelf(GetCurrentShelfLayer());
     currentMaxShelfLayer = currentDisplayShelf.shelves.Count - 1;
 }
    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);
        }
    }
    public override void OnInspectorGUI()
    {
        StoreObjectFunction_DisplayShelf script = (StoreObjectFunction_DisplayShelf)target;

        // Custom shelf lists
        script.editorType = (StoreObjectFunction_DisplayShelf.EditorType)EditorGUILayout.EnumPopup("Custom shelf list", script.editorType);

        if (script.editorType == StoreObjectFunction_DisplayShelf.EditorType.CustomShelfLists)
        {
            if (script.totalShelfListsCount > 0 && script.shelfLists.Count < script.totalShelfListsCount)
            {
                for (int i = script.shelfLists.Count; i < script.totalShelfListsCount; i++)
                {
                    script.shelfLists.Add(new ShelfList());
                }
            }
        }
        else
        {
            script.ClearShelfLists();
        }
        if (script.editorType == StoreObjectFunction_DisplayShelf.EditorType.CustomShelfLists)
        {
            script.totalShelfListsCount = EditorGUILayout.DelayedIntField("Number of Shelf Lists", script.totalShelfListsCount);
            if (script.totalShelfListsCount > 0)
            {
                for (int i = 0; i < script.totalShelfListsCount; i++)
                {
                    EditorGUILayout.Separator();
                    int value = i;
                    try
                    {
                        script.shelfLists[value].SetShelfListName(EditorGUILayout.TextField("Shelf List Name", script.shelfLists[value].GetShelfListName()));
                        script.shelfLists[value].SetShelfListCount(EditorGUILayout.DelayedIntField("  " + script.shelfLists[value].GetShelfListName() + " # of Shelves", script.shelfLists[i].GetShelfListCount()));
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        script.shelfLists.Add(new ShelfList());
                        script.shelfLists[value].SetShelfListName(EditorGUILayout.TextField("Shelf List Name", script.shelfLists[value].GetShelfListName()));
                        script.shelfLists[value].SetShelfListCount(EditorGUILayout.DelayedIntField("  " + script.shelfLists[value].GetShelfListName() + " # of Shelves", script.shelfLists[i].GetShelfListCount()));
                    }
                    script.OnSetListCount();
                    if (script.shelfLists[i].GetShelfListCount() > 0)
                    {
                        for (int j = 0; j < script.shelfLists[i].GetShelfListCount(); j++)
                        {
                            script.shelfLists[i].shelfLayoutPositions[j] = (ShelfLayoutPosition)EditorGUILayout.ObjectField("  Shelf Position " + j, script.shelfLists[i].shelfLayoutPositions[j], typeof(ShelfLayoutPosition), true);
                        }
                    }
                }
            }
        }
        if (script.totalShelfListsCount == 0)
        {
            if (script.shelfLists.Count > 0)
            {
                script.ClearShelfLists();
            }
        }

        script.priority = EditorGUILayout.Toggle("Priority Object?", script.priority);

        Undo.RecordObject(target, "Modified Shelf Function");
        EditorUtility.SetDirty(target);
    }
Beispiel #12
0
 abstract public void MoveProduct(Dispensary.JobType preferredJob, Vector3 pos, StoreObjectFunction_DisplayShelf displayShelf);