Ejemplo n.º 1
0
    private void CreateConveyor()
    {
        bool         isFind = false;
        ConveyorItem item   = null;

        for (int i = 0; i < conveyorList.Count; i++)
        {
            if (!conveyorList[i].isUsing)
            {
                item   = conveyorList[i];
                isFind = true;
                break;
            }
        }

        if (!isFind)
        {
            var co = Resources.Load <ConveyorItem>("Prefabs/Foods/ConveyorItem");
            item = Instantiate(co, Vector3.zero, Quaternion.identity, ui_ConveyorTR);
            item.InitItem();
            conveyorList.Add(item);
        }

        item.RefreshItem();
    }
Ejemplo n.º 2
0
 public void SetItemColor(Color color, ConveyorItem except = null)
 {
     for (int i = 0; _conveyorItems.Count > i; i++)
     {
         if (_conveyorItems[i] != except)
         {
             _conveyorItems[i].color = color;
         }
     }
 }
Ejemplo n.º 3
0
    public float AddItemToConveyor(Inventory inventory)
    {
        if (_itemLimit > _conveyorItems.Count)
        {
            Definitions.Items item  = inventory.items[UnityEngine.Random.Range(0, inventory.items.Count)];
            ConveyorItem      toAdd = new ConveyorItem(this, Definitions.Item(item), inventory.Settings(item));
            _conveyorItems.Add(toAdd);
            Updater += toAdd.Update;
        }

        return(Time.time + itemInterval);
    }
Ejemplo n.º 4
0
    public HeldItem(ConveyorItem conveyorItem) : base("Held" + conveyorItem.type.ToString(), GameObject.CreatePrimitive(PrimitiveType.Quad))
    {
        conveyorItem.SetHeld(true);
        conveyorItem.color = Color.gray;

        container.transform.localRotation = Quaternion.Euler(90, 0, 0);

        body.transform.localRotation = Quaternion.identity;
        body.transform.localScale    = new Vector3(conveyorItem.width, conveyorItem.height, 1);

        meshRenderer.material.color = Color.white;

        label.SetLocalRotation(Quaternion.identity);
        label.SetText(conveyorItem.text);

        position          = conveyorItem.position + Vector3.forward;
        this.conveyorItem = conveyorItem;
    }
Ejemplo n.º 5
0
    public void Update(bool addConveyorItems)
    {
        if (running)
        {
            coinCounter.SetCounterValue(player.inventory.coins);

            //While there are strictly speaking better ways to get a world-space mouse position, this one has the absolute minimum number of moving parts
            //First we get a ray. The camera has a convenience method that returns a ray from the center of the camera in the direction of a screen point
            //The mouse position we can poll via the input system is in screen-space coordinates
            Ray mouseRay = camera.ScreenPointToRay(Input.mousePosition);

            //The actual raycast returns an array with all the targets the ray passed through
            //Note that we don't pass in the ray itself -- that's because the method taking a ray as argument flat-out doesn't work
            //We don't bother constraining the raycast by layer mask just yet, since the ground plane is the only collider in the scene
            RaycastHit[] hits = Physics.RaycastAll(mouseRay.origin, mouseRay.direction, float.PositiveInfinity);

            //These references might be populated later
            Lane         hoveredLane = null;
            ConveyorItem hoveredItem = null;

            //Proceed if raycast hits something
            if (hits.Length > 0)
            {
                //Get the mouse position on the ground plane
                Vector3 mousePosition = hits[0].point;

                //See if the mouse is hovering any lanes
                hoveredLane = stage.GetHoveredLane(mousePosition);

                //Proceed if the mouse is hovering the conveyor
                if (conveyor.Contains(mousePosition))
                {
                    //Try to get a hovered conveyor item
                    hoveredItem = conveyor.GetHoveredItem(mousePosition);

                    //Proceed if an item is hovered and no item is held
                    if (hoveredItem != null && heldItem == null)
                    {
                        //Instantiate a new HeldItem if no item is held and the left mouse button is pressed
                        //Otherwise, change the color of the item to indicate hover
                        if (heldItem == null && Input.GetMouseButtonDown(0))
                        {
                            heldItem = new HeldItem(hoveredItem);
                        }
                        else
                        {
                            hoveredItem.color = Color.yellow;
                        }
                    }
                }

                //Reset lane colors
                stage.SetLaneColor(Color.black);

                if (heldItem != null) //Proceed if an item is held
                {
                    //Position the held item at the world-space mouse position
                    heldItem.SetPosition(mousePosition);

                    //Proceed if a lane is hovered
                    if (hoveredLane != null)
                    {
                        hoveredLane.color = Color.yellow;
                    }

                    //Proceed if the left mouse button is released
                    if (!Input.GetMouseButton(0))
                    {
                        hoveredItem = conveyor.GetHoveredItem(mousePosition);

                        if (hoveredLane != null)
                        {
                            hoveredLane.Add(new LaneItem(heldItem, hoveredLane));
                            heldItem.Destroy();
                        }

                        if (hoveredItem != null && heldItem.conveyorItem != hoveredItem)
                        {
                            ItemDefinition heldDefinition    = heldItem.conveyorItem.definition;
                            ItemSettings   heldSettings      = heldItem.conveyorItem.settings;
                            ItemDefinition hoveredDefinition = hoveredItem.definition;
                            ItemSettings   hoveredSettings   = hoveredItem.settings;

                            heldItem.conveyorItem.SetItemDefinition(hoveredDefinition);
                            heldItem.conveyorItem.SetItemSettings(hoveredSettings);
                            hoveredItem.SetItemDefinition(heldDefinition);
                            hoveredItem.SetItemSettings(heldSettings);
                            heldItem.conveyorItem.Refresh();
                            hoveredItem.Refresh();
                        }

                        //Reset the held conveyor item's color and clean up the held item
                        heldItem.conveyorItem.color = Color.white;
                        heldItem.conveyorItem.SetHeld(false);
                        heldItem.Destroy();
                        heldItem = null;
                    }
                }
            }

            //Reset the color of any item not currently hovered
            conveyor.SetItemColor(Color.white, heldItem != null ? heldItem.conveyorItem : hoveredItem);

            //Update the conveyor
            conveyor.Update();

            //Update the stage
            stage.Update();

            //Update the level
            level.Update();

            //Proceed if the item spawn interval has elapsed, and add a new item to the conveyor belt
            if (Time.time > itemTime && addConveyorItems)
            {
                itemTime = conveyor.AddItemToConveyor(player.inventory);
            }
        }
    }
Ejemplo n.º 6
0
 public int IndexOf(ConveyorItem conveyorItem) => _conveyorItems.IndexOf(conveyorItem);
Ejemplo n.º 7
0
 public void RemoveItemFromConveyor(ConveyorItem toRemove)
 {
     Updater -= toRemove.Update;
     _conveyorItems.Remove(toRemove);
 }