Ejemplo n.º 1
0
    private void ClaimEmptyOffice()
    {
        myOffice = null;
        List <GameObject> offices = sim.offices;


        if (isSocialDistancing)
        {
            // Attempt to leave one space in between
            for (int i = 0; i < offices.Count; i++)
            {
                if (!offices[i].GetComponent <Office>().isOccupied)
                {
                    myOffice = offices[i].GetComponent <Office>();
                    break;
                }
            }
            // Couldn't find one empty both sides so check one by one
            if (myOffice == null)
            {
                for (int i = 0; i < offices.Count; i++)
                {
                    if (!offices[i].GetComponent <Office>().isOccupied)
                    {
                        myOffice = offices[i].GetComponent <Office>();
                        break;
                    }
                }
            }
        }
        else
        {
            // Randomly occupy one
            List <GameObject> emptyOffices = new List <GameObject>();

            foreach (GameObject o in offices)
            {
                if (!o.GetComponent <Room>().isOccupied)
                {
                    emptyOffices.Add(o);
                }
            }

            if (emptyOffices.Count > 0)
            {
                int rand = Random.Range(0, emptyOffices.Count);
                myOffice = emptyOffices[rand].GetComponent <Office>();
            }
        }

        if (myOffice == null)
        {
            print("non found");
            Destroy(gameObject);
            enabled = false;
            return;
        }

        if (!myOffice.ClaimOffice())
        {
            ClaimEmptyOffice();
        }

        Go(myOffice.seats[0].position);
    }