public void ChangeInterface(Vector3 pos) //method from IUi, changes depending on what the player is looking at/holding
 {
     if (i.GetHolding() != null && canInteract)
     {
         GameObject obj = i.GetHolding().GetObject();
         if (obj.CompareTag("Food"))
         {
             Food_O[] food = obj.GetComponentsInChildren <Food_O>();
             Food_O   last = food[food.Length - 1];
             if (last.stack + stack <= 7)
             {
                 CheckStack();
             }
             else
             {
                 i.SetUI(2, "");
             }
         }
         else
         {
             i.SetUI(2, "");
         }
     }
     else if (i.GetHolding() == null && canInteract)
     {
         i.SetUI(4, GetName());
     }
 }
    public IEnumerator RestockFood(GameObject foodType, float time)
    {
        List <PlaceMarker> markers = GetComponentsInChildren <PlaceMarker>().ToList();

        for (int i = 0; i < markers.Count; i++)
        {
            if (markers[i].transform.parent.CompareTag("Food"))
            {
                continue;
            }

            if (!markers[i].GetOccupation())
            {
                GameObject food = Instantiate(foodType, markers[i].transform.position, markers[i].transform.rotation);
                Food_O     f    = food.GetComponent <Food_O>();
                f.SetMarker(markers[i]);
                f.EnablePhysics(transform);
                f.ChangeDrag(f.defaultDrag);
                f.SetOnSurface(true);
                f.SetFreshness(true);
                markers[i].SetOccupation(true);
                ListOfFood().Add(f);
                MarkerList().Remove(markers[i]);
                yield return(new WaitForSeconds(time));
            }
        }
    }
 void DismantleStack() //ugly, needs readjusting, but separates each food object when in a stack
 {
     if (firstOnStack != null)
     {
         if (firstOnStack.foodStack.Count > 0)
         {
             Food_O food = firstOnStack;
             foreach (Food_O f in food.foodStack)
             {
                 if (f.firstOnStack != null)
                 {
                     f.transform.SetParent(f.firstOnStack.transform.parent);
                 }
                 f.firstOnStack = null;
                 if (f.GetMarker() != null)
                 {
                     f.GetMarker().SetOccupation(false);
                 }
                 if (f.thisMarker != null)
                 {
                     f.thisMarker.SetOccupation(false);
                 }
                 f.inStack = true;
             }
             food.foodStack.Clear();
         }
     }
 }
    bool CheckForChildren(Food_O bottom) //checking if the food has children and configuring accordingly
    {
        Food_O[] food = bottom.GetComponentsInChildren <Food_O>();
        Move_S   m    = bottom.GetComponentInParent <Move_S>(); //if the foo is stacked, bottom is the food at the bottom of the stack

        if (bottom.GetFreshness())                              //untouched food
        {
            if (manager != null)                                //cheap way to configure, checking scene basically
            {
                if (manager.GetItemPrice(bottom.GetName()))     //if can afford
                {
                    bottom.SetFreshness(false);
                }
                else
                {
                    return(false);
                }
            }
        }
        i.OnPickUp(bottom.transform);
        if (m != null) //checking if on board/ plate / tray
        {
            for (int i = 0; i < food.Length; i++)
            {
                food[i].SetOnSurface(false);
                m.ListOfFood().Remove(food[i]);         //removing the food from the script list
            }
            if (firstOnStack != null || stack == 1)     //if theres a stack or singular food
            {
                m.MarkerList().Add(bottom.GetMarker()); //readding the marker to the board/plate/tray for future
                bottom.SetMarker(null);
            }
            if (m.startedWithFood) //checking if the surface needs replenishing
            {
                if (m.ListOfFood().Count == 0)
                {
                    StartCoroutine(m.RestockFood(m.foodType, .2f));
                }
            }
        }
        for (int i = 0; i < food.Length; i++) //for all food, be it one or more
        {
            food[i].stack = i + 1;            //changing the food variables
            food[i].ChangeDrag(3);
            if (CheckObjectCount.objects.Contains(food[i].gameObject))
            {
                CheckObjectCount.objects.Remove(food[i].gameObject);
            }
            if (food[i] != bottom)
            {
                food[i].DisablePhysics(food[i - 1].transform);
            }
            food[i].inStack = false;
        }
        return(true);
    }
    void OnDrop(RaycastHit hit)
    {
        SetPhysics(null);
        GameObject obj = GetHolding().GetObject();

        newColider = false;
        if (obj.GetComponent <Move_S>() != null) //board/plate/tray dropped
        {
            if (obj.CompareTag("Plate"))         //checking if its a plate
            {
                if (Physics.Raycast(guide.position, -Vector3.up, out hit, 5f))
                {
                    float dist = Vector3.Distance(guide.position, hit.point);
                    StartCoroutine(BreakStuff(dist, obj));
                }
            }
            Move_S m = GetHolding().GetObject().GetComponent <Move_S>();
            if (m.ListOfFood().Count > 0)            //checking if theres food on the object
            {
                foreach (Food_O f in m.ListOfFood()) //resetting varibales for each food object
                {
                    f.GetComponent <IPhysics>().GetMarker().SetOccupation(false);
                    f.SetOnSurface(false);
                    f.ChangeDrag(3);
                    f.firstOnStack = null;
                    f.SetMarker(null);
                    StartCoroutine(CheckObjectCount.CheckPrefabCount(f.gameObject));
                    GameManager.dropCount++;
                }
                m.ListOfFood().Clear();
            }
            m.MarkerList().Clear();
            m.AddMarkerChildren();
        }
        else if (obj.GetComponent <Food_O>() != null) //if food dropped
        {
            Food_O food = obj.GetComponent <Food_O>();
            StartCoroutine(CheckObjectCount.CheckPrefabCount(food.gameObject));
            if (food.foodStack.Count > 0)
            {
                foreach (Food_O f in food.foodStack) //resetting varibales
                {
                    f.firstOnStack = null;
                    StartCoroutine(CheckObjectCount.CheckPrefabCount(f.gameObject));
                    GameManager.dropCount++;
                    f.GetMarker().SetOccupation(false);
                    f.SetMarker(null);
                }
                food.foodStack.Clear();
            }
        }
        SetInteract(null);
    }
