Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        if (gameObject.GetComponent <Renderer>() != null)
        {
            rend         = gameObject.GetComponent <Renderer>();
            rend.enabled = present;
        }

        if (gameObject.GetComponent <Collider>() != null)
        {
            cldr         = gameObject.GetComponent <Collider>();
            cldr.enabled = present;
        }

        if (gameObject.GetComponent <Rigidbody>() != null)
        {
            rb = gameObject.GetComponent <Rigidbody>();
            if (present)
            {
                rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
            }
            else
            {
                rb.constraints = RigidbodyConstraints.FreezeAll;
            }
        }
        if (plate == null)
        {
            Debug.Log("Error:" + name + " has no plate.");
            return;
        }
        plateScript = plate.GetComponent <PlateBehavior>();
        previous    = plateScript.isActivated();
    }
Beispiel #2
0
    IEnumerator PickupAnimation(GameObject target)
    {
        Grabbable targetGrabbable = target.GetComponent <Grabbable>();

        if (targetGrabbable != null && targetGrabbable.Held)
        {
            yield break;
        }
        switch (target.tag)
        {
        case "fryBasket":
            yield return(PickupAndRotate(target));

            yield break;

        case "plate":
            PlateBehavior plate = target.GetComponent <PlateBehavior>();
            if (plate.Open)
            {
                plate.Close();
                yield break;
            }
            break;
        }

        pickupState  = PickupState.Seeking;
        pickupTarget = target;
        Vector3 currPos = transform.position;
        Vector3 vel     = Vector3.zero;

        //Debug.LogFormat("{0} Hand is going in", hand);
        while (pickupState == PickupState.Seeking)
        {
            if ((currPos - transform.position).magnitude > pickUpDistance || HoldingSomething)
            {
                pickupState = PickupState.Returning;
                break;
            }
            vel  = target.transform.position - this.transform.position;
            vel  = vel.normalized;
            vel *= pickupSpeed;
            rigidbody.velocity = vel;
            yield return(new WaitForFixedUpdate());
        }

        //Debug.LogFormat("{0} Hand is backing out", hand);
        while (transform.position.y < hoverHeight)
        {
            rigidbody.velocity = Vector3.up * pickupSpeed;
            yield return(new WaitForFixedUpdate());
        }

        rigidbody.velocity = Vector3.zero;
        //Debug.LogFormat("{0} Hand Done Picking Up", hand);
        pickupState = PickupState.Idle;
        yield break;
    }
Beispiel #3
0
/*    public List<FoodBehavior.FoodType> foodTypeList;
 *
 *  private void OnValidate()
 *  {
 *      foodTypeList.Clear();
 *      foreach (Recipe food in FoodItems)
 *      {
 *          foodTypeList.Add(food.foodName);
 *      }
 *      foodTypeList.Sort();
 *  }*/

    public bool CheckDelivery(PlateBehavior deliveredPlate)
    {
        //check size of food list
        //if (deliveredPlate.contents.Count != FoodItems.Count) return false;

        //check names of foods
        //List<FoodBehavior.FoodType> foodTypes = new List<FoodBehavior.FoodType>();
        List <Recipe> satisfied = new List <Recipe>();

        foreach (FoodBehavior food in deliveredPlate.contents)
        {
            //REALLY Hard constraint that all food must be perfectly done to be considered
            if (food.doneness != FoodBehavior.Doneness.Cooked)
            {
                continue;
            }

            foreach (Recipe recipe in FoodItems)
            {
                // if this recipe is already satsified skip it
                if (satisfied.Contains(recipe))
                {
                    continue;
                }
                //if the food type isn't the target skip it
                if (recipe.foodType != food.foodType)
                {
                    continue;
                }

                // if different breading count skip it
                if (recipe.BreadingLayers.Count != food.BreadingLayers.Count)
                {
                    continue;
                }

                if (recipe.BreadingLayers.SequenceEqual(food.BreadingLayers))
                {
                    satisfied.Add(recipe);
                    break;
                }
            }
        }
        return(satisfied.Count == FoodItems.Count);
    }
Beispiel #4
0
    IEnumerator OrderResult(PlateBehavior plate, bool success)
    {
        yield return(new WaitForSeconds(1));

        if (success)
        {
            Destroy(plate.gameObject);
            guiManager gui = FindObjectOfType <guiManager>();
            gui.UpdateOrderList();
        }
        else
        {
            Rigidbody plateBody = plate.GetComponent <Rigidbody>();
            plate.gameObject.layer = 12;
            plate.tag = "trash";
            plateBody.AddForce((Vector3.up - Vector3.forward) * 10, ForceMode.Impulse);
        }
    }
Beispiel #5
0
    /*  private void OnTriggerEnter(Collider other) {
     *    if(other.tag == "plate") {
     *        PlateBehavior plate = other.GetComponent<PlateBehavior>();
     *        evaluatePlate(plate);
     *    }
     * }*/

    // Update is called once per frame
    public void evaluatePlate(PlateBehavior plate)
    {
        //compareAgainstOrder(plate.contents);
        Debug.LogFormat("Recieved this plate: {0}", string.Join(",", plate.contents));

        Debug.Log("Checking against Orders:");
        foreach (Order order in activeOrderList)
        {
            Debug.Log(string.Join(",", order.FoodItems));
        }

        int orderHit = -1;

        for (int i = 0; i < activeOrderList.Count; i++)
        {
            if (activeOrderList[i].CheckDelivery(plate))
            {
                orderHit = i;
                break;
            }
        }

        if (orderHit > -1)
        {
            Debug.Log("Successful Delivery!");
            activeOrderList.RemoveAt(orderHit);
            if (enforceTime)
            {
                orderAddTimes.RemoveAt(orderHit);
            }
            StartCoroutine(OrderResult(plate, true));
        }
        else
        {
            Debug.Log("Incorrect Delivery!");
            //could be fun to throw the plate back rather than just destroy it
            StartCoroutine(OrderResult(plate, false));
        }
    }