Пример #6
0
 public void OnClick(RaycastHit hit, Transform t)
 {
     if (CheckForFood())
     {
         PlaceMarker m = i.AnyMarker(markers.ToList(), hit.point);
         if (!m.GetOccupation())
         {
             GameObject obj  = i.GetHolding().GetObject();
             Food_O     food = obj.GetComponent <Food_O>();
             if (!food.HasChild() && CheckScene())
             {
                 StartCoroutine(WaitToCook(food));
                 i.OnPutDown(m, null, true);
                 obj.transform.rotation = Quaternion.identity;
             }
         }
     }
 }
    void PutFoodOnFood(GameObject obj) //when food is in hand and want to place on other food.
    {
        Food_O[] food = obj.GetComponentsInChildren <Food_O>();
        Food_O   last = food[food.Length - 1];   //getting the last in the stack, may only be the one

        if (last.stack + stack <= 7 && !inStack) //may change stack limit
        {
            PlaceMarker m = i.GetMarker(gameObject);
            if (m != null)
            {
                for (int i = 0; i < food.Length; i++)
                {
                    food[i].ChangeDrag(food[i].defaultDrag); //restting the drag and stack varibales
                    if (food[i] != obj.GetComponent <Food_O>())
                    {
                        food[i].stack = food[i - 1].stack + 1;
                    }
                    else
                    {
                        food[i].stack = stack + 1;
                    }
                }
                if (GetParents() != null)
                {
                    Food_O bottom = GetParents()[GetParents().Length - 1];//getting item at the bottom of the stack
                    foreach (Food_O f in food)
                    {
                        bottom.foodStack.Add(f); //reordering the stack
                        f.firstOnStack = bottom;
                    }
                }
                Move_S move = m.GetComponentInParent <Move_S>(); //checing if the placemarker belongs to a plate/board/tray
                if (move != null)
                {
                    for (int i = 0; i < food.Length; i++)
                    {
                        food[i].SetOnSurface(true);
                        move.ListOfFood().Add(food[i]); //adding food to the surface accordingly
                    }
                }
                i.OnPutDown(m, transform, false);
            }
        }
    }
Пример #8
0
    static IEnumerator Strobe(GameObject obj)
    {
        Food_O f = objects[0].GetComponent <Food_O>();

        if (f != null)
        {
            Destroy(f);
        }
        objects.Remove(objects[0]);
        int i = 3;

        while (i > 0)
        {
            i--;
            yield return(new WaitForSeconds(.1f));

            obj.SetActive(false);
            yield return(new WaitForSeconds(.1f));

            obj.SetActive(true);
        }
        Destroy(obj);
    }
Пример #9
0
 public void ChangeInterface(Vector3 pos)
 {
     if (CheckForFood())
     {
         Food_O f = i.GetHolding().GetObject().GetComponent <Food_O>();
         if (f.HasChild())
         {
             i.SetUI(2, "");
         }
         else if (!CheckScene())
         {
             i.SetUI(2, GetName() + " is warming up");
         }
         else
         {
             i.SetUI(1, "Cook " + f.GetName());
         }
     }
     if (i.GetHolding() == null)
     {
         i.SetUI(3, "");
     }
 }
Пример #10
0
 public override void Awake()
 {
     base.Awake();
     friedEgg = transform.Find("Fried Egg");
     fEgg     = friedEgg.GetComponent <Food_O>();
 }
Пример #11
0
    IEnumerator WaitToCook(Food_O food)
    {
        yield return(new WaitForSeconds(.2f));

        food.StartCooking();
    }
Пример #12
0
    public IEnumerator FlipFood(Transform main, Transform mdel, Vector3 toPos, float dur, Food_O food) //when the player flips a food object
    {
        isMoving = true;
        food.ChangeDrag(0);
        float counter = 0;

        angle += 180;
        float a = 0;

        food.DisablePhysics(food.transform);
        Vector3 startPos = main.position;

        isMoving = true;
        while (counter < dur) //moving up
        {
            counter      += Time.deltaTime;
            main.position = Vector3.Lerp(startPos, toPos, counter / dur);
            yield return(null);
        }
        while (a < 180) //then rotating
        {
            mdel.Rotate(Vector3.forward, 10);
            a += 10;
            yield return(null);
        }
        food.EnablePhysics(food.transform); //allowing gravity to take it down
        float dist = .1f;
        float cal  = Mathf.Sqrt(dist / -(Physics.gravity.y / 2));

        yield return(new WaitForSeconds(cal)); //only changing the drag after the food has finished falling

        food.ChangeDrag(3);
        isMoving = false;
    